Check Upstream Updates #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Check Upstream Updates | |
| # Runs every Monday at 9 AM UTC | |
| on: | |
| schedule: | |
| - cron: '0 9 * * 1' | |
| workflow_dispatch: # Allows manual trigger | |
| jobs: | |
| check-updates: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Add upstream remote | |
| run: | | |
| git remote add upstream https://github.com/elie222/inbox-zero.git || true | |
| git fetch upstream | |
| - name: Check for updates | |
| id: check | |
| run: | | |
| BEHIND_COUNT=$(git rev-list --count HEAD..upstream/main) | |
| AHEAD_COUNT=$(git rev-list --count upstream/main..HEAD) | |
| echo "behind_count=$BEHIND_COUNT" >> $GITHUB_OUTPUT | |
| echo "ahead_count=$AHEAD_COUNT" >> $GITHUB_OUTPUT | |
| if [ "$BEHIND_COUNT" -gt 0 ]; then | |
| echo "updates_available=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "updates_available=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Get latest upstream commits | |
| if: steps.check.outputs.updates_available == 'true' | |
| id: commits | |
| run: | | |
| COMMITS=$(git log --oneline --no-decorate HEAD..upstream/main | head -10) | |
| echo "commits<<EOF" >> $GITHUB_OUTPUT | |
| echo "$COMMITS" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| - name: Create Issue for Updates | |
| if: steps.check.outputs.updates_available == 'true' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const behind = '${{ steps.check.outputs.behind_count }}'; | |
| const ahead = '${{ steps.check.outputs.ahead_count }}'; | |
| const commits = `${{ steps.commits.outputs.commits }}`; | |
| const title = `🔄 Upstream Updates Available (${behind} commits)`; | |
| const body = `## Upstream Updates Available | |
| The original Inbox Zero repository has **${behind} new commits** since your last sync. | |
| ### Your Status | |
| - 🔴 Behind upstream by: **${behind} commits** | |
| - 🟢 Ahead of upstream by: **${ahead} commits** (your custom changes) | |
| ### Recent Upstream Changes | |
| \`\`\` | |
| ${commits} | |
| \`\`\` | |
| ### Action Required | |
| Follow the steps in \`FORK-MAINTENANCE-GUIDE.md\` to sync: | |
| 1. Review changes: \`git log HEAD..upstream/main --oneline\` | |
| 2. Merge updates: \`git merge upstream/main\` | |
| 3. Resolve any conflicts | |
| 4. Test locally: \`pnpm install && pnpm run build && pnpm run dev\` | |
| 5. Deploy: \`git push origin main\` | |
| ### Quick Commands | |
| \`\`\`bash | |
| cd "/Users/jra/Documents/Cursor Projects/inbox-zero" | |
| git fetch upstream | |
| git merge upstream/main | |
| # Resolve conflicts if any | |
| pnpm install | |
| pnpm run build | |
| pnpm run dev | |
| # Test, then push | |
| git push origin main | |
| \`\`\` | |
| --- | |
| *This issue was automatically created by the upstream update checker.* | |
| *See [FORK-MAINTENANCE-GUIDE.md](../blob/main/FORK-MAINTENANCE-GUIDE.md) for detailed instructions.*`; | |
| // Check if an issue already exists | |
| const issues = await github.rest.issues.listForRepo({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| state: 'open', | |
| labels: 'upstream-updates' | |
| }); | |
| if (issues.data.length === 0) { | |
| await github.rest.issues.create({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| title: title, | |
| body: body, | |
| labels: ['upstream-updates', 'maintenance'] | |
| }); | |
| console.log('✅ Created new issue for upstream updates'); | |
| } else { | |
| console.log('ℹ️ Issue already exists, skipping creation'); | |
| } | |
| - name: Summary | |
| run: | | |
| echo "## Upstream Update Check Results" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "- Behind upstream: ${{ steps.check.outputs.behind_count }} commits" >> $GITHUB_STEP_SUMMARY | |
| echo "- Ahead of upstream: ${{ steps.check.outputs.ahead_count }} commits (your custom changes)" >> $GITHUB_STEP_SUMMARY | |
| echo "- Updates available: ${{ steps.check.outputs.updates_available }}" >> $GITHUB_STEP_SUMMARY | |
| if [ "${{ steps.check.outputs.updates_available }}" = "true" ]; then | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "⚠️ **Action required:** Updates are available. An issue has been created." >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "✅ **No action needed:** Your fork is up-to-date!" >> $GITHUB_STEP_SUMMARY | |
| fi | |