From e138d62515393e5b6ac3fe2c3bd8e4162dc2b459 Mon Sep 17 00:00:00 2001 From: Victor Date: Tue, 26 Nov 2024 16:22:51 +0000 Subject: [PATCH] fix: use terraform.tf files as fallback cache when repos don't have tf lockfiles --- lint/action.yaml | 8 +++++++- test/action.yaml | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lint/action.yaml b/lint/action.yaml index fde8e2a..864cbab 100644 --- a/lint/action.yaml +++ b/lint/action.yaml @@ -43,11 +43,17 @@ runs: run: | echo "TF_PLUGIN_CACHE_DIR=${{ runner.temp }}/.terraform.d/plugin-cache" >>"$GITHUB_ENV" mkdir --parents "${{ runner.temp }}/.terraform.d/plugin-cache" + - name: Check for terraform lockfiles + id: check_terraform_lockfiles + if: inputs.s3-bucket-name != '' + uses: andstor/file-existence-action@v3 + with: + files: "**/.terraform.lock.hcl" - name: Compute terraform plugin cache key if: inputs.s3-bucket-name != '' id: tf_plugin_cache_key run: | - echo "key=terraform-${{ runner.os }}-${{ hashFiles('**/.terraform.lock.hcl') }}" >> $GITHUB_OUTPUT + echo "key=terraform-${{ runner.os }}-${{ steps.check_terraform_lockfiles.outputs.files_exists == 'true' && hashFiles('**/.terraform.lock.hcl') || hashFiles('**/terraform.tf') }}" >> $GITHUB_OUTPUT shell: bash - name: Load cached terraform plugins if available if: inputs.s3-bucket-name != '' diff --git a/test/action.yaml b/test/action.yaml index 12768da..f4a1f00 100644 --- a/test/action.yaml +++ b/test/action.yaml @@ -50,11 +50,17 @@ runs: run: | echo "TF_PLUGIN_CACHE_DIR=${{ runner.temp }}/.terraform.d/plugin-cache" >>"$GITHUB_ENV" mkdir --parents "${{ runner.temp }}.terraform.d/plugin-cache" + - name: Check for terraform lockfiles + id: check_terraform_lockfiles + if: inputs.s3-bucket-name != '' + uses: andstor/file-existence-action@v3 + with: + files: "**/.terraform.lock.hcl" - name: Compute terraform plugin cache key if: inputs.s3-bucket-name != '' id: tf_plugin_cache_key run: | - echo "key=terraform-${{ runner.os }}-${{ hashFiles('**/.terraform.lock.hcl') }}" >> $GITHUB_OUTPUT + echo "key=terraform-${{ runner.os }}-${{ steps.check_terraform_lockfiles.outputs.files_exists == 'true' && hashFiles('**/.terraform.lock.hcl') || hashFiles('**/terraform.tf', '**/versions.tf') }}" >> $GITHUB_OUTPUT shell: bash - name: Load cached terraform plugins if available if: inputs.s3-bucket-name != ''