-
Notifications
You must be signed in to change notification settings - Fork 123
workflows: Auto go mod tidy dependabot PRs #2776
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
stevenhorsman
wants to merge
2
commits into
confidential-containers:main
Choose a base branch
from
stevenhorsman:add-auto-go-mod-on-dependabot-PRs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| name: Automatically run go mod tidy on dependabot PRs | ||
| on: | ||
| pull_request_target: | ||
| branches: [ main ] | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| permissions: {} | ||
|
|
||
| jobs: | ||
| tidy-dependabot-pr: | ||
stevenhorsman marked this conversation as resolved.
Fixed
Show fixed
Hide fixed
|
||
| name: Run go mod tidy on dependabot PR | ||
| runs-on: ubuntu-24.04 | ||
| if: github.event.pull_request.user.login == 'dependabot[bot]' | ||
| permissions: | ||
| contents: write # We need permissions to push new content to the PR | ||
| pull-requests: write # Permissions to create a new PR and close the original | ||
|
|
||
| steps: | ||
| - name: Checkout the PR Code | ||
| uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 | ||
| with: | ||
| fetch-depth: 0 | ||
| ref: ${{ github.event.pull_request.head.sha }} | ||
| persist-credentials: false | ||
|
|
||
| - name: Rebase the code | ||
| if: github.event_name == 'pull_request_target' | ||
| working-directory: ./ | ||
| run: | | ||
| ./hack/ci-helper.sh rebase-atop-of-the-latest-target-branch | ||
|
|
||
| - name: Read properties from versions.yaml | ||
| id: read-properties | ||
| run: | | ||
| go_version="$(yq '.tools.golang' src/cloud-api-adaptor/versions.yaml)" | ||
| [ -n "$go_version" ] | ||
| echo "go_version=${go_version}" >> "${GITHUB_OUTPUT}" | ||
|
|
||
| - name: Setup Golang version | ||
| uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0 | ||
| with: | ||
| go-version: ${{ steps.read-properties.outputs.go_version }} | ||
| cache-dependency-path: "**/go.sum" | ||
| cache: false | ||
|
|
||
| - name: Go tidy check | ||
| run: | | ||
| ./hack/go-tidy.sh | ||
| echo "Go mod tidy made: $(git diff)" | ||
|
|
||
| - name: Check if go mod tidy produces changes | ||
| id: go-mod-tidy-changed | ||
| run: | | ||
| if [ -n "$(git status --porcelain)" ]; then | ||
| echo "changed=true" >> "${GITHUB_OUTPUT}" | ||
| else | ||
| echo "changed=false" >> "${GITHUB_OUTPUT}" | ||
| fi | ||
|
|
||
| - name: Commit and push changes | ||
| if: steps.go-mod-tidy-changed.outputs.changed == 'true' | ||
| # uses: devops-infra/action-commit-push@8a2d9d73c3f506468129be2e4409e60dbed70357 # v1.0.3 | ||
| # with: | ||
| # github_token: ${{ secrets.GITHUB_TOKEN }} | ||
| # commit_message: "chore: Auto-run go mod tidy after Dependabot update" | ||
| run: | | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "github-actions[bot]@users.noreply.github.com" | ||
|
|
||
| git checkout -b "${UPDATED_BRANCH}" | ||
| git add . | ||
| git commit -m "Apply automated changes to ${ORIGINAL_BRANCH}" | ||
| git push origin "${UPDATED_BRANCH}" | ||
| env: | ||
| ORIGINAL_BRANCH: ${{ github.event.pull_request.head.ref }} | ||
| UPDATED_BRANCH: "automated-updates-${{ github.event.pull_request.number }}" | ||
|
|
||
|
|
||
| - name: Create new pull request | ||
| if: steps.go-mod-tidy-changed.outputs.changed == 'true' | ||
| id: create_pr | ||
| run: | | ||
| gh pr create \ | ||
| --title "Automated Fixes for ${ORIGINAL_BRANCH}" \ | ||
| --body "This PR applies automated changes to the branch associated with PR #${{ github.event.pull_request.number }}." \ | ||
Check warningCode scanning / zizmor code injection via template expansion Warning
code injection via template expansion
|
||
| --base "${ORIGINAL_BRANCH}" \ | ||
| --head "${UPDATED_BRANCH}" | ||
| echo "pr_number=$(gh pr view --json number --jq '.number') >> "${GITHUB_OUTPUT}" | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| ORIGINAL_BRANCH: ${{ github.event.pull_request.head.ref }} | ||
| UPDATED_BRANCH: "automated-updates-${{ github.event.pull_request.number }}" | ||
|
|
||
| - name: Close original Pull Request | ||
| if: steps.go-mod-tidy-changed.outputs.changed == 'true' | ||
| run: gh pr close "${ORIGINAL_PR}" --comment "PR replaced with ${REPLACEMENT_PR}" | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| ORIGINAL_PR: ${{ github.event.pull_request.number }} | ||
| REPLACEMENT_PR: ${{ steps.create_pr.outputs.pr_number }} | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check failure
Code scanning / zizmor
use of fundamentally insecure workflow trigger Error