Skip to content

Commit 2e5bb22

Browse files
committed
setup infracost usage
1 parent b1194b8 commit 2e5bb22

File tree

2 files changed

+984
-42
lines changed

2 files changed

+984
-42
lines changed

.github/workflows/infracost.yml

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ jobs:
3131
run: |
3232
infracost breakdown --path=terraform/ \
3333
--format=json \
34+
--usage-file infracost-usage.yml \
3435
--out-file=/tmp/infracost-base.json
3536
3637
- name: Checkout PR branch
@@ -40,6 +41,7 @@ jobs:
4041
run: |
4142
infracost diff --path=terraform/ \
4243
--format=json \
44+
--usage-file infracost-usage.yml \
4345
--compare-to=/tmp/infracost-base.json \
4446
--out-file=/tmp/infracost.json
4547
@@ -50,45 +52,3 @@ jobs:
5052
--github-token=${{ github.token }} \
5153
--pull-request=${{ github.event.pull_request.number }} \
5254
--behavior=update
53-
54-
infracost-default-branch-update:
55-
name: Infracost Default Branch Update
56-
if: github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'master')
57-
runs-on: ubuntu-latest
58-
steps:
59-
- name: Setup Infracost
60-
uses: infracost/actions/setup@v3
61-
with:
62-
api-key: ${{ secrets.INFRACOST_API_KEY }}
63-
64-
- name: Checkout main/master branch
65-
uses: actions/checkout@v4
66-
67-
- name: Run Infracost on default branch and update Infracost Cloud
68-
run: |
69-
infracost breakdown --path=terraform/ \
70-
--format=json \
71-
--out-file=infracost.json
72-
73-
infracost upload --path=infracost.json || echo "Always pass main branch runs even if there are policy failures"
74-
75-
# Update PR status in Infracost Cloud
76-
infracost-pull-request-status-update:
77-
name: Infracost PR Status Update
78-
if: github.event_name == 'pull_request' && github.event.action == 'closed'
79-
runs-on: ubuntu-latest
80-
steps:
81-
- name: Infracost PR Status Update
82-
run: |
83-
PR_STATUS="MERGED"
84-
if [[ ${{ github.event.pull_request.merged }} = false ]]; then PR_STATUS="CLOSED"; fi
85-
86-
echo "Updating status of ${{ github.event.pull_request.html_url }} to $PR_STATUS"
87-
curl -i \
88-
--request POST \
89-
--header "Content-Type: application/json" \
90-
--header "X-API-Key: $INFRACOST_API_KEY" \
91-
--data "{ \"query\": \"mutation {updatePullRequestStatus( url: \\\"${{ github.event.pull_request.html_url }}\\\", status: $PR_STATUS )}\" }" \
92-
"https://dashboard.api.infracost.io/graphql";
93-
env:
94-
INFRACOST_API_KEY: ${{ secrets.INFRACOST_API_KEY }}

0 commit comments

Comments
 (0)