| 
50 | 50 |                                      --github-token=${{ github.token }} \  | 
51 | 51 |                                      --pull-request=${{ github.event.pull_request.number }} \  | 
52 | 52 |                                      --behavior=update  | 
 | 53 | +
  | 
 | 54 | +  infracost-default-branch-update:  | 
 | 55 | +    name: Infracost Default Branch Update  | 
 | 56 | +    if: github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'master')  | 
 | 57 | +    runs-on: ubuntu-latest  | 
 | 58 | +    steps:  | 
 | 59 | +      - name: Setup Infracost  | 
 | 60 | +        uses: infracost/actions/setup@v3  | 
 | 61 | +        with:  | 
 | 62 | +          api-key: ${{ secrets.INFRACOST_API_KEY }}  | 
 | 63 | + | 
 | 64 | +      - name: Checkout main/master branch  | 
 | 65 | +        uses: actions/checkout@v4  | 
 | 66 | + | 
 | 67 | +      - name: Run Infracost on default branch and update Infracost Cloud  | 
 | 68 | +        run: |  | 
 | 69 | +          infracost breakdown --path=terraform/ \  | 
 | 70 | +                    --format=json \  | 
 | 71 | +                    --out-file=infracost.json  | 
 | 72 | +
  | 
 | 73 | +          infracost upload --path=infracost.json || echo "Always pass main branch runs even if there are policy failures"  | 
 | 74 | +
  | 
 | 75 | +  # Update PR status in Infracost Cloud  | 
 | 76 | +  infracost-pull-request-status-update:  | 
 | 77 | +    name: Infracost PR Status Update  | 
 | 78 | +    if: github.event_name == 'pull_request' && github.event.action == 'closed'  | 
 | 79 | +    runs-on: ubuntu-latest  | 
 | 80 | +    steps:  | 
 | 81 | +    - name: Infracost PR Status Update  | 
 | 82 | +      run: |  | 
 | 83 | +        PR_STATUS="MERGED"  | 
 | 84 | +        if [[ ${{ github.event.pull_request.merged }} = false ]]; then PR_STATUS="CLOSED"; fi  | 
 | 85 | +
  | 
 | 86 | +        echo "Updating status of ${{ github.event.pull_request.html_url }} to $PR_STATUS"  | 
 | 87 | +        curl -i \  | 
 | 88 | +          --request POST \  | 
 | 89 | +          --header "Content-Type: application/json" \  | 
 | 90 | +          --header "X-API-Key: $INFRACOST_API_KEY" \  | 
 | 91 | +          --data "{ \"query\": \"mutation {updatePullRequestStatus( url: \\\"${{ github.event.pull_request.html_url }}\\\", status: $PR_STATUS )}\" }" \  | 
 | 92 | +          "https://dashboard.api.infracost.io/graphql";  | 
 | 93 | +      env:  | 
 | 94 | +        INFRACOST_API_KEY: ${{ secrets.INFRACOST_API_KEY }}  | 
0 commit comments