Update Go Dependencies #11
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: Update Go Dependencies | |
| on: | |
| schedule: | |
| # Run every Monday at 9:00 AM UTC | |
| - cron: '0 9 * * 1' | |
| workflow_dispatch: # Allow manual trigger | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| update-dependencies: | |
| name: Update Go Dependencies | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v5 | |
| with: | |
| ref: master | |
| fetch-depth: 0 | |
| - name: Set up Go | |
| uses: actions/setup-go@v6 | |
| with: | |
| go-version: '1.25' | |
| - name: Update Go dependencies | |
| run: make update-go-deps | |
| - name: Tidy dependencies | |
| run: make tidy | |
| - name: Generate manifests | |
| run: make generate manifests | |
| - name: Format and lint fix | |
| run: make fmt lint-fix | |
| - name: Check for changes | |
| id: check_changes | |
| run: | | |
| if [ -n "$(git status --porcelain)" ]; then | |
| echo "has_changes=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "has_changes=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Commit and push changes | |
| if: steps.check_changes.outputs.has_changes == 'true' | |
| run: | | |
| git config --local user.email "[email protected]" | |
| git config --local user.name "koperator-bot" | |
| git checkout -b automated/update-go-deps | |
| git add . | |
| git commit -m "chore(deps): update Go dependencies" | |
| # Push using PAT | |
| git remote set-url origin https://x-access-token:${{ secrets.PAT }}@github.com/${{ github.repository }}.git | |
| git push origin automated/update-go-deps --force | |
| - name: Create Pull Request with GitHub CLI | |
| if: steps.check_changes.outputs.has_changes == 'true' | |
| env: | |
| GH_TOKEN: ${{ secrets.PAT }} | |
| run: | | |
| # Define PR content | |
| PR_TITLE="chore(deps): update Go dependencies" | |
| PR_BODY="## Automated Go Dependencies Update | |
| This PR updates Go module dependencies to their latest versions. | |
| ### Changes made: | |
| - Updated Go module dependencies via \`make update-go-deps\` | |
| - Regenerated manifests via \`make generate manifests\` | |
| - Applied formatting and linting fixes via \`make fmt lint-fix\` | |
| Please review the changes and ensure all tests pass before merging. | |
| --- | |
| *Generated by https://github.com/adobe/koperator/blob/master/.github/workflows/update-go-deps.yml*" | |
| # Check if PR already exists and get its state | |
| PR_STATE=$(gh pr view automated/update-go-deps --json state --jq .state 2>/dev/null || echo "NOT_FOUND") | |
| if [ "$PR_STATE" = "OPEN" ]; then | |
| echo "PR already exists and is open, updating..." | |
| gh pr edit automated/update-go-deps --title "$PR_TITLE" --body "$PR_BODY" | |
| elif [ "$PR_STATE" = "CLOSED" ] || [ "$PR_STATE" = "MERGED" ]; then | |
| echo "PR exists but is $PR_STATE, attempting to reopen..." | |
| if gh pr reopen automated/update-go-deps 2>/dev/null; then | |
| echo "Successfully reopened PR, updating..." | |
| gh pr edit automated/update-go-deps --title "$PR_TITLE" --body "$PR_BODY" | |
| else | |
| echo "Could not reopen PR (likely branch deleted), creating new PR..." | |
| gh pr create \ | |
| --title "$PR_TITLE" \ | |
| --body "$PR_BODY" \ | |
| --head automated/update-go-deps \ | |
| --base master \ | |
| --label "dependencies,go,automated" | |
| fi | |
| else | |
| echo "Creating new PR..." | |
| gh pr create \ | |
| --title "$PR_TITLE" \ | |
| --body "$PR_BODY" \ | |
| --head automated/update-go-deps \ | |
| --base master \ | |
| --label "dependencies,go,automated" | |
| fi | |