diff --git a/setup/README.md b/setup/README.md index a18e3d30..bfe192cc 100644 --- a/setup/README.md +++ b/setup/README.md @@ -31,15 +31,22 @@ The Setup Action requires `bash` and `curl` to be available and requires privile The Snyk Setup Action has properties which are passed to the underlying image. These are passed to the action using `with`. -| Property | Default | Description | -| --- | --- | --- | -| snyk-version | latest | Install a specific version of Snyk | +| Property | Default | Description | +|--------------|---------|------------------------------------| +| snyk-version | latest | Install a specific version of Snyk | The Action also has outputs: -| Property | Default | Description | -| --- | --- | --- | -| version | | The full version of the Snyk CLI installed | +| Property | Default | Description | +|----------|---------|--------------------------------------------| +| version | | The full version of the Snyk CLI installed | + +## Caching + +The Setup Action automatically caches the Snyk CLI binary to speed up subsequent workflow runs. The cache key is based on the operating system and Snyk version (`snyk-{os}-{version}`). + +> [!IMPORTANT] +> The Snyk CLI is only cached when using a specific version of Snyk (e.g., `v1.391.0`). When using `snyk-version: latest`, the CLI will always be re-downloaded to ensure you have the most recent version. For example, you can choose to install a specific version of Snyk. The installed version can be grabbed from the output: diff --git a/setup/action.yml b/setup/action.yml index acbd17b5..3cea7464 100644 --- a/setup/action.yml +++ b/setup/action.yml @@ -18,15 +18,25 @@ outputs: runs: using: "composite" steps: - - env: + - name: Cache Snyk CLI + id: cache-snyk + uses: actions/cache@v4 + with: + path: | + /usr/local/bin/snyk + /usr/local/bin/snyk-* + key: snyk-${{ inputs.os }}-${{ inputs.snyk-version }} + + - name: Install Snyk CLI + if: inputs.snyk-version == 'latest' || steps.cache-snyk.outputs.cache-hit != 'true' + shell: bash + env: INPUT_SNYK_VERSION: ${{ inputs.snyk-version }} INPUT_OS: ${{ inputs.os }} run: | - echo $GITHUB_ACTION_PATH - echo ${{ github.action_path }} - ${{ github.action_path }}/setup_snyk.sh "${INPUT_SNYK_VERSION}" "${INPUT_OS}" || $GITHUB_ACTION_PATH/setup_snyk.sh "${INPUT_SNYK_VERSION}" "${INPUT_OS}" + + - name: Get Snyk version + id: version shell: bash - - id: version - shell: bash - run: echo "version=$(snyk version)" >> $GITHUB_OUTPUT + run: echo "version=$(snyk version)" >> "${GITHUB_OUTPUT}"