|
| 1 | +name: Update Go Dependencies |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + # Run every Monday at 9:00 AM UTC |
| 6 | + - cron: '0 9 * * 1' |
| 7 | + workflow_dispatch: # Allow manual trigger |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: write |
| 11 | + pull-requests: write |
| 12 | + |
| 13 | +jobs: |
| 14 | + update-dependencies: |
| 15 | + name: Update Go Dependencies |
| 16 | + runs-on: ubuntu-24.04 |
| 17 | + |
| 18 | + steps: |
| 19 | + - name: Checkout code |
| 20 | + uses: actions/checkout@v5 |
| 21 | + with: |
| 22 | + ref: master |
| 23 | + fetch-depth: 0 |
| 24 | + |
| 25 | + - name: Set up Go |
| 26 | + uses: actions/setup-go@v6 |
| 27 | + with: |
| 28 | + go-version: '1.25' |
| 29 | + |
| 30 | + - name: Update Go dependencies |
| 31 | + run: make update-go-deps |
| 32 | + |
| 33 | + - name: Tidy dependencies |
| 34 | + run: make tidy |
| 35 | + |
| 36 | + - name: Generate manifests |
| 37 | + run: make generate manifests |
| 38 | + |
| 39 | + - name: Format and lint fix |
| 40 | + run: make fmt lint-fix |
| 41 | + |
| 42 | + - name: Check for changes |
| 43 | + id: check_changes |
| 44 | + run: | |
| 45 | + if [ -n "$(git status --porcelain)" ]; then |
| 46 | + echo "has_changes=true" >> $GITHUB_OUTPUT |
| 47 | + else |
| 48 | + echo "has_changes=false" >> $GITHUB_OUTPUT |
| 49 | + fi |
| 50 | +
|
| 51 | + - name: Commit and push changes |
| 52 | + if: steps.check_changes.outputs.has_changes == 'true' |
| 53 | + run: | |
| 54 | + git config --local user.email "[email protected]" |
| 55 | + git config --local user.name "koperator-bot" |
| 56 | + git checkout -b automated/update-go-deps |
| 57 | + git add . |
| 58 | + git commit -m "chore(deps): update Go dependencies" |
| 59 | +
|
| 60 | + # Push using PAT |
| 61 | + git remote set-url origin https://x-access-token:${{ secrets.PAT }}@github.com/${{ github.repository }}.git |
| 62 | + git push origin automated/update-go-deps --force |
| 63 | +
|
| 64 | + - name: Create Pull Request with GitHub CLI |
| 65 | + if: steps.check_changes.outputs.has_changes == 'true' |
| 66 | + env: |
| 67 | + GH_TOKEN: ${{ secrets.PAT }} |
| 68 | + run: | |
| 69 | + # Define PR content |
| 70 | + PR_TITLE="chore(deps): update Go dependencies" |
| 71 | + PR_BODY="## Automated Go Dependencies Update |
| 72 | +
|
| 73 | + This PR updates Go module dependencies to their latest versions. |
| 74 | +
|
| 75 | + ### Changes made: |
| 76 | + - Updated Go module dependencies via \`make update-go-deps\` |
| 77 | + - Regenerated manifests via \`make generate manifests\` |
| 78 | + - Applied formatting and linting fixes via \`make fmt lint-fix\` |
| 79 | +
|
| 80 | + Please review the changes and ensure all tests pass before merging. |
| 81 | +
|
| 82 | + --- |
| 83 | + *Generated by https://github.com/adobe/koperator/blob/master/.github/workflows/update-go-deps.yml*" |
| 84 | +
|
| 85 | + # Check if PR already exists and get its state |
| 86 | + PR_STATE=$(gh pr view automated/update-go-deps --json state --jq .state 2>/dev/null || echo "NOT_FOUND") |
| 87 | +
|
| 88 | + if [ "$PR_STATE" = "OPEN" ]; then |
| 89 | + echo "PR already exists and is open, updating..." |
| 90 | + gh pr edit automated/update-go-deps --title "$PR_TITLE" --body "$PR_BODY" |
| 91 | + elif [ "$PR_STATE" = "CLOSED" ] || [ "$PR_STATE" = "MERGED" ]; then |
| 92 | + echo "PR exists but is $PR_STATE, attempting to reopen..." |
| 93 | + if gh pr reopen automated/update-go-deps 2>/dev/null; then |
| 94 | + echo "Successfully reopened PR, updating..." |
| 95 | + gh pr edit automated/update-go-deps --title "$PR_TITLE" --body "$PR_BODY" |
| 96 | + else |
| 97 | + echo "Could not reopen PR (likely branch deleted), creating new PR..." |
| 98 | + gh pr create \ |
| 99 | + --title "$PR_TITLE" \ |
| 100 | + --body "$PR_BODY" \ |
| 101 | + --head automated/update-go-deps \ |
| 102 | + --base master \ |
| 103 | + --label "dependencies,go,automated" |
| 104 | + fi |
| 105 | + else |
| 106 | + echo "Creating new PR..." |
| 107 | + gh pr create \ |
| 108 | + --title "$PR_TITLE" \ |
| 109 | + --body "$PR_BODY" \ |
| 110 | + --head automated/update-go-deps \ |
| 111 | + --base master \ |
| 112 | + --label "dependencies,go,automated" |
| 113 | + fi |
| 114 | +
|
0 commit comments