Skip to content

Commit e235a0a

Browse files
committed
Setup infracost
1 parent 0d21931 commit e235a0a

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

.github/workflows/infracost.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
on:
2+
pull_request:
3+
types: [opened, synchronize, closed]
4+
push:
5+
branches:
6+
- main
7+
8+
env:
9+
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
10+
jobs:
11+
infracost-pull-request-checks:
12+
name: Infracost Pull Request Checks
13+
if: github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'synchronize')
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: read
17+
pull-requests: write # Required to post comments
18+
steps:
19+
- name: Setup Infracost
20+
uses: infracost/actions/setup@v3
21+
with:
22+
api-key: ${{ secrets.INFRACOST_API_KEY }}
23+
24+
- name: Checkout base branch
25+
uses: actions/checkout@v4
26+
with:
27+
ref: '${{ github.event.pull_request.base.ref }}'
28+
29+
- name: Generate Infracost cost estimate baseline
30+
run: |
31+
infracost breakdown --path=. \
32+
--format=json \
33+
--out-file=/tmp/infracost-base.json
34+
35+
- name: Checkout PR branch
36+
uses: actions/checkout@v4
37+
38+
- name: Generate Infracost diff
39+
run: |
40+
infracost diff --path=. \
41+
--format=json \
42+
--compare-to=/tmp/infracost-base.json \
43+
--out-file=/tmp/infracost.json
44+
45+
- name: Post Infracost comment
46+
run: |
47+
infracost comment github --path=/tmp/infracost.json \
48+
--repo=$GITHUB_REPOSITORY \
49+
--github-token=${{ github.token }} \
50+
--pull-request=${{ github.event.pull_request.number }} \
51+
--behavior=update

0 commit comments

Comments
 (0)