From 4af12377223c1de82be101130a973140a2196a60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Wei=C3=9Fe?= Date: Tue, 30 Apr 2024 15:24:10 +0200 Subject: [PATCH] Only try to upload updated tf state if it exists MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Daniel Weiße --- .github/actions/update_tfstate/action.yml | 30 +++++++++++------------ 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/actions/update_tfstate/action.yml b/.github/actions/update_tfstate/action.yml index 58d9ef11e..4bbdf8ec3 100644 --- a/.github/actions/update_tfstate/action.yml +++ b/.github/actions/update_tfstate/action.yml @@ -2,7 +2,7 @@ name: Update TFState description: "Update the terraform state artifact." inputs: - name: + name: description: "The name of the artifact that contains the tfstate." required: true runID: @@ -20,17 +20,17 @@ runs: using: "composite" steps: - name: Check if tfstate should be deleted - if: always() && ${{ inputs.skipDeletion }} == "false" + if: always() && inputs.skipDeletion == 'false' shell: bash run: | if [ ! -d constellation-terraform ] && [ ! -d constellation-iam-terraform ]; then - echo "DELETE_TF_STATE=true" >> "$GITHUB_ENV" + echo "DELETE_TF_STATE=true" >> "$GITHUB_ENV" else - echo "DELETE_TF_STATE=false" >> "$GITHUB_ENV" + echo "DELETE_TF_STATE=false" >> "$GITHUB_ENV" fi - name: Delete tfstate artifact if necessary - if: always() && env.DELETE_TF_STATE == 'true' && ${{ inputs.skipDeletion }} == "false" + if: always() && env.DELETE_TF_STATE == 'true' && inputs.skipDeletion == 'false' uses: ./.github/actions/artifact_delete with: name: ${{ inputs.name }} @@ -41,22 +41,24 @@ runs: shell: bash run: | rm -rf to-zip/* + mkdir -p to-zip + to_upload="" if [ -d constellation-terraform ]; then - cp -r constellation-terraform to-zip - rm to-zip/constellation-terraform/plan.zip - rm -rf to-zip/constellation-terraform/.terraform - to_upload+="to-zip/constellation-terraform" + cp -r constellation-terraform to-zip + rm -f to-zip/constellation-terraform/plan.zip + rm -rf to-zip/constellation-terraform/.terraform + to_upload+="to-zip/constellation-terraform" fi if [ -d constellation-iam-terraform ]; then - cp -r constellation-iam-terraform to-zip - rm -rf to-zip/constellation-iam-terraform/.terraform - to_upload+=" to-zip/constellation-iam-terraform" + cp -r constellation-iam-terraform to-zip + rm -rf to-zip/constellation-iam-terraform/.terraform + to_upload+=" to-zip/constellation-iam-terraform" fi echo "TO_UPLOAD=$to_upload" >> "$GITHUB_ENV" - name: Update tfstate - if: always() + if: always() && env.TO_UPLOAD != '' uses: ./.github/actions/artifact_upload with: name: ${{ inputs.name }} @@ -64,5 +66,3 @@ runs: ${{ env.TO_UPLOAD }} encryptionSecret: ${{ inputs.encryptionSecret }} overwrite: true - -