Skip to content

Commit 869b24d

Browse files
authored
feat(run-digger-action): add digger-version input (#2283)
* feat(run-digger-action): allow specifying digger version explicitly
1 parent b8a7dec commit 869b24d

File tree

2 files changed

+81
-39
lines changed

2 files changed

+81
-39
lines changed

action.yml

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ inputs:
232232
description: "(orchestrator only) the spec to pass onto digger cli"
233233
required: false
234234
default: ""
235+
digger-version:
236+
description: "Pre-compiled version of digger CLI to install. Must correspond to a valid release tag (vX.Y.Z). This value overrides the version derived from the github.action_ref."
237+
required: false
238+
default: ""
235239

236240
outputs:
237241
output:
@@ -245,6 +249,30 @@ runs:
245249
run: echo digger run ${{ inputs.id }}
246250
shell: bash
247251

252+
- name: Determine binary mode (local, build, or pre-built)
253+
id: determine-binary-mode
254+
env:
255+
LOCAL_DEV_MODE: ${{ inputs.local-dev-mode }}
256+
INPUT_DIGGER_VERSION: ${{ inputs.digger-version }}
257+
ACTION_REF: ${{ github.action_ref }}
258+
run: |
259+
set -euo pipefail
260+
261+
if [[ ! ( -z "$INPUT_DIGGER_VERSION" || "$INPUT_DIGGER_VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ) ]]; then
262+
echo "::error::Invalid digger-version input $INPUT_DIGGER_VERSION. Must be empty string or match vX.Y.Z"
263+
exit 1
264+
fi
265+
266+
if [[ "$LOCAL_DEV_MODE" == "true" ]]; then
267+
BINARY_MODE="local" # Use locally compiled binary (for development)
268+
elif [[ -n "$INPUT_DIGGER_VERSION" || "$ACTION_REF" == v* ]]; then
269+
BINARY_MODE="prebuilt" # Install prebuilt binary from release
270+
else
271+
BINARY_MODE="build" # Build from source at runtime
272+
fi
273+
echo "binary-mode=${BINARY_MODE}" >> ${GITHUB_OUTPUT}
274+
shell: bash
275+
248276
- name: Validate Input Configuration for Google
249277
run: |
250278
if [[ -z ${{ toJSON(inputs.google-auth-credentials) }} && -z "${{ inputs.google-workload-identity-provider }}" ]]; then
@@ -257,7 +285,7 @@ runs:
257285
exit 1
258286
shell: bash
259287
if: inputs.setup-google-cloud == 'true'
260-
- uses: actions/checkout@v4
288+
- uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0
261289
with:
262290
clean: false
263291
ref: refs/pull/${{ github.event.issue.number }}/merge
@@ -396,15 +424,15 @@ runs:
396424
with:
397425
go-version-file: "${{ github.action_path }}/cli/go.mod"
398426
cache: false
399-
if: ${{ !startsWith(github.action_ref, 'v') }}
427+
if: ${{ steps.determine-binary-mode.outputs.binary-mode != 'prebuilt' }}
400428

401429
- name: Determine Golang cache paths
402430
id: golang-env
403431
run: |
404432
echo "build-cache-path=$(go env GOCACHE)" >>"$GITHUB_OUTPUT"
405433
echo "module-cache-path=$(go env GOMODCACHE)" >>"$GITHUB_OUTPUT"
406434
shell: bash
407-
if: ${{ !startsWith(github.action_ref, 'v') }}
435+
if: ${{ steps.determine-binary-mode.outputs.binary-mode != 'prebuilt' }}
408436

409437
- name: Copy Digger CLI go.sum for cache key
410438
run: |
@@ -416,7 +444,7 @@ runs:
416444
cp "$GITHUB_ACTION_PATH/cli/go.sum" "$GITHUB_WORKSPACE/.digger.go.sum"
417445
fi
418446
shell: bash
419-
if: ${{ !startsWith(github.action_ref, 'v') }}
447+
if: ${{ steps.determine-binary-mode.outputs.binary-mode != 'prebuilt' }}
420448

421449
- name: Adding required env vars for next step
422450
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0
@@ -434,7 +462,7 @@ runs:
434462
shell: bash
435463

436464
- name: build and run digger
437-
if: ${{ !startsWith(github.action_ref, 'v') && inputs.local-dev-mode == 'false' }}
465+
if: ${{ steps.determine-binary-mode.outputs.binary-mode == 'build' }}
438466
shell: bash
439467
env:
440468
PLAN_UPLOAD_DESTINATION: ${{ inputs.upload-plan-destination }}
@@ -485,10 +513,10 @@ runs:
485513
cd $GITHUB_WORKSPACE
486514
digger
487515
488-
- name: run digger
489-
if: ${{ startsWith(github.action_ref, 'v') && inputs.local-dev-mode == 'false' }}
516+
- name: download, install, and run digger
517+
if: ${{ steps.determine-binary-mode.outputs.binary-mode == 'prebuilt' }}
490518
env:
491-
actionref: ${{ github.action_ref }}
519+
DIGGER_VERSION: ${{ inputs.digger-version || github.action_ref }}
492520
PLAN_UPLOAD_DESTINATION: ${{ inputs.upload-plan-destination }}
493521
PLAN_UPLOAD_S3_ENCRYPTION_ENABLED: ${{ inputs.upload-plan-destination-s3-encryption-enabled }}
494522
PLAN_UPLOAD_S3_ENCRYPTION_TYPE: ${{ inputs.upload-plan-destination-s3-encryption-type }}
@@ -525,16 +553,16 @@ runs:
525553
set -euo pipefail
526554
527555
echo "🔧 Downloading Digger CLI..."
528-
echo "Runner OS: ${{ runner.os }}, Arch: ${{ runner.arch }}, Action Ref: ${actionref}"
556+
echo "Runner OS: ${{ runner.os }}, Arch: ${{ runner.arch }}, Digger Version: ${DIGGER_VERSION}"
529557
530558
if [[ ${{ inputs.ee }} == "true" ]]; then
531559
if [[ ${{ inputs.fips }} == "true" ]]; then
532-
DOWNLOAD_URL="https://github.com/diggerhq/digger/releases/download/${actionref}/digger-ee-cli-${{ runner.os }}-${{ runner.arch }}-fips"
560+
DOWNLOAD_URL="https://github.com/diggerhq/digger/releases/download/${DIGGER_VERSION}/digger-ee-cli-${{ runner.os }}-${{ runner.arch }}-fips"
533561
else
534-
DOWNLOAD_URL="https://github.com/diggerhq/digger/releases/download/${actionref}/digger-ee-cli-${{ runner.os }}-${{ runner.arch }}"
562+
DOWNLOAD_URL="https://github.com/diggerhq/digger/releases/download/${DIGGER_VERSION}/digger-ee-cli-${{ runner.os }}-${{ runner.arch }}"
535563
fi
536564
else
537-
DOWNLOAD_URL="https://github.com/diggerhq/digger/releases/download/${actionref}/digger-cli-${{ runner.os }}-${{ runner.arch }}"
565+
DOWNLOAD_URL="https://github.com/diggerhq/digger/releases/download/${DIGGER_VERSION}/digger-cli-${{ runner.os }}-${{ runner.arch }}"
538566
fi
539567
540568
echo "Downloading from: $DOWNLOAD_URL"
@@ -543,12 +571,12 @@ runs:
543571
echo "Failed to download Digger CLI from $DOWNLOAD_URL"
544572
echo ""
545573
echo "Possible reasons:"
546-
echo "1. The release ${actionref} might not exist"
574+
echo "1. The release ${DIGGER_VERSION} might not exist"
547575
echo "2. Binary for ${{ runner.os }}-${{ runner.arch }} might not be available"
548576
echo "3. Network connectivity issues"
549577
echo ""
550578
echo "Suggestions:"
551-
echo "- Check if release ${actionref} exists at: https://github.com/diggerhq/digger/releases"
579+
echo "- Check if release ${DIGGER_VERSION} exists at: https://github.com/diggerhq/digger/releases"
552580
echo "- Verify the architecture combination is supported"
553581
echo "- Try using a different release version"
554582
exit 1
@@ -572,9 +600,9 @@ runs:
572600
digger
573601
574602
- name: run digger in local dev mode
575-
if: ${{ inputs.local-dev-mode == 'true' }}
603+
if: ${{ steps.determine-binary-mode.outputs.binary-mode == 'local' }}
576604
env:
577-
actionref: ${{ github.action_ref }}
605+
DIGGER_VERSION: ${{ github.action_ref }}
578606
PLAN_UPLOAD_DESTINATION: ${{ inputs.upload-plan-destination }}
579607
PLAN_UPLOAD_S3_ENCRYPTION_ENABLED: ${{ inputs.upload-plan-destination-s3-encryption-enabled }}
580608
PLAN_UPLOAD_S3_ENCRYPTION_TYPE: ${{ inputs.upload-plan-destination-s3-encryption-type }}

docs/ce/howto/versioning.mdx

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,64 @@
11
---
2-
title: "Specifying version"
3-
description: "For serious usecases always use a pinned version which is of the form @vX.Y.Z since this will download a compiled binary. In addition to being faster to run, it is also more secure than using a commit from a branch"
2+
title: "Specifying Version"
43
---
54

65
<Warning>
7-
For serious usecases always use a pinned version which is of the form @vX.Y.Z
8-
since this will download a compiled binary. In addition to being faster to run, it
9-
is also more secure than using a commit from a branch
6+
For production use cases it is best to pin the version of the action with the commit hash (e.g. `-uses: diggerhq/digger@<COMMIT_HASH>`) of the desired release
7+
AND specify the `digger-version` input to be a tagged release (`vX.Y.Z`).
8+
9+
This provides the security of ensuring the same action code is executed each time with the performance of using a pre-compiled Digger binary.
1010
</Warning>
1111

12-
## Use vLatest tag
12+
## Commit Hash + digger-version input (Production recommendation)
13+
14+
For production usage, we recommend pinning the action to the commit hash of a released version AND specifying a Digger CLI version via the `digger-version` input.
1315

14-
The default and recommended way of versioning Digger is to use the vLatest tag, which always points to the latest release. The difference compared to just specifying "latest" is that it is a release with pre-built binaries, so it is faster than building from a branch, which using "latest" effectively does.
16+
Specifying the action commit hash is the only way to ensure the same version of a GitHub Action is executed each time and helps protect against supply chain attacks such as [CVE-2025-30066](https://www.wiz.io/blog/github-action-tj-actions-changed-files-supply-chain-attack-cve-2025-30066).
17+
18+
The `digger-version` input enables pinning to the hash while ALSO using a pre-built Digger cli binary.
1519

1620
```
1721
- name: digger
18-
uses: diggerhq/[email protected]
19-
env:
20-
...
22+
uses: diggerhq/digger@<COMMIT_HASH_OF_TAGGED_RELEASE> # vX.Y.Z
23+
with:
24+
digger-version: vX.Y.Z
2125
```
2226

23-
## Use a pinned version
27+
## vLatest (Convenient auto-upgrades)
2428

25-
To pin a specific release of Digger, you can use `@vX.Y.Z` tag in your workflow file:
29+
For non-production use cases, you can specify the `vLatest` tag to use the latest tagged release for the digger action and the Digger CLI.
30+
31+
The difference compared to just specifying "latest" is that it is a release with pre-built binaries, so it is faster than building from a branch, which using "latest" effectively does.
2632

2733
```
2834
- name: digger
29-
uses: diggerhq/[email protected]
30-
env:
31-
...
35+
uses: diggerhq/digger@vLatest
3236
```
3337

34-
## Use latest commit from a branch
38+
## vX.Y.Z (Simple and stable)
39+
40+
If you aren't worried about supply chain attacks but want stability of using a specific release, you can pin the action to a specific release of Digger.
41+
42+
This will infer the Digger cli version to use based on the version of the action using `github.action_ref` and install the corresponding pre-built binary.
43+
44+
```
45+
- name: digger
46+
uses: diggerhq/[email protected]
47+
```
3548

36-
You can also run latest commit from a specific branch
49+
## Commit Hash Only (Build a specific CLI version from source at runtime)
3750

38-
Only use this at your own risk in non-production scenarios. This can break things!
51+
If you want to use an unreleased version of the Digger CLI (e.g. test something on a feature branch or a yet to be released commit from `develop`),
52+
you can specify the action with that commit hash AND omit the `digger-version` input.
3953

4054
<Warning>
41-
Only use this at your own risk in non-production scenarios. This can break
42-
things!
55+
Only use this at your own risk in non-production scenarios. This can break things!
4356
</Warning>
4457

4558
```
4659
- name: digger
47-
uses: diggerhq/digger@yolo-lets-do-it
48-
env:
49-
...
60+
uses: diggerhq/digger@<YOLO_COMMIT_HASH>
61+
with:
62+
# OMIT THE digger-version INPUT
63+
# digger-input: ""
5064
```

0 commit comments

Comments
 (0)