Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/infra_features.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ jobs:
ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}

runs-on: ubuntu-latest

defaults:
run:
shell: bash
Expand Down
166 changes: 87 additions & 79 deletions .github/workflows/infra_main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,88 +2,96 @@ name: infra-main

on:
pull_request:
types: [opened, closed]
branches:
- infra_main
types: [opened, closed]
push:
branches:
- infra_main

jobs:
infracost-pull-request-checks:
name: Infracost Pull Request Checks
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
permissions:
contents: read
pull_request: write

steps:
- name: Checkout PR branch
uses: actions/checkout@v4

- name: Terraform plan
id: plan
if: github.event_name == 'pull_request'
run: terraform plan -no-color -input=false
continue-on-error: true

- uses: actions/github-script@v6
if: github.event_name == 'pull_request'
env:
PLAN: "terraform\n${{ steps.plan.outputs.stdout }}"
with:
script: |
const output = `#### Terraform Plan 📖`${{ steps.plan.outcome }}\`

<details><summary>Show Plan</summary>

\`\`\`\n
${process.env.PLAN}
\`\`\`

</details>
*Pushed by: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`;

github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})

- name: Terraform Plan Status
if: steps.plan.outcome == 'failure'
run: exit 1

- name: Setup Infracost
uses: infracost/actions/setup@v3
with:
api-key: ${{ secrets.INFRACOST_API_KEY }}

# - name: Checkout base branch
# uses: actions/checkout@v4
# with:
# ref: '${{ github.event.pull_request.base.ref }}'

- name: Generate Infracost cost estimate
run: |
infracost breakdown --path=infrastructure \
--format=json \
--out-file=/tmp/infracost.json

# - name: Checkout PR branch
# uses: actions/checkout@v4

# - name: Generate Infracost diff
# run: |
# infracost diff --path=. \
# --format=json \
# --compare-to=/tmp/infracost-base.json \
# --out-file=/tmp/infracost.json

- name: Post Infracost comment
run: |
infracost comment github --path=/tmp/infracost.json \
--repo=$GITHUB_REPOSITORY \
--github-token=${{ github.token }} \
--pull-request=${{ github.event.pull_request.number }} \
--behavior=update
env:
ARM_CLIENT_ID: ${{ secrets.ARM_CLIENT_ID }}
ARM_CLIENT_SECRET: ${{ secrets.ARM_CLIENT_SECRET }}
ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}

name: Infracost Pull Request Checks
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
permissions:
contents: read
pull_request: write

steps:
- name: Checkout PR branch
uses: actions/checkout@v3

- name: Terraform plan
id: plan
if: github.event_name == 'pull_request'
run: terraform plan -no-color -input=false
continue-on-error: true

- uses: actions/github-script@v6
if: github.event_name == 'pull_request'
env:
PLAN: "terraform\n${{ steps.plan.outputs.stdout }}"
with:
script: |
const output = `#### Terraform Plan 📖`${{ steps.plan.outcome }}\`

<details><summary>Show Plan</summary>

\`\`\`\n
${process.env.PLAN}
\`\`\`

</details>
*Pushed by: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`;

github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})

- name: Terraform Plan Status
if: steps.plan.outcome == 'failure'
run: exit 1

- name: Setup Infracost
uses: infracost/actions/setup@v3
with:
api-key: ${{ secrets.INFRACOST_API_KEY }}

# - name: Checkout base branch
# uses: actions/checkout@v4
# with:
# ref: '${{ github.event.pull_request.base.ref }}'

- name: Generate Infracost cost estimate
run: |
infracost breakdown --path=infrastructure \
--format=json \
--out-file=/tmp/infracost.json

# - name: Checkout PR branch
# uses: actions/checkout@v4

# - name: Generate Infracost diff
# run: |
# infracost diff --path=. \
# --format=json \
# --compare-to=/tmp/infracost-base.json \
# --out-file=/tmp/infracost.json

- name: Post Infracost comment
run: |
infracost comment github --path=/tmp/infracost.json \
--repo=$GITHUB_REPOSITORY \
--github-token=${{ github.token }} \
--pull-request=${{ github.event.pull_request.number }} \
--behavior=update