forked from clouddrove/github-shared-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
101 lines (91 loc) · 3.69 KB
/
Copy pathinfracost.yml
File metadata and controls
101 lines (91 loc) · 3.69 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
---
name: 💸 Infracost Analysis
on:
workflow_call:
inputs:
working-directory:
required: true
description: Working directory of terraform resources
type: string
default: ./
slack_notification:
description: Slack notification required or not
type: string
default: false
secrets:
INFRACOST_API_KEY:
required: true
description: Provide Key from infracost api
GITHUB:
required: true
description: GitHub token.
SLACK_WEBHOOK:
required: false
description: Slack webhook url
jobs:
infracost:
name: 💸 Infracost Analysis
runs-on: ubuntu-latest
steps:
- name: 🛠️ Setup Infracost
uses: infracost/actions/setup@d51fc54d23c9ad90f984b884257bd96dc2625067
with:
api-key: ${{ secrets.INFRACOST_API_KEY }}
- name: 📦 Checkout Repository
uses: actions/checkout@v7
with:
ref: ${{ github.event.pull_request.base.ref }}
- name: 🐞 Print debug info
run: |
echo "github base branch is ${{ github.event.pull_request.base.ref }}"
echo "github.event.pull_request.number is ${{ github.event.pull_request.number }}"
- name: 🧮 Generate Infracost cost estimate baseline
run: |
export INFRACOST_API_KEY=${{ secrets.INFRACOST_API_KEY }}
cd ${{ inputs.working-directory }}
infracost breakdown --path . \
--format=json \
--out-file=/tmp/infracost-base.json
- name: 📦 Checkout Repository
uses: actions/checkout@v7
- name: 🔀 Generate Infracost diff
run: |
export INFRACOST_API_KEY=${{ secrets.INFRACOST_API_KEY }}
cd ${{ inputs.working-directory }}
infracost diff --path=. \
--format=json \
--show-skipped \
--compare-to=/tmp/infracost-base.json \
--out-file=/tmp/infracost.json
- name: 📝 Generate Infracost Report
run: |
export INFRACOST_API_KEY=${{ secrets.INFRACOST_API_KEY }}
cd ${{ inputs.working-directory }}
infracost output --path /tmp/infracost.json --show-skipped --format html --out-file report.html
- name: 📤 Upload current cost in artifactory
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f
with:
name: report.html
path: ${{ inputs.working-directory }}/report.html
- name: 💬 Post Infracost comment
run: |
export INFRACOST_API_KEY=${{ secrets.INFRACOST_API_KEY }}
infracost comment github --path=/tmp/infracost.json \
--repo=$GITHUB_REPOSITORY \
--github-token=${{ secrets.GITHUB }} \
--pull-request=${{ github.event.pull_request.number }} \
--behavior=update
- name: 📨 Generate Slack message
id: infracost-slack
run: |
echo "::set-output name=slack-message::$(infracost output --path=/tmp/infracost.json --format=slack-message --show-skipped)"
echo "::set-output name=diffTotalMonthlyCost::$(jq '(.diffTotalMonthlyCost // 0) | tonumber' /tmp/infracost.json)"
- name: 🚀 Send cost estimate to Slack
uses: slackapi/slack-github-action@v3
if: ${{ inputs.slack_notification == 'true' }}
with:
payload: ${{ steps.infracost-slack.outputs.slack-message }}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK}}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
...