Skip to content

Commit 2165335

Browse files
committed
ci: trunk-check-fix
1 parent 2c6eeae commit 2165335

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

.github/workflows/scans.yml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,34 @@ jobs:
154154
trunk:
155155
permissions:
156156
checks: write
157-
contents: read
157+
contents: write
158158

159159
runs-on: ubuntu-latest
160160
steps:
161161
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
162162

163163
- uses: trunk-io/trunk-action@4d5ecc89b2691705fd08c747c78652d2fc806a94 # v1
164+
165+
- name: trunk check --fix
166+
if: ${{ failure() && github.event_name == 'pull_request' }}
167+
run: |
168+
git config user.email "${GITHUB_ACTOR_ID}+${GITHUB_ACTOR}@users.noreply.github.com"
169+
git config user.name "${GITHUB_ACTOR}"
170+
git fetch origin "${GITHUB_HEAD_REF}" --depth 1
171+
git switch "${GITHUB_HEAD_REF}"
172+
173+
git fetch origin "${DEFAULT_BRANCH}" --depth 1
174+
upstream=$(git rev-parse "${DEFAULT_BRANCH}")
175+
"${TRUNK_PATH}" check --ci --upstream "${upstream}" --fix
176+
177+
if [[ -n "$(git diff --name-only)" ]]; then
178+
git commit --all --message "${COMMIT_MESSAGE}"
179+
git push origin HEAD:refs/heads/"${GITHUB_HEAD_REF}"
180+
fi
181+
env:
182+
COMMIT_MESSAGE: "fix: trunk check --fix"
183+
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
184+
# https://api.github.com/users/trunk-io
185+
GITHUB_ACTOR: trunk-io
186+
GITHUB_ACTOR_ID: 74779146
187+
GITHUB_SHA: ${{ github.event.pull_request.head.sha || github.sha }}

0 commit comments

Comments
 (0)