|
| 1 | +name: 🔄 Weekly Dependency Update |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + # Run weekly on Monday at 9 AM UTC |
| 6 | + - cron: '0 9 * * 1' |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + dry-run: |
| 10 | + description: 'Check for updates without creating PR' |
| 11 | + required: false |
| 12 | + type: boolean |
| 13 | + default: false |
| 14 | + |
| 15 | +permissions: |
| 16 | + contents: read |
| 17 | + |
| 18 | +jobs: |
| 19 | + check-updates: |
| 20 | + name: Check for dependency updates |
| 21 | + runs-on: ubuntu-latest |
| 22 | + permissions: |
| 23 | + contents: read |
| 24 | + outputs: |
| 25 | + has-updates: ${{ steps.check.outputs.has-updates }} |
| 26 | + steps: |
| 27 | + - name: Checkout repository |
| 28 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 29 | + with: |
| 30 | + fetch-depth: 0 |
| 31 | + persist-credentials: false |
| 32 | + |
| 33 | + - name: Setup Node.js |
| 34 | + uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0 |
| 35 | + with: |
| 36 | + node-version-file: .node-version |
| 37 | + cache: '' |
| 38 | + |
| 39 | + - name: Setup pnpm |
| 40 | + uses: pnpm/action-setup@b307475762933b98ed359c036b0e51f26b63b74b # v5.0.0 |
| 41 | + |
| 42 | + - name: Install dependencies |
| 43 | + run: pnpm install --frozen-lockfile |
| 44 | + |
| 45 | + - name: Check for npm updates |
| 46 | + id: check |
| 47 | + run: | |
| 48 | + echo "Checking for npm package updates..." |
| 49 | + HAS_UPDATES=false |
| 50 | + NPM_UPDATES=$(pnpm outdated 2>/dev/null || true) |
| 51 | + if [ -n "$NPM_UPDATES" ] && ! echo "$NPM_UPDATES" | grep -q "No outdated"; then |
| 52 | + echo "npm packages have updates available" |
| 53 | + HAS_UPDATES=true |
| 54 | + fi |
| 55 | + echo "has-updates=$HAS_UPDATES" >> $GITHUB_OUTPUT |
| 56 | +
|
| 57 | + apply-updates: |
| 58 | + name: Apply updates with Claude Code |
| 59 | + needs: check-updates |
| 60 | + if: needs.check-updates.outputs.has-updates == 'true' && inputs.dry-run != true |
| 61 | + runs-on: ubuntu-latest |
| 62 | + permissions: |
| 63 | + contents: write |
| 64 | + pull-requests: write |
| 65 | + steps: |
| 66 | + - name: Checkout repository |
| 67 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 68 | + with: |
| 69 | + fetch-depth: 0 |
| 70 | + persist-credentials: false |
| 71 | + |
| 72 | + - name: Setup Node.js |
| 73 | + uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0 |
| 74 | + with: |
| 75 | + node-version-file: .node-version |
| 76 | + cache: '' |
| 77 | + |
| 78 | + - name: Setup pnpm |
| 79 | + uses: pnpm/action-setup@b307475762933b98ed359c036b0e51f26b63b74b # v5.0.0 |
| 80 | + |
| 81 | + - name: Install dependencies |
| 82 | + run: pnpm install --frozen-lockfile |
| 83 | + |
| 84 | + - name: Install Claude Code |
| 85 | + run: npm install -g @anthropic-ai/claude-code |
| 86 | + |
| 87 | + - name: Create update branch |
| 88 | + id: branch |
| 89 | + run: | |
| 90 | + BRANCH_NAME="weekly-update-$(date +%Y%m%d)" |
| 91 | + git config user.name "github-actions[bot]" |
| 92 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 93 | + git checkout -b "$BRANCH_NAME" |
| 94 | + echo "branch=$BRANCH_NAME" >> $GITHUB_OUTPUT |
| 95 | +
|
| 96 | + - name: Run updating skill with Claude Code |
| 97 | + id: claude |
| 98 | + timeout-minutes: 30 |
| 99 | + env: |
| 100 | + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} |
| 101 | + CI: 'true' |
| 102 | + GITHUB_ACTIONS: 'true' |
| 103 | + run: | |
| 104 | + if [ -z "$ANTHROPIC_API_KEY" ]; then |
| 105 | + echo "⚠️ ANTHROPIC_API_KEY not set - skipping automated update" |
| 106 | + echo "success=false" >> $GITHUB_OUTPUT |
| 107 | + exit 0 |
| 108 | + fi |
| 109 | +
|
| 110 | + claude --print --dangerously-skip-permissions \ |
| 111 | + --model sonnet \ |
| 112 | + "/updating - Run the updating skill to update all dependencies. Create atomic commits for each update. You are running in CI mode - skip builds and tests. Do not push or create a PR." \ |
| 113 | + 2>&1 | tee claude-output.log |
| 114 | +
|
| 115 | + if [ $? -eq 0 ]; then |
| 116 | + echo "success=true" >> $GITHUB_OUTPUT |
| 117 | + else |
| 118 | + echo "success=false" >> $GITHUB_OUTPUT |
| 119 | + fi |
| 120 | +
|
| 121 | + - name: Check for changes |
| 122 | + id: changes |
| 123 | + run: | |
| 124 | + if [ -n "$(git status --porcelain)" ] || [ "$(git rev-list --count HEAD ^origin/main)" -gt 0 ]; then |
| 125 | + echo "has-changes=true" >> $GITHUB_OUTPUT |
| 126 | + else |
| 127 | + echo "has-changes=false" >> $GITHUB_OUTPUT |
| 128 | + fi |
| 129 | +
|
| 130 | + - name: Push branch |
| 131 | + if: steps.claude.outputs.success == 'true' && steps.changes.outputs.has-changes == 'true' |
| 132 | + env: |
| 133 | + BRANCH_NAME: ${{ steps.branch.outputs.branch }} |
| 134 | + run: git push origin "$BRANCH_NAME" |
| 135 | + |
| 136 | + - name: Create Pull Request |
| 137 | + if: steps.claude.outputs.success == 'true' && steps.changes.outputs.has-changes == 'true' |
| 138 | + env: |
| 139 | + GH_TOKEN: ${{ github.token }} |
| 140 | + BRANCH_NAME: ${{ steps.branch.outputs.branch }} |
| 141 | + run: | |
| 142 | + COMMITS=$(git log --oneline origin/main..HEAD) |
| 143 | + COMMIT_COUNT=$(git rev-list --count origin/main..HEAD) |
| 144 | +
|
| 145 | + gh pr create \ |
| 146 | + --title "chore(deps): weekly dependency update ($(date +%Y-%m-%d))" \ |
| 147 | + --body "## Weekly Dependency Update |
| 148 | +
|
| 149 | +Automated weekly update of npm packages. |
| 150 | + |
| 151 | +### Commits (${COMMIT_COUNT}) |
| 152 | + |
| 153 | +<details> |
| 154 | +<summary>View commit history</summary> |
| 155 | + |
| 156 | +\`\`\` |
| 157 | +${COMMITS} |
| 158 | +\`\`\` |
| 159 | + |
| 160 | +</details> |
| 161 | + |
| 162 | +--- |
| 163 | + |
| 164 | +<sub>Generated by [weekly-update.yml](.github/workflows/weekly-update.yml)</sub>" \ |
| 165 | + --draft \ |
| 166 | + --head "$BRANCH_NAME" \ |
| 167 | + --base main |
| 168 | + |
| 169 | + - name: Upload Claude output |
| 170 | + if: always() |
| 171 | + uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0 |
| 172 | + with: |
| 173 | + name: claude-output-${{ github.run_id }} |
| 174 | + path: claude-output.log |
| 175 | + retention-days: 7 |
0 commit comments