-
-
Notifications
You must be signed in to change notification settings - Fork 39
/
main.sh
26 lines (21 loc) · 938 Bytes
/
main.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/env bash
set -eu
set -o pipefail
if [ -n "${S3_BUCKET_NAME_PLAN_FILE:-}" ]; then
github-comment exec -- aws s3 cp "s3://$S3_BUCKET_NAME_PLAN_FILE/$CI_INFO_PR_NUMBER/$TFACTION_TARGET/tfplan.binary" tfplan.binary
elif [ -n "${GCS_BUCKET_NAME_PLAN_FILE:-}" ]; then
github-comment exec -- gsutil cp "gs://$GCS_BUCKET_NAME_PLAN_FILE/$CI_INFO_PR_NUMBER/$TFACTION_TARGET/tfplan.binary" tfplan.binary
fi
set +e
tfcmt -var "target:$TFACTION_TARGET" apply -- terraform apply -auto-approve -no-color -input=false tfplan.binary
code=$?
set -e
while read -r pr_number; do
if [ "$CI_INFO_PR_NUMBER" = "$pr_number" ]; then
# To prevent infinite loop
continue
fi
echo "===> Update PR $pr_number" >&2
env GITHUB_TOKEN="$GITHUB_APP_TOKEN" gh api -X PUT "repos/{owner}/{repo}/pulls/${pr_number}/update-branch" || :
done < <(github-comment exec -- gh pr list --json number -L 100 -l "$TFACTION_TARGET" -q ".[].number")
exit "$code"