CI Auto-Fix #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
| # Generated by climate publish. | |
| name: CI Auto-Fix | |
| on: | |
| workflow_run: | |
| workflows: ["CI"] | |
| types: [completed] | |
| permissions: | |
| contents: write | |
| actions: write | |
| concurrency: | |
| group: ci-autofix-${{ github.event.workflow_run.head_branch }} | |
| cancel-in-progress: true | |
| jobs: | |
| autofix: | |
| if: > | |
| github.event.workflow_run.conclusion == 'failure' && | |
| github.event.workflow_run.head_repository.full_name == github.repository && | |
| github.event.workflow_run.head_branch != '' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout failed branch | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event.workflow_run.head_branch }} | |
| - name: Stop on stale branch head | |
| id: freshness | |
| run: | | |
| current_sha="$(git rev-parse HEAD)" | |
| expected_sha="${{ github.event.workflow_run.head_sha }}" | |
| if [ "$current_sha" != "$expected_sha" ]; then | |
| echo "should_skip=true" >> "$GITHUB_OUTPUT" | |
| echo "Branch advanced from ${expected_sha} to ${current_sha}; skipping stale auto-fix run." | |
| exit 0 | |
| fi | |
| echo "should_skip=false" >> "$GITHUB_OUTPUT" | |
| - name: Set up Go | |
| if: steps.freshness.outputs.should_skip != 'true' | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version-file: go.mod | |
| - name: Download dependencies | |
| if: steps.freshness.outputs.should_skip != 'true' | |
| run: go mod download | |
| - name: Run gofmt auto-fix | |
| if: steps.freshness.outputs.should_skip != 'true' | |
| run: gofmt -w . | |
| - name: Run golangci-lint auto-fix | |
| id: golangci_autofix | |
| if: steps.freshness.outputs.should_skip != 'true' | |
| continue-on-error: true | |
| uses: golangci/golangci-lint-action@v7 | |
| with: | |
| version: v2.11.3 | |
| args: --fix | |
| - name: Detect changes | |
| id: changes | |
| if: steps.freshness.outputs.should_skip != 'true' | |
| run: | | |
| if git diff --quiet; then | |
| echo "changed=false" >> "$GITHUB_OUTPUT" | |
| echo "No auto-fixable changes detected." | |
| exit 0 | |
| fi | |
| echo "changed=true" >> "$GITHUB_OUTPUT" | |
| - name: Commit and push auto-fixes | |
| if: steps.changes.outputs.changed == 'true' | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git add -A | |
| git commit -m "ci: auto-fix formatting and lint" | |
| git push origin HEAD:${{ github.event.workflow_run.head_branch }} | |
| - name: Re-dispatch CI | |
| if: steps.changes.outputs.changed == 'true' | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| curl --fail --silent --show-error \ | |
| -X POST \ | |
| -H "Authorization: Bearer ${GH_TOKEN}" \ | |
| -H "Accept: application/vnd.github+json" \ | |
| https://api.github.com/repos/${{ github.repository }}/actions/workflows/ci.yml/dispatches \ | |
| -d '{"ref":"${{ github.event.workflow_run.head_branch }}"}' |