Skip to content

Commit 7f976b5

Browse files
ci: Integrate zizmor checks to repo (#818)
That PR integrate one more static analysis tool, as CodeQL is good, but it not cover all cases Here is an article about zizmor value - https://blog.yossarian.net/2024/12/06/zizmor-ultralytics-injection zizmor repo - https://github.com/woodruffw/zizmor --------- Co-authored-by: George L. Yermulnik <[email protected]>
1 parent 79085a6 commit 7f976b5

File tree

10 files changed

+95
-59
lines changed

10 files changed

+95
-59
lines changed

.github/workflows/build-image-test.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3737
with:
3838
fetch-depth: 0
39+
persist-credentials: false
3940

4041
- name: Get changed Docker related files
4142
id: changed-files-specific

.github/workflows/build-image.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ jobs:
2121
steps:
2222
- name: Checkout code
2323
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
24+
with:
25+
persist-credentials: false
26+
2427
- name: Set up Docker Buildx
2528
uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3.10.0
2629
- name: Login to GitHub Container Registry
@@ -30,10 +33,13 @@ jobs:
3033
username: ${{ github.repository_owner }}
3134
password: ${{ secrets.GITHUB_TOKEN }}
3235
- name: Set tag for image
36+
env:
37+
REF_TYPE: ${{ github.ref_type }}
38+
REF_NAME: ${{ github.ref_name }}
3339
run: >-
3440
echo IMAGE_TAG=$(
35-
[ ${{ github.ref_type }} == 'tag' ]
36-
&& echo ${{ github.ref_name }}
41+
[ $REF_TYPE == 'tag' ]
42+
&& echo $REF_NAME
3743
|| echo 'latest'
3844
) >> $GITHUB_ENV
3945

.github/workflows/ci-cd.yml

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ on:
1010
- pre-commit-ci-update-config # pre-commit.ci always creates a PR
1111
pull_request:
1212
workflow_call: # a way to embed the main tests
13+
secrets:
14+
CODECOV_TOKEN:
15+
required: true
1316

1417
permissions:
1518
contents: read
@@ -112,6 +115,7 @@ jobs:
112115
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
113116
with:
114117
fetch-depth: 0
118+
persist-credentials: false
115119
- name: >-
116120
Calculate Python interpreter version hash value
117121
for use in the cache key
@@ -208,6 +212,8 @@ jobs:
208212
)
209213
- name: Set the target Git tag
210214
id: git-tag
215+
env:
216+
DIST_VERSION: ${{ steps.scm-version.outputs.dist-version }}
211217
run: |
212218
from os import environ
213219
from pathlib import Path
@@ -218,13 +224,13 @@ jobs:
218224
mode=FILE_APPEND_MODE,
219225
) as outputs_file:
220226
print(
221-
"tag=v${{
222-
steps.scm-version.outputs.dist-version
223-
}}",
227+
f"tag=v{environ['DIST_VERSION'].removeprefix('v')}",
224228
file=outputs_file,
225229
)
226230
- name: Set the expected dist artifact names
227231
id: artifact-name
232+
env:
233+
DIST_VERSION: ${{ steps.scm-version.outputs.dist-version }}
228234
run: |
229235
from os import environ
230236
from pathlib import Path
@@ -238,15 +244,11 @@ jobs:
238244
mode=FILE_APPEND_MODE,
239245
) as outputs_file:
240246
print(
241-
f"sdist={sdist_file_prj_base_name !s}-${{
242-
steps.scm-version.outputs.dist-version
243-
}}.tar.gz",
247+
f"sdist={sdist_file_prj_base_name !s}-{environ['DIST_VERSION']}.tar.gz",
244248
file=outputs_file,
245249
)
246250
print(
247-
f"wheel={whl_file_prj_base_name !s}-${{
248-
steps.scm-version.outputs.dist-version
249-
}}-py3-none-any.whl",
251+
f"wheel={whl_file_prj_base_name !s}-{environ['DIST_VERSION']}-py3-none-any.whl",
250252
file=outputs_file,
251253
)
252254
@@ -268,7 +270,8 @@ jobs:
268270

269271
env:
270272
TOXENV: cleanup-dists,build-dists
271-
273+
SDIST_ARTIFACT_NAME: ${{ needs.pre-setup.outputs.sdist-artifact-name }}
274+
WHEEL_ARTIFACT_NAME: ${{ needs.pre-setup.outputs.wheel-artifact-name }}
272275
outputs:
273276
dists-base64-hash: ${{ steps.dist-hashes.outputs.combined-hash }}
274277

@@ -282,6 +285,7 @@ jobs:
282285
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
283286
with:
284287
fetch-depth: 0
288+
persist-credentials: false
285289

