Skip to content
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

fix: specify a commit hash when downloading a plan file #1570

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions terraform-apply/download_plan_file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://cli.github.com/manual/gh_run_list

  -c, --commit SHA        Filter runs by the SHA of the commit

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If no workflow run is found, the command succeeds but run_id is empty.


if [ "$head_sha" != "$pr_head_sha" ]; then
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We specify a commit hash when downloading a plan file, so we don't have to check a commit hash anymore.

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

Expand Down
10 changes: 0 additions & 10 deletions terraform-apply/github-comment.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
# https://github.com/suzuki-shunsuke/github-comment
post:
invalid-workflow-sha:
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This template isn't used anymore.

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
Expand Down