- name: Checkout base branch
uses: actions/checkout@v3
with:
ref: main
# Generate Infracost JSON file as the baseline. --format=json
- name: Generate Infracost cost estimate baseline
run: |
current_env=$(basename ${{ inputs.WORKING_DIR }})
infracost breakdown --include-all-paths --show-skipped --path=${{ inputs.WORKING_DIR }}
infracost breakdown --include-all-paths --show-skipped --fields=all --format=json --out-file="/tmp/$current_env-base.json" --path=${{ inputs.WORKING_DIR }}
- name: Checkout Current branch
uses: actions/checkout@v3
- name: Generate Infracost diff
run: |
current_env=$(basename ${{ inputs.WORKING_DIR }})
mkdir -p tmp/${{ inputs.WORKING_DIR }}
infracost diff --include-all-paths --show-skipped --compare-to="/tmp/$current_env-base.json" --path=${{ inputs.WORKING_DIR }}
infracost diff --include-all-paths --show-skipped --compare-to="/tmp/$current_env-base.json" --format=json --path=${{ inputs.WORKING_DIR }} --out-file="tmp/${{ inputs.WORKING_DIR }}/infracost-diff.json"
- uses: actions/upload-artifact@v3
if: github.event_name == 'pull_request'
with:
name: infracost-${{ inputs.ENV }}
path: tmp/${{ inputs.WORKING_DIR }}/infracost-diff.json
infracost-pr-comment:
needs: ["infracost-estimates"]
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v3
if: github.event_name == 'pull_request'
with:
name: infracost-${{ inputs.ENV }}
path: tmp/${{ inputs.WORKING_DIR }}
- name: Setup Infracost
uses: infracost/actions/setup@v2
# See
https://github.com/infracost/actions/tree/master/setup for other inputs
# If you can't use this action, see Docker images in
https://infracost.io/cicd
with:
api-key: ${{ secrets.INFRACOST_API_KEY }}
- name: Post Infracost comment
if: github.event_name == 'pull_request'
working-directory: tmp/${{ inputs.WORKING_DIR }}
run: |
current_env=$(basename ${{ inputs.WORKING_DIR }})
ls -l
infracost comment github --show-all-projects --show-skipped --path="./infracost-diff.json" --repo=$GITHUB_REPOSITORY --github-token=${{ secrets.GIT_TOKEN }} --pull-request=${{github.event.pull_request.number}} --behavior=new