Skip to content

Monitor Upstream Repository #281

Monitor Upstream Repository

Monitor Upstream Repository #281

name: 'Monitor Upstream Repository'
on:
schedule:
# Check every 6 hours
- cron: '0 */6 * * *'
workflow_dispatch: # Allow manual triggering
jobs:
check-upstream:
runs-on: ubuntu-latest
steps:
- name: Check for new upstream commits
id: check
uses: actions/github-script@v7
with:
script: |
const upstreamOwner = 'Nukem9';
const upstreamRepo = 'dlssg-to-fsr3';
const upstreamBranch = 'master';
// Get the latest commit from upstream
const { data: upstreamCommits } = await github.rest.repos.listCommits({
owner: upstreamOwner,
repo: upstreamRepo,
sha: upstreamBranch,
per_page: 1
});
if (upstreamCommits.length === 0) {
console.log('No commits found in upstream repository');
return;
}
const latestUpstreamCommit = upstreamCommits[0].sha;
console.log(`Latest upstream commit: ${latestUpstreamCommit}`);
// Check if we have a record of the last processed commit
try {
const { data: lastProcessedRef } = await github.rest.git.getRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'tags/last-processed-upstream'
}).catch(e => {
if (e.status === 404) {
return { data: null };
}
throw e;
});
const lastProcessedCommit = lastProcessedRef ? lastProcessedRef.object.sha : null;
console.log(`Last processed commit: ${lastProcessedCommit || 'none'}`);
if (lastProcessedCommit !== latestUpstreamCommit) {
console.log('New commit detected, triggering build');
// Trigger the build workflow
await github.rest.repos.createDispatchEvent({
owner: context.repo.owner,
repo: context.repo.repo,
event_type: 'upstream_update',
client_payload: {
upstream_commit: latestUpstreamCommit,
upstream_repo: `${upstreamOwner}/${upstreamRepo}`,
upstream_branch: upstreamBranch
}
});
// Update or create the tag to mark this commit as processed
if (lastProcessedRef) {
await github.rest.git.updateRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'tags/last-processed-upstream',
sha: latestUpstreamCommit,
force: true
});
} else {
const { data: commitData } = await github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/tags/last-processed-upstream',
sha: latestUpstreamCommit
});
}
} else {
console.log('No new commits since last build');
}
} catch (error) {
console.error('Error checking upstream repository:', error);
}