Skip to content

Commit

Permalink
fix: handle case when entire TF project is deleted and (#94)
Browse files Browse the repository at this point in the history
combine pre_workflow_hooks into 1 run command so 1 GH status item is shown for that

Thanks to https://github.com/firataras to finding and verifying the fixes
  • Loading branch information
alikhajeh1 committed Jul 10, 2024
1 parent 919b1b7 commit f4e8855
Showing 1 changed file with 47 additions and 41 deletions.
88 changes: 47 additions & 41 deletions examples/infracost-comment/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,23 @@ This Atlantis repo.yaml file shows how Infracost can be used with Atlantis. Even
workflow: terraform-infracost
pre_workflow_hooks:
# Clean up any files left over from previous runs
- run: rm -rf /tmp/$BASE_REPO_OWNER-$BASE_REPO_NAME-$PULL_NUM
commands: plan
- run: mkdir -p /tmp/$BASE_REPO_OWNER-$BASE_REPO_NAME-$PULL_NUM
- run: |
INFRACOST_DIR=/tmp/$BASE_REPO_OWNER-$BASE_REPO_NAME-$PULL_NUM
rm -rf $INFRACOST_DIR && \
mkdir -p $INFRACOST_DIR
commands: plan
post_workflow_hooks:
- run: |
# Choose the commenting behavior, 'new' is a good default:
# new: Create a new cost estimate comment on every run of Atlantis for each project.
# update: Create a single comment and update it. The "quietest" option.
# hide-and-new: Minimize previous comments and create a new one.
# delete-and-new: Delete previous comments and create a new one.
infracost comment github --repo $BASE_REPO_OWNER/$BASE_REPO_NAME \
INFRACOST_DIR=/tmp/$BASE_REPO_OWNER-$BASE_REPO_NAME-$PULL_NUM
if [ "$(ls -A $INFRACOST_DIR)" ]; then
infracost comment github --repo $BASE_REPO_OWNER/$BASE_REPO_NAME \
--pull-request $PULL_NUM \
--path /tmp/$BASE_REPO_OWNER-$BASE_REPO_NAME-$PULL_NUM/'*'-infracost.json \
--path $INFRACOST_DIR/'*'-infracost.json \
--github-token $GITHUB_TOKEN \
--behavior new
else
echo "Infracost comment not posted because $INFRACOST_DIR is empty."
fi
commands: plan
workflows:
terraform-infracost:
Expand Down Expand Up @@ -98,21 +99,23 @@ This Atlantis repo.yaml file shows how Infracost can be used with Atlantis. Even
workflow: terraform-infracost
pre_workflow_hooks:
# Clean up any files left over from previous runs
- run: rm -rf /tmp/$BASE_REPO_OWNER-$BASE_REPO_NAME-$PULL_NUM
command: plan
- run: mkdir -p /tmp/$BASE_REPO_OWNER-$BASE_REPO_NAME-$PULL_NUM
- run: |
INFRACOST_DIR=/tmp/$BASE_REPO_OWNER-$BASE_REPO_NAME-$PULL_NUM
rm -rf $INFRACOST_DIR && \
mkdir -p $INFRACOST_DIR
command: plan
post_workflow_hooks:
- run: |
# Choose the commenting behavior, 'new' is a good default:
# new: Create a new cost estimate comment on every run of Atlantis for each project.
# update: Create a single comment and update it. The "quietest" option.
# delete-and-new: Delete previous comments and create a new one.
infracost comment gitlab --repo $BASE_REPO_OWNER/$BASE_REPO_NAME \
--merge-request $PULL_NUM \
--path /tmp/$BASE_REPO_OWNER-$BASE_REPO_NAME-$PULL_NUM/'*'-infracost.json \
--gitlab-token $GITLAB_TOKEN \
--behavior new
INFRACOST_DIR=/tmp/$BASE_REPO_OWNER-$BASE_REPO_NAME-$PULL_NUM
if [ "$(ls -A $INFRACOST_DIR)" ]; then
infracost comment gitlab --repo $BASE_REPO_OWNER/$BASE_REPO_NAME \
--merge-request $PULL_NUM \
--path $INFRACOST_DIR/'*'-infracost.json \
--gitlab-token $GITLAB_TOKEN \
--behavior new
else
echo "Infracost comment not posted because $INFRACOST_DIR is empty."
fi
command: plan
workflows:
terraform-infracost:
Expand Down Expand Up @@ -152,22 +155,24 @@ This Atlantis repo.yaml file shows how Infracost can be used with Atlantis. Even
workflow: terraform-infracost
pre_workflow_hooks:
# Clean up any files left over from previous runs
- run: rm -rf /tmp/${BASE_REPO_OWNER//\//-}-$BASE_REPO_NAME-$PULL_NUM
command: plan
- run: mkdir -p /tmp/${BASE_REPO_OWNER//\//-}-$BASE_REPO_NAME-$PULL_NUM
- run: |
INFRACOST_DIR=/tmp/${BASE_REPO_OWNER//\//-}-$BASE_REPO_NAME-$PULL_NUM
rm -rf $INFRACOST_DIR && \
mkdir -p $INFRACOST_DIR
command: plan
post_workflow_hooks:
- run: |
# Choose the commenting behavior, 'new' is a good default:
# new: Create a new cost estimate comment on every run of Atlantis for each project.
# update: Create a single comment and update it. The "quietest" option.
# delete-and-new: Delete previous comments and create a new one.
infracost comment azure-repos --repo-url $AZURE_REPO_URL \
INFRACOST_DIR=/tmp/${BASE_REPO_OWNER//\//-}-$BASE_REPO_NAME-$PULL_NUM
if [ "$(ls -A $INFRACOST_DIR)" ]; then
infracost comment azure-repos --repo-url $AZURE_REPO_URL \
--pull-request $PULL_NUM \
--path /tmp/${BASE_REPO_OWNER//\//-}-$BASE_REPO_NAME-$PULL_NUM/'*'-infracost.json \
--path $INFRACOST_DIR/'*'-infracost.json \
--azure-access-token $AZURE_ACCESS_TOKEN \
--tag $INFRACOST_COMMENT_TAG \
--behavior new
else
echo "Infracost comment not posted because $INFRACOST_DIR is empty."
fi
command: plan
workflows:
terraform-infracost:
Expand Down Expand Up @@ -206,22 +211,23 @@ This Atlantis repo.yaml file shows how Infracost can be used with Atlantis. Even
workflow: terraform-infracost
pre_workflow_hooks:
# Clean up any files left over from previous runs
- run: rm -rf /tmp/$BASE_REPO_OWNER-$BASE_REPO_NAME-$PULL_NUM
commands: plan
- run: mkdir -p /tmp/$BASE_REPO_OWNER-$BASE_REPO_NAME-$PULL_NUM
- run: |
INFRACOST_DIR=/tmp/$BASE_REPO_OWNER-$BASE_REPO_NAME-$PULL_NUM
rm -rf $INFRACOST_DIR && \
mkdir -p $INFRACOST_DIR
commands: plan
post_workflow_hooks:
- run: |
# Choose the commenting behavior, 'new' is a good default:
# new: Create a new cost estimate comment on every run of Atlantis for each project.
# update: Create a single comment and update it. The "quietest" option.
# hide-and-new: Minimize previous comments and create a new one.
# delete-and-new: Delete previous comments and create a new one.
infracost comment bitbucket --repo $BASE_REPO_OWNER/$BASE_REPO_NAME \
INFRACOST_DIR=/tmp/$BASE_REPO_OWNER-$BASE_REPO_NAME-$PULL_NUM
if [ "$(ls -A $INFRACOST_DIR)" ]; then
infracost comment bitbucket --repo $BASE_REPO_OWNER/$BASE_REPO_NAME \
--pull-request $PULL_NUM \
--path /tmp/$BASE_REPO_OWNER-$BASE_REPO_NAME-$PULL_NUM/'*'-infracost.json \
--path $INFRACOST_DIR/'*'-infracost.json \
--bitbucket-token $BITBUCKET_TOKEN \
--behavior new
else
echo "Infracost comment not posted because $INFRACOST_DIR is empty."
fi
commands: plan
workflows:
terraform-infracost:
Expand Down

0 comments on commit f4e8855

Please sign in to comment.