From 243cd29187ff1f48d8c407f2589303808e449b7f Mon Sep 17 00:00:00 2001 From: yhna940 Date: Sat, 24 Feb 2024 21:56:17 +0900 Subject: [PATCH] Add infracost --- .github/workflows/cost.yml | 49 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 .github/workflows/cost.yml diff --git a/.github/workflows/cost.yml b/.github/workflows/cost.yml new file mode 100644 index 0000000..b6df588 --- /dev/null +++ b/.github/workflows/cost.yml @@ -0,0 +1,49 @@ +name: Cost Estimation + +on: + pull_request: + types: [opened, synchronize, closed] + +jobs: + infracost-pull-request-checks: + name: Infracost Pull Request Checks + if: github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'synchronize') + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: write # Required to post comments + steps: + + - name: Setup Infracost + uses: infracost/actions/setup@v2 + 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 baseline + run: | + infracost breakdown --path=. \ + --format=json \ + --out-file=/tmp/infracost-base.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