Skip to content

Commit 925f6fd

Browse files
frasertweedaleblackheaven
authored andcommitted
ci: properly handle multiple changed advisories
The updated CI does not properly interpret the list of changed files so that only modified advisories get checked (when *only* advisories changed). - The "changed files" list could include non-advisories (e.g. CI workflow YAML files). Update the `advisories_changed` job to output the filtered file list (as JSON). - Remove the `changed_files` job. It is not needed. We output the matched files from the `advisories_changed` job. - There were some `bash` command parsing errors when including the JSON in the command arguments. Propagate it in environment variables instead. - `$CHANGED_ADVISORIES` outputs only the first element of the array. Use `printf` to print the array, one file per line. - Finally, it seems that `jq` is present in the CI environment and we can remove the "Setup jq" step.
1 parent f40ab7a commit 925f6fd

File tree

2 files changed

+17
-25
lines changed

2 files changed

+17
-25
lines changed

.github/workflows/check-advisories-standalone.yml

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,24 @@ jobs:
2020
runs-on: ubuntu-22.04
2121
outputs:
2222
should_skip: ${{ steps.skip_check.outputs.should_skip }}
23+
changed_files: ${{ steps.process-changed-files.outputs.out }}
2324
steps:
2425
- id: skip_check
2526
uses: fkirc/[email protected]
2627
with:
2728
concurrent_skipping: "never"
2829
skip_after_successful_duplicate: "true"
29-
paths: '["advisories/**"]'
30+
paths: '["advisories/**", "EXAMPLE_ADVISORY.md"]'
3031
do_not_skip: '["push", "workflow_dispatch", "schedule"]'
32+
- id: process-changed-files
33+
name: Extract matched files list
34+
env:
35+
PATHS_RESULT: ${{ steps.skip_check.outputs.paths_result }}
36+
run: |
37+
echo -n 'out=' >> "$GITHUB_OUTPUT"
38+
# See https://github.com/fkirc/skip-duplicate-actions#paths_result
39+
printenv PATHS_RESULT \
40+
| jq --compact-output .global.matched_files >> "$GITHUB_OUTPUT"
3141
code_hash:
3242
name: Compute code directory hash
3343
runs-on: ubuntu-22.04
@@ -40,30 +50,12 @@ jobs:
4050
run: |
4151
code_hash=$(git rev-parse HEAD:code)
4252
echo "code-hash=$code_hash" >> "$GITHUB_OUTPUT"
43-
changed_files:
44-
name: Debug
45-
needs: [tools_changed, advisories_changed, code_hash]
46-
if: ${{ needs.tools_changed.outputs.should_skip == 'true' && needs.advisories_changed.outputs.should_skip != 'true' }}
47-
runs-on: ubuntu-22.04
48-
permissions:
49-
pull-requests: read
50-
outputs:
51-
advisories: ${{ steps.changed-files.outputs.all_changed_files }}
52-
steps:
53-
- name: Get changed files
54-
id: changed-files
55-
uses: tj-actions/changed-files@v37
56-
with:
57-
json: "true"
58-
59-
- name: List all changed files
60-
run: echo "${{ steps.changed-files.outputs.all_changed_files }}"
6153
check_advisories:
6254
name: Invoke check-advisories workflow
63-
needs: [tools_changed, advisories_changed, code_hash, changed_files]
55+
needs: [tools_changed, advisories_changed, code_hash]
6456
if: ${{ needs.tools_changed.outputs.should_skip == 'true' && needs.advisories_changed.outputs.should_skip != 'true' }}
6557
uses: ./.github/workflows/check-advisories.yml
6658
with:
6759
fetch-key: hsec-tools-${{ needs.code_hash.outputs.code_hash }}
6860
is-artifact: false
69-
changed-advisories: ${{ needs.changed_files.outputs.advisories }}
61+
changed-advisories: ${{ needs.advisories_changed.outputs.changed_files }}

.github/workflows/check-advisories.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,19 @@ jobs:
3737
path: ~/.local/dockerImages
3838
fail-on-cache-miss: true
3939
- run: docker load -i ~/.local/dockerImages/hsec-tools
40-
- name: 'Setup jq'
41-
uses: dcarbone/[email protected]
4240
- name: Run advisory syntax checks
41+
env:
42+
CHANGED_ADVISORIES_JSON: ${{ inputs.changed-advisories }}
4343
run: |
44-
CHANGED_ADVISORIES=( $(echo "${{ inputs.changed-advisories }}" | jq -r '.[]') )
44+
CHANGED_ADVISORIES=( $(printenv CHANGED_ADVISORIES_JSON | jq -r '.[]') )
4545
cd source
4646
RESULT=0
4747
# Remove the begining of the README to extract the example.
4848
(echo '```toml'; sed -e '1,/```toml/d' README.md) > EXAMPLE_README.md
4949
while read FILE ; do
5050
echo -n "$FILE: "
5151
docker run --rm -v $PWD:/advisories haskell/hsec-tools:latest /bin/hsec-tools check "advisories/$FILE" || RESULT=1
52-
done < <([ ${#CHANGED_ADVISORIES[@]} -gt 0 ] && echo $CHANGED_ADVISORIES || find advisories EXAMPLE_README.md EXAMPLE_ADVISORY.md -type f -name "*.md")
52+
done < <([ ${#CHANGED_ADVISORIES[@]} -gt 0 ] && printf "%s\n" "${CHANGED_ADVISORIES[@]}" || find advisories EXAMPLE_README.md EXAMPLE_ADVISORY.md -type f -name "*.md")
5353
exit $RESULT
5454
- name: Run advisory uniqueness checks
5555
run: |

0 commit comments

Comments
 (0)