Repository navigation
Test dependencies with Snyk and show its badge #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| name: Snyk | ||
|
|
||
| # Snyk cannot read Cargo.lock directly. Each Cargo set is described as | ||
| # CycloneDX SBOMs, one per workspace member, and tested with `snyk sbom test`; | ||
| # an npm set is tested from its package-lock.json. It runs weekly and when a | ||
| # manifest or lockfile changes. | ||
| on: | ||
| schedule: | ||
| - cron: "33 5 * * 2" | ||
| workflow_dispatch: | ||
| push: | ||
| branches: [main] | ||
| paths: | ||
| - "**/Cargo.toml" | ||
| - "**/Cargo.lock" | ||
| - "**/package.json" | ||
| - "**/package-lock.json" | ||
| - ".github/workflows/snyk.yml" | ||
| pull_request: | ||
| paths: | ||
| - "**/Cargo.toml" | ||
| - "**/Cargo.lock" | ||
| - "**/package.json" | ||
| - "**/package-lock.json" | ||
| - ".github/workflows/snyk.yml" | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| test: | ||
| name: Snyk open source test | ||
| # Pull requests from forks, and Dependabot's (which get Dependabot secrets | ||
| # only), receive no SNYK_TOKEN; the weekly run scans their changes. | ||
| if: github.event_name != 'pull_request' || (github.event.pull_request.head.repo.full_name == github.repository && github.event.pull_request.user.login != 'dependabot[bot]') | ||
| runs-on: ubuntu-24.04 | ||
| timeout-minutes: 30 | ||
| env: | ||
| # One dependency set per line: cargo:<workspace directory> or | ||
| # npm:<package-lock.json>. | ||
| SNYK_TARGETS: | | ||
| cargo:. | ||
| steps: | ||
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| with: | ||
| persist-credentials: false | ||
| - uses: snyk/actions/setup@9adf32b1121593767fc3c057af55b55db032dc04 # v1.0.0 | ||
| # A prebuilt release whose checksum the action's manifest pins, instead of | ||
| # compiling the generator on every run. | ||
| - uses: taiki-e/install-action@1e29709c0ec63babbe8f266397a465f29a825f91 # v2.87.31 | ||
| with: | ||
| tool: cargo-cyclonedx@0.5.9 | ||
| - name: Test each dependency set | ||
| env: | ||
| SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} | ||
| run: | | ||
| set -uo pipefail | ||
| # Without the token every SBOM is still generated, so a broken lock | ||
| # shows up, but the job fails because nothing was scanned. | ||
| if [ -z "$SNYK_TOKEN" ]; then | ||
| echo "::error::The SNYK_TOKEN repository secret is not set, so nothing was scanned." | ||
| fi | ||
| status=0 | ||
| while IFS=: read -r kind target; do | ||
| [ -n "$kind" ] || continue | ||
| case "$kind" in | ||
| npm) [ -z "$SNYK_TOKEN" ] || snyk test --file="$target" --project-name="$target" || status=1 ;; | ||
| cargo) | ||
| # rustup reads a pinned version from the toolchain file. | ||
| if [ -f "$target/rust-toolchain.toml" ] || [ -f "$target/rust-toolchain" ]; then | ||
| (cd "$target" && rustup toolchain install) \ | ||
| || { echo "::error::rustup could not install the toolchain for $target"; status=1; continue; } | ||
| fi | ||
| (cd "$target" && cargo cyclonedx --format json --spec-version 1.5 --override-filename snyk-sbom) \ | ||
| || { echo "::error::cargo cyclonedx failed for $target"; status=1; continue; } | ||
| list=$(mktemp) | ||
| find "$target" -name snyk-sbom.json -not -path '*/target/*' -print0 > "$list" \ | ||
| || { echo "::error::Cannot list the SBOMs for $target"; status=1; continue; } | ||
| [ -s "$list" ] || { echo "::error::cargo cyclonedx wrote no SBOM for $target"; status=1; continue; } | ||
| while IFS= read -r -d '' sbom; do | ||
| [ -z "$SNYK_TOKEN" ] || snyk sbom test --experimental --file="$sbom" || status=1 | ||
| done < "$list" ;; | ||
| *) echo "::error::Unknown dependency set $kind:$target"; status=1 ;; | ||
| esac | ||
| done <<< "$SNYK_TARGETS" | ||
| [ -n "$SNYK_TOKEN" ] || exit 1 | ||
| exit "$status" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 MEDIUM RISK
Point both Snyk badge URLs at this repository's
.github/workflows/snyk.ymlso the badge reports this project's workflow status.TIPReact 👍 if this review is right, or reply with what's wrong and how it could be better to help improve the reviewer.