Skip to content

Commit

Permalink
Merge pull request #199 from appvia/cli_workflow
Browse files Browse the repository at this point in the history
[CLI] - Infracost Workflow
  • Loading branch information
gambol99 committed Jul 1, 2022
2 parents 39621cd + cf1fa1c commit 514bdab
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
2 changes: 0 additions & 2 deletions pkg/cmd/tnctl/workflow/assets/github/ci.yaml.tpl
Expand Up @@ -2,8 +2,6 @@
name: Review

on:
push:
branches: [master, main]
pull_request:
types: [opened, reopened, synchronize]

Expand Down
26 changes: 18 additions & 8 deletions pkg/cmd/tnctl/workflow/assets/github/main.yaml.tpl
Expand Up @@ -148,12 +148,10 @@ jobs:
code-costs:
name: Cost Review
needs: cost-token
if: needs.cost-token.outputs.enable_infracost == 'true'
if: needs.cost-token.outputs.enable_infracost == 'true' && github.event_name == 'pull_request'
runs-on: ubuntu-latest
env:
TF_ROOT: .
outputs:
security: {{ "${{" }} steps.costs.outcome {{ "}}" }}
steps:
- name: Clone repo
uses: actions/checkout@v3
Expand All @@ -163,25 +161,37 @@ jobs:
api-key: {{ "${{" }} secrets.ORG_INFRACOST_API_KEY {{ "}}" }}
- name: Checkout base branch
uses: actions/checkout@v3
if: github.event_name == 'pull_request'
with:
ref: '{{ "${{" }} github.event.pull_request.base.ref {{ "}}" }}'
- name: Generate Infracost cost estimate baseline
if: github.event_name == 'pull_request'
- name: Checking for baseline files
id: baseline
run: |
if ls *.tf 2>/dev/null; then
echo "::set-output name=exists::true"
else
echo "::set-output name=exists::false"
fi
- name: Generate cost estimate baseline
if: steps.baseline.outputs.exists == 'true'
run: |
infracost breakdown --path=${TF_ROOT} \
--format=json \
--out-file=/tmp/infracost-base.json
- name: Checkout PR branch
if: github.event_name == 'pull_request'
uses: actions/checkout@v3
- name: Generate Infracost diff
id: costs
if: steps.baseline.outputs.exists == 'true'
run: |
infracost diff --path=${TF_ROOT} \
--format=json \
--compare-to=/tmp/infracost-base.json \
--out-file=/tmp/infracost.json
- name: Generate Infracost Cost
if: steps.baseline.outputs.exists == 'false'
run: |
infracost breakdown --path=${TF_ROOT} \
--format=json \
--out-file=/tmp/infracost.json
- name: Post Infracost comment
run: |
infracost comment github \
Expand Down

0 comments on commit 514bdab

Please sign in to comment.