286290
- name: >-
287291
Calculate Python interpreter version hash value
@@ -357,19 +361,13 @@ jobs:
357361
--quiet
358362
- name: Verify that the artifacts with expected names got created
359363
run: >-
360-
ls -1
361-
'dist/${{ needs.pre-setup.outputs.sdist-artifact-name }}'
362-
'dist/${{ needs.pre-setup.outputs.wheel-artifact-name }}'
364+
ls -1 "dist/${SDIST_ARTIFACT_NAME}" "dist/${WHEEL_ARTIFACT_NAME}"
363365
- name: Generate dist hashes to be used for provenance
364366
id: dist-hashes
365367
run: >-
366368
echo "combined-hash=$(
367-
sha256sum
368-
'${{ needs.pre-setup.outputs.sdist-artifact-name }}'
369-
'${{ needs.pre-setup.outputs.wheel-artifact-name }}'
370-
| base64 -w0
371-
)"
372-
>> "${GITHUB_OUTPUT}"
369+
sha256sum "$SDIST_ARTIFACT_NAME" "$WHEEL_ARTIFACT_NAME" | base64 -w0
370+
)" >> $GITHUB_OUTPUT
373371
working-directory: dist
374372
- name: Store the distribution packages
375373
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
@@ -386,7 +384,7 @@ jobs:
386384
retention-days: 30
387385

388386
lint:
389-
name: 🧹 Linters${{ '' }} # nest jobs under the same sidebar category
387+
name: 🧹 Linters${{ '' }} # Group jobs in sidebar # zizmor: ignore[obfuscation]
390388
needs:
391389
- build
392390
- pre-setup # transitive, for accessing settings
@@ -444,7 +442,7 @@ jobs:
444442
codecov-token: ${{ secrets.CODECOV_TOKEN }}
445443

446444
tests:
447-
name: 🧪 Tests${{ '' }} # nest jobs under the same sidebar category
445+
name: 🧪 Tests${{ '' }} # Group jobs in sidebar # zizmor: ignore[obfuscation]
448446
needs:
449447
- build
450448
- pre-setup # transitive, for accessing settings

.github/workflows/codeql.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ jobs:
4444
steps:
4545
- name: Checkout repository
4646
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
47+
with:
48+
persist-credentials: false
4749

4850
# Initializes the CodeQL tools for scanning.
4951
- name: Initialize CodeQL

.github/workflows/dependency-review.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,8 @@ jobs:
2222
steps:
2323
- name: Checkout Repository
2424
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
25+
with:
26+
persist-credentials: false
27+
2528
- name: Dependency Review
2629
uses: actions/dependency-review-action@da24556b548a50705dd671f47852072ea4c105d9 # v4.7.1

.github/workflows/pr-title.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Validate PR title
22

33
on:
4-
pull_request_target:
4+
pull_request:
55
types:
66
- opened
77
- edited

.github/workflows/pre-commit.yaml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,20 @@ jobs:
1414
runs-on: ubuntu-latest
1515
steps:
1616
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
17+
with:
18+
persist-credentials: false
1719
- run: >-
1820
git fetch --no-tags --prune --depth=1 origin
1921
+refs/heads/*:refs/remotes/origin/*
2022
2123
- name: Get changed files
2224
id: file_changes
25+
env:
26+
BASE_REF: ${{ github.base_ref }}
27+
SHA: ${{ github.sha }}
2328
run: |
24-
export DIFF=$(git diff --name-only origin/${{ github.base_ref }} ${{
25-
github.sha
26-
}})
27-
echo "Diff between ${{ github.base_ref }} and ${{ github.sha }}"
29+
export DIFF=$(git diff --name-only "origin/$BASE_REF" "$SHA")
30+
echo "Diff between $BASE_REF and $SHA"
2831
echo "files=$( echo "$DIFF" | xargs echo )" >> $GITHUB_OUTPUT
2932
3033
- name: Install shfmt
@@ -48,10 +51,11 @@ jobs:
4851
)"
4952
> hadolint
5053
&& chmod +x hadolint && sudo mv hadolint /usr/bin/
51-
# Needed for pre-commit fix push to succeed
54+
# Needed for pre-commit fix push to succeed
5255
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
5356
with:
5457
fetch-depth: 0
58+
persist-credentials: false
5559
ref: ${{ github.event.pull_request.head.sha }}
5660
# Needed to trigger pre-commit workflow on autofix commit. Guide:
5761
# https://web.archive.org/web/20210731173012/https://github.community/t/required-check-is-expected-after-automated-push/187545/

.github/workflows/reusable-tox.yml

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,10 @@ jobs:
150150
steps:
151151
- name: Export requested job-global environment variables
152152
if: inputs.environment-variables != ''
153+
env:
154+
INPUT_ENV_VARS: ${{ inputs.environment-variables }}
153155
run: >-
154-
echo '${{ inputs.environment-variables }}'
155-
>> "${GITHUB_ENV}"
156+
echo "$INPUT_ENV_VARS" >> $GITHUB_ENV
156157
157158
- name: >-
158159
Switch to using Python v${{ inputs.python-version }}
@@ -170,6 +171,7 @@ jobs:
170171
contains(fromJSON('["pre-commit", "spellcheck-docs"]'), inputs.toxenv)
171172
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
172173
with:
174+
persist-credentials: false
173175
ref: ${{ github.event.inputs.release-committish }}
174176
- name: Retrieve the project source from an sdist inside the GHA artifact
175177
if: >-
@@ -273,18 +275,24 @@ jobs:
273275

274276
- name: >-
275277
Pre-populate tox envs: `${{ env.TOXENV }}`
276-
run: >-
277-
python -Im
278-
tox
279-
--parallel auto
280-
--parallel-live
281-
--skip-missing-interpreters false
282-
${{
283-
inputs.built-wheel-names != ''
284-
&& format('--installpkg dist/{0}', inputs.built-wheel-names)
285-
|| ''
286-
}}
287-
--notest
278+
shell: bash
279+
env:
280+
INPUT_BUILT_WHEEL_NAMES: ${{ inputs.built-wheel-names }}
281+
run: |-
282+
tox_common_args=(
283+
--parallel auto
284+
--parallel-live
285+
--skip-missing-interpreters false
286+
)
287+
if [[ $INPUT_BUILT_WHEEL_NAMES ]]; then
288+
python -Im tox "${tox_common_args[@]}" \
289+
--installpkg "dist/$INPUT_BUILT_WHEEL_NAMES" \
290+
--notest
291+
else
292+
python -Im tox "${tox_common_args[@]}" \
293+
--notest
294+
fi
295+
288296
- name: Initialize pre-commit envs if needed
289297
if: inputs.toxenv == 'pre-commit'
290298
run: >-
@@ -301,19 +309,24 @@ jobs:
301309
- name: >-
302310
Run tox envs: `${{ env.TOXENV }}`
303311
id: tox-run
304-
run: >-
305-
python -Im
306-
tox
307-
--parallel auto
308-
--parallel-live
309-
--skip-missing-interpreters false
310-
--skip-pkg-install
311-
--quiet
312-
${{
313-
inputs.tox-run-posargs != ''
314-
&& format('-- {0}', inputs.tox-run-posargs)
315-
|| ''
316-
}}
312+
shell: bash
313+
env:
314+
INPUT_TOX_RUN_POSARGS: ${{ inputs.tox-run-posargs }}
315+
run: |-
316+
tox_common_args=(
317+
--parallel auto
318+
--parallel-live
319+
--skip-missing-interpreters false
320+
--skip-pkg-install
321+
--quiet
322+
)
323+
if [ -n "$INPUT_TOX_RUN_POSARGS" ]; then
324+
python -Im tox "${tox_common_args[@]}" \
325+
-- "$INPUT_TOX_RUN_POSARGS"
326+
else
327+
python -Im tox "${tox_common_args[@]}"
328+
fi
329+
317330
# Generate nice SVG image of passed/failed tests in GHA Job Summary
318331
- name: Produce markdown test summary from JUnit
319332
if: >-
@@ -352,13 +365,15 @@ jobs:
352365
&& steps.tox-run.outputs.test-result-files == ''
353366
&& steps.tox-run.outputs.codecov-flags != 'MyPy'
354367
run: >-
355-
cat code-coverage-results.md >> "${GITHUB_STEP_SUMMARY}"
368+
cat code-coverage-results.md >> "$GITHUB_STEP_SUMMARY"
356369
- name: Re-run the failing tests with maximum verbosity
357370
if: >-
358371
!cancelled()
359372
&& failure()
360373
&& inputs.tox-rerun-posargs != ''
361374
# `exit 1` makes sure that the job remains red with flaky runs
375+
env:
376+
INPUT_TOX_RERUN_POSARGS: ${{ inputs.tox-rerun-posargs }}
362377
run: >-
363378
python -Im
364379
tox
@@ -368,7 +383,7 @@ jobs:
368383
-vvvvv
369384
--skip-pkg-install
370385
--
371-
${{ inputs.tox-rerun-posargs }}
386+
$INPUT_TOX_RERUN_POSARGS
372387
&& exit 1
373388
shell: bash
374389
- name: Send coverage data to Codecov

.github/workflows/scheduled-runs.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@ jobs:
3737
main-ci-cd-pipeline:
3838
name: ∞ Main CI/CD pipeline
3939
uses: ./.github/workflows/ci-cd.yml
40-
secrets: inherit
40+
secrets:
41+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ repos:
4747
hooks:
4848
- id: gitleaks
4949

50+
# Github Action static analysis tool
51+
- repo: https://github.com/woodruffw/zizmor-pre-commit
52+
rev: v1.9.0
53+
hooks:
54+
- id: zizmor
55+
5056
# Dockerfile
5157
- repo: https://github.com/hadolint/hadolint
5258
rev: v2.13.1-beta

0 commit comments

Comments
 (0)