Skip to content

Commit f0f768e

Browse files
authored
feat: limit zizmor scan to changed workflows (#9)
Modify the workflow to extract the list of changed workflow files and pass them directly to zizmor. This prevents scanning all workflows when only a subset has changed.
1 parent bc3b24a commit f0f768e

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

.github/workflows/github_actions_scan.yml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
check-changes:
2323
runs-on: 'ubuntu-latest'
2424
outputs:
25-
changed: '${{ steps.check.outputs.changed }}'
25+
files: '${{ steps.check.outputs.files }}'
2626
permissions:
2727
contents: 'read'
2828
steps:
@@ -39,19 +39,16 @@ jobs:
3939
GIT_HEAD_SHA: '${{ github.event.pull_request.head.sha }}'
4040
GIT_BASE_SHA: '${{ github.event.pull_request.base.sha }}'
4141
run: |
42-
changed="false"
43-
if git diff --name-only "${GIT_BASE_SHA}" "${GIT_HEAD_SHA}" | grep -E '^\.github/workflows/.+\.ya?ml$' > /dev/null; then
44-
changed="true"
45-
fi
46-
echo "changed=$changed" >> "$GITHUB_OUTPUT"
42+
files=$(git diff --name-only "${GIT_BASE_SHA}" "${GIT_HEAD_SHA}" | grep -E '^\.github/workflows/.+\.ya?ml$' | xargs || true)
43+
echo "files=$files" >> "$GITHUB_OUTPUT"
4744
4845
zizmor-scan:
4946
needs: ['check-changes']
5047
runs-on: 'ubuntu-latest'
5148
if: >-
5249
inputs.wif_provider != '' ||
5350
(
54-
needs.check-changes.outputs.changed == 'true' &&
51+
needs.check-changes.outputs.files != '' &&
5552
github.event_name == 'pull_request_target' &&
5653
!startsWith(github.workflow_ref, format('{0}/', github.repository))
5754
)
@@ -70,6 +67,7 @@ jobs:
7067
shell: 'bash'
7168
env:
7269
GH_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
70+
CHANGED_FILES: '${{ needs.check-changes.outputs.files }}'
7371
run: >-
7472
docker run
7573
--rm
@@ -80,7 +78,7 @@ jobs:
8078
--format sarif
8179
--no-ignores
8280
--
83-
.github/workflows
81+
${CHANGED_FILES}
8482
> zizmor.sarif.json
8583
- name: 'Enrich SARIF with GitHub metadata'
8684
shell: 'bash'
@@ -171,6 +169,7 @@ jobs:
171169
shell: 'bash'
172170
env:
173171
GH_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
172+
CHANGED_FILES: '${{ needs.check-changes.outputs.files }}'
174173
run: >-
175174
docker run
176175
--rm
@@ -180,4 +179,4 @@ jobs:
180179
"ghcr.io/zizmorcore/zizmor:${ZIZMOR_VERSION}@${ZIZMOR_DOCKER_DIGEST}"
181180
--format github
182181
--
183-
.github/workflows
182+
${CHANGED_FILES}

0 commit comments

Comments
 (0)