From 067bed6c7dd0f56f0f510b0b225c293139c94325 Mon Sep 17 00:00:00 2001 From: Shunsuke Suzuki Date: Mon, 11 Mar 2024 07:09:41 +0900 Subject: [PATCH] fix: specify a commit hash when downloading a plan file --- terraform-apply/download_plan_file.sh | 10 +++------- terraform-apply/github-comment.yaml | 10 ---------- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/terraform-apply/download_plan_file.sh b/terraform-apply/download_plan_file.sh index 9203b3c44..b38d6aaf2 100644 --- a/terraform-apply/download_plan_file.sh +++ b/terraform-apply/download_plan_file.sh @@ -9,14 +9,10 @@ workflow=$PLAN_WORKFLOW_NAME pr_head_sha=$(jq -r ".head.sha" "$CI_INFO_TEMP_DIR/pr.json") -body=$(gh run list -w "$workflow" -b "$branch" -L 1 --json headSha,databaseId --jq '.[0]') -run_id=$(echo "$body" | jq -r ".databaseId") -head_sha=$(echo "$body" | jq -r ".headSha") +run_id=$(gh run list -c "$pr_head_sha" -w "$workflow" -b "$branch" -L 1 --json databaseId --jq '.[0].databaseId') -if [ "$head_sha" != "$pr_head_sha" ]; then - echo "::error::workflow run's headSha is different from the associated pull request's head sha" - github-comment post -k invalid-workflow-sha \ - -var "wf_sha:$head_sha" -var "pr_sha:$pr_head_sha" +if [ -z "$run_id" ]; then + echo "::error::No workflow run is found (branch: $branch, commit:$pr_head_sha, workflow: $workflow)" exit 1 fi diff --git a/terraform-apply/github-comment.yaml b/terraform-apply/github-comment.yaml index 803cf7404..e0ebba5a1 100644 --- a/terraform-apply/github-comment.yaml +++ b/terraform-apply/github-comment.yaml @@ -1,14 +1,4 @@ # https://github.com/suzuki-shunsuke/github-comment -post: - invalid-workflow-sha: - template: | - ## :x: {{if .Vars.tfaction_target}}{{.Vars.tfaction_target}}: {{end}}workflow run's headSha is invalid - - {{template "link" .}} - - It failed to get a Terraform plan file from the pull request workflow run's artifacts. - workflow run's headSha ({{.Vars.wf_sha}}) is different from the associated pull request's head sha ({{.Vars.pr_sha}}). - exec: default: - when: ExitCode != 0