Skip to content

Upstream Release Monitor #13

Upstream Release Monitor

Upstream Release Monitor #13

name: Upstream Release Monitor
on:
schedule:
# Run weekly on Monday at 9:00 AM UTC
- cron: '0 9 * * 1'
workflow_dispatch: # Allow manual triggering
# Security note: This workflow only uses schedule/workflow_dispatch triggers.
# External data (upstream release tags) is passed through env vars, not
# interpolated directly in run: commands, to prevent injection.
jobs:
check-upstream:
runs-on: ubuntu-latest
permissions:
contents: write
issues: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Check latest upstream release
id: check-release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Checking latest release of upstash/context7..."
LATEST_TAG=$(gh api repos/upstash/context7/releases/latest --jq '.tag_name')
RELEASE_URL=$(gh api repos/upstash/context7/releases/latest --jq '.html_url')
RELEASE_BODY=$(gh api repos/upstash/context7/releases/latest --jq '.body')
echo "Latest upstream tag: $LATEST_TAG"
echo "latest_tag=$LATEST_TAG" >> "$GITHUB_OUTPUT"
echo "release_url=$RELEASE_URL" >> "$GITHUB_OUTPUT"
# Save release body to file (may contain newlines)
echo "$RELEASE_BODY" > /tmp/release_body.txt
KNOWN_VERSION=$(cat .github/last-known-upstream-version)
echo "Known version: $KNOWN_VERSION"
echo "known_version=$KNOWN_VERSION" >> "$GITHUB_OUTPUT"
if [ "$LATEST_TAG" = "$KNOWN_VERSION" ]; then
echo "No new release detected."
echo "new_release=false" >> "$GITHUB_OUTPUT"
else
echo "New release detected: $LATEST_TAG (was $KNOWN_VERSION)"
echo "new_release=true" >> "$GITHUB_OUTPUT"
fi
- name: Update tracked version
if: steps.check-release.outputs.new_release == 'true'
env:
LATEST_TAG: ${{ steps.check-release.outputs.latest_tag }}
run: |
echo "$LATEST_TAG" > .github/last-known-upstream-version
- name: Commit updated version
if: steps.check-release.outputs.new_release == 'true'
env:
LATEST_TAG: ${{ steps.check-release.outputs.latest_tag }}
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add .github/last-known-upstream-version
git commit -m "chore: track upstream release $LATEST_TAG"
git push
- name: Create issue for new release
if: steps.check-release.outputs.new_release == 'true'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const releaseBody = fs.readFileSync('/tmp/release_body.txt', 'utf8').trim();
const title = `Upstream release: ${process.env.LATEST_TAG}`;
const body = [
'## New Upstream Release Detected',
'',
`**Tag:** \`${process.env.LATEST_TAG}\``,
`**Previous:** \`${process.env.KNOWN_VERSION}\``,
`**Release:** ${process.env.RELEASE_URL}`,
'',
'### Release Notes',
releaseBody || '_No release notes provided._',
'',
'### Action Required',
'Review the upstream changes and determine if this fork needs updates:',
'- [ ] Check for breaking API changes',
'- [ ] Check for new features to incorporate',
'- [ ] Update dependencies if needed',
'- [ ] Run tests against new upstream version',
'',
`*This issue was created automatically by the [release monitor workflow](${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}).*`
].join('\n');
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title,
body,
labels: ['upstream-release', 'automated']
});
env:
LATEST_TAG: ${{ steps.check-release.outputs.latest_tag }}
KNOWN_VERSION: ${{ steps.check-release.outputs.known_version }}
RELEASE_URL: ${{ steps.check-release.outputs.release_url }}