Skip to content

Commit daf2de2

Browse files
committed
fix(workflows): fix generate.yml zizmor findings and git push auth
- Move permissions from workflow to job level - Add persist-credentials: false to checkout actions - Fix git push authentication using GITHUB_TOKEN with https URL - Add job-level permissions for validate job
1 parent deaf5c8 commit daf2de2

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

.github/workflows/generate.yml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ on:
2121
type: boolean
2222

2323
permissions:
24-
contents: write
25-
pull-requests: write
24+
contents: read
2625

2726
jobs:
2827
fetch_and_update:
2928
name: Sync OpenAPI definition
3029
runs-on: ubuntu-latest
30+
permissions:
31+
contents: write
32+
pull-requests: write
3133
outputs:
3234
has_changes: ${{ steps.check.outputs.has_changes }}
3335
steps:
@@ -42,7 +44,7 @@ jobs:
4244
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
4345
with:
4446
autocrlf: false
45-
token: ${{ secrets.GITHUB_TOKEN }}
47+
persist-credentials: false
4648

4749
- uses: SocketDev/socket-registry/.github/actions/setup-and-install@e145a6b355d614054e4df3d49ba5218812f42b3e # main
4850

@@ -90,11 +92,16 @@ jobs:
9092
9193
- name: Commit and push changes
9294
if: steps.check.outputs.has_changes == 'true'
95+
env:
96+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9397
run: |
9498
git checkout -b automated/open-api
9599
git add .
96-
git commit -m "fix(openapi): sync with openapi definition"
97-
git push origin automated/open-api -fu --no-verify
100+
git commit -m "fix(openapi): sync with openapi definition" --no-verify
101+
102+
# Use gh to push (works with GITHUB_TOKEN in env)
103+
gh repo set-default ${{ github.repository }}
104+
git push https://x-access-token:${GH_TOKEN}@github.com/${{ github.repository }}.git automated/open-api -f
98105
99106
- name: Create Pull Request
100107
if: steps.check.outputs.has_changes == 'true'
@@ -131,12 +138,15 @@ jobs:
131138
needs: fetch_and_update
132139
if: needs.fetch_and_update.outputs.has_changes == 'true'
133140
runs-on: ubuntu-latest
141+
permissions:
142+
contents: read
134143
outputs:
135144
has_changes: ${{ steps.check.outputs.has_changes }}
136145
steps:
137146
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
138147
with:
139148
autocrlf: false
149+
persist-credentials: false
140150
ref: automated/open-api
141151

142152
- uses: SocketDev/socket-registry/.github/actions/setup-and-install@e145a6b355d614054e4df3d49ba5218812f42b3e # main

0 commit comments

Comments
 (0)