Skip to content

Feat: Add caching support for dependencies #1292

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
merged 9 commits into from
Apr 26, 2024
Merged
27 changes: 27 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ inputs:
description: 'drift-detection slack drift url'
required: false
default: ''
cache-dependencies:
description: "Leverage actions/cache to cache dependencies to speed up execution"
required: false
default: 'false'
outputs:
output:
value: ${{ steps.digger.outputs.output }}
Expand Down Expand Up @@ -212,6 +216,16 @@ runs:
subscription-id: ${{ inputs.azure-subscription-id }}
if: ${{ inputs.setup-azure == 'true' && inputs.azure-client-id != '' }}

- uses: actions/cache/restore@v4
id: restore_cache
name: restore_cache
with:
path: ${{ github.workspace }}/cache
key: digger-cache
restore-keys: |
digger-cache
if: ${{ inputs.cache-dependencies == 'true' }}

- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
Expand Down Expand Up @@ -262,6 +276,10 @@ runs:
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env['ACTIONS_RUNTIME_TOKEN'])
core.exportVariable('ACTIONS_RUNTIME_URL', process.env['ACTIONS_RUNTIME_URL'])

- name: create cache dir
run: |
mkdir -p $GITHUB_WORKSPACE/cache
shell: bash

- name: build and run digger
if: ${{ !startsWith(github.action_ref, 'v') }}
Expand All @@ -282,6 +300,7 @@ runs:
INPUT_DRIFT_DETECTION_SLACK_NOTIFICATION_URL: ${{ inputs.drift-detection-slack-notification-url }}
NO_BACKEND: ${{ inputs.no-backend }}
DEBUG: 'true'
TF_PLUGIN_CACHE_DIR: ${{ github.workspace }}/cache
run: |
cd $GITHUB_ACTION_PATH/cli
go build -o digger ./cmd/digger
Expand Down Expand Up @@ -315,6 +334,14 @@ runs:
PATH=$PATH:$(pwd)
cd $GITHUB_WORKSPACE
digger

- uses: actions/cache/save@v4
name: cache-save
with:
path: ${{ github.workspace }}/cache
key: digger-cache-${{ hashFiles('**/cache') }}
if: ${{ inputs.cache-dependencies == 'true' }}

branding:
icon: globe
color: purple
Loading