From 0afaf5b0387009b7afa70f02b83ec45c7de1a460 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 | 7 ++++++- test/action.yaml | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lint/action.yaml b/lint/action.yaml index fde8e2a..6035c8a 100644 --- a/lint/action.yaml +++ b/lint/action.yaml @@ -43,11 +43,16 @@ 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 + 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..0d74747 100644 --- a/test/action.yaml +++ b/test/action.yaml @@ -50,11 +50,16 @@ 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 + 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 != ''