Skip to content

Commit

Permalink
Cache Go dependencies when building CLI (#1573)
Browse files Browse the repository at this point in the history
* [actions] enable caching of golang builds
  • Loading branch information
sikha-root committed Jun 11, 2024
1 parent d7b2229 commit 4f0ae71
Showing 1 changed file with 42 additions and 14 deletions.
56 changes: 42 additions & 14 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
name: run-digger
description: Manage terraform collaboration
author: Digger
Expand Down Expand Up @@ -29,14 +30,14 @@ inputs:
required: false
default: 'false'
google-auth-credentials:
description: Service account key used got Google auth (mutually exclusive with 'google-workload-identity-provider' input)
required: false
description: Service account key used got Google auth (mutually exclusive with 'google-workload-identity-provider' input)
required: false
google-workload-identity-provider:
description: Workload identity provider to be used for Google OIDC auth (mutually exclusive with 'google-auth-credentials' input)
required: false
description: Workload identity provider to be used for Google OIDC auth (mutually exclusive with 'google-auth-credentials' input)
required: false
google-workload-identity-provider-audience:
description: "'audience' parameter configured in Google's Workload Identity Provider (if specified). To be used when the 'google-workload-identity-provider' input is specified"
required: false
description: "'audience' parameter configured in Google's Workload Identity Provider (if specified). To be used when the 'google-workload-identity-provider' input is specified"
required: false
google-service-account:
description: Service account to be used when the 'google-workload-identity-provider' input is specified)
required: false
Expand Down Expand Up @@ -224,9 +225,9 @@ runs:
- name: Configure OIDC Azure credentials
uses: azure/[email protected]
with:
client-id: ${{ inputs.azure-client-id }}
tenant-id: ${{ inputs.azure-tenant-id }}
subscription-id: ${{ inputs.azure-subscription-id }}
client-id: ${{ inputs.azure-client-id }}
tenant-id: ${{ inputs.azure-tenant-id }}
subscription-id: ${{ inputs.azure-subscription-id }}
if: ${{ inputs.setup-azure == 'true' && inputs.azure-client-id != '' }}

- uses: actions/cache/restore@v4
Expand Down Expand Up @@ -263,7 +264,6 @@ runs:
tofu_wrapper: false
if: inputs.setup-opentofu == 'true'


- name: Setup Checkov
run: |
python3 -m venv .venv
Expand All @@ -277,9 +277,37 @@ runs:
- name: setup go
uses: actions/setup-go@v5
with:
go-version: '^1.21.1'
go-version-file: '${{ github.action_path }}/cli/go.mod'
cache: false
if: ${{ !startsWith(github.action_ref, 'v') }}

- name: Determine Golang cache paths
id: golang-env
run: |
echo "build-cache-path=$(go env GOCACHE)" >>"$GITHUB_OUTPUT"
echo "module-cache-path=$(go env GOMODCACHE)" >>"$GITHUB_OUTPUT"
shell: bash
if: ${{ !startsWith(github.action_ref, 'v') }}

- name: Copy Digger CLI go.sum for cache key
run: |
if [[ ${{ inputs.ee }} == "true" ]]; then
cp "$GITHUB_ACTION_PATH/ee/cli/go.sum" "$GITHUB_WORKSPACE/.digger.go.sum"
else
cp "$GITHUB_ACTION_PATH/cli/go.sum" "$GITHUB_WORKSPACE/.digger.go.sum"
fi
shell: bash
if: ${{ !startsWith(github.action_ref, 'v') }}

- uses: actions/cache@v4
with:
path: |
${{ steps.golang-env.outputs.build-cache-path }}
${{ steps.golang-env.outputs.module-cache-path }}
key: digger-cli-cache-${{ hashFiles('.digger.go.sum') }}
restore-keys: digger-cli-cache-
if: ${{ !startsWith(github.action_ref, 'v') && inputs.cache-dependencies == 'true' }}

- name: Adding required env vars for next step
uses: actions/github-script@v7
env:
Expand Down Expand Up @@ -326,12 +354,12 @@ runs:
else
cd $GITHUB_ACTION_PATH/cli
fi
go build -o digger ./cmd/digger
chmod +x digger
PATH=$PATH:$(pwd)
cd $GITHUB_WORKSPACE
digger
- name: run digger
if: ${{ startsWith(github.action_ref, 'v') }}
env:
Expand Down Expand Up @@ -360,9 +388,9 @@ runs:
shell: bash
run: |
if [[ ${{ inputs.ee }} == "true" ]]; then
curl -sL https://github.com/diggerhq/digger/releases/download/${actionref}/digger-ee-cli-${{ runner.os }}-${{ runner.arch }} -o digger
curl -sL https://github.com/diggerhq/digger/releases/download/${actionref}/digger-ee-cli-${{ runner.os }}-${{ runner.arch }} -o digger
else
curl -sL https://github.com/diggerhq/digger/releases/download/${actionref}/digger-cli-${{ runner.os }}-${{ runner.arch }} -o digger
curl -sL https://github.com/diggerhq/digger/releases/download/${actionref}/digger-cli-${{ runner.os }}-${{ runner.arch }} -o digger
fi
chmod +x digger
PATH=$PATH:$(pwd)
Expand Down

0 comments on commit 4f0ae71

Please sign in to comment.