|
| 1 | +name: Infracost |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: [main] |
| 6 | + types: [opened, synchronize, reopened] |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: read |
| 10 | + |
| 11 | +jobs: |
| 12 | + report: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + |
| 15 | + permissions: |
| 16 | + contents: read |
| 17 | + pull-requests: write |
| 18 | + |
| 19 | + steps: |
| 20 | + - uses: infracost/actions/setup@e9d6e6cd65e168e76b0de50ff9957d2fe8bb1832 # v3.0.1 |
| 21 | + with: |
| 22 | + api-key: ${{ secrets.INFRACOST_API_KEY }} |
| 23 | + |
| 24 | + # Checkout the base branch of the pull request (e.g. main/master). |
| 25 | + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 |
| 26 | + with: |
| 27 | + ref: ${{ github.event.pull_request.base.ref }} |
| 28 | + |
| 29 | + - run: | |
| 30 | + infracost breakdown --config-file=infracost.yml \ |
| 31 | + --format=json \ |
| 32 | + --out-file=/tmp/infracost-base.json |
| 33 | +
|
| 34 | + # Checkout the current PR branch so we can create a diff. |
| 35 | + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 |
| 36 | + |
| 37 | + # Generate an Infracost diff and save it to a JSON file. |
| 38 | + - run: | |
| 39 | + infracost diff --config-file=infracost.yml \ |
| 40 | + --format=json \ |
| 41 | + --compare-to=/tmp/infracost-base.json \ |
| 42 | + --out-file=/tmp/infracost.json |
| 43 | +
|
| 44 | + # Posts a comment to the PR using the 'update' behavior. |
| 45 | + # This creates a single comment and updates it. The "quietest" option. |
| 46 | + # The other valid behaviors are: |
| 47 | + # delete-and-new - Delete previous comments and create a new one. |
| 48 | + # hide-and-new - Minimize previous comments and create a new one. |
| 49 | + # new - Create a new cost estimate comment on every push. |
| 50 | + # See https://www.infracost.io/docs/features/cli_commands/#comment-on-pull-requests for other options. |
| 51 | + - run: | |
| 52 | + infracost comment github --path=/tmp/infracost.json \ |
| 53 | + --repo="${GITHUB_REPOSITORY}" \ |
| 54 | + --github-token=${{github.token}} \ |
| 55 | + --pull-request=${{github.event.pull_request.number}} \ |
| 56 | + --behavior=update \ |
| 57 | + --show-skipped |
0 commit comments