feat: add repo topics #8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| branches: | |
| - main | |
| env: | |
| AWS_REGION: ${{ vars.AWS_REGION }} | |
| AWS_ENDPOINT_URL_S3: ${{ vars.AWS_ENDPOINT_URL_S3 }} | |
| AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| GITHUB_OWNER: ${{ vars.OWNER }} | |
| GITHUB_APP_ID: ${{ vars.APP_ID }} | |
| GITHUB_APP_INSTALLATION_ID: ${{ vars.APP_INSTALLATION_ID }} | |
| GITHUB_APP_PEM_FILE: ${{ secrets.APP_PEM_FILE }} | |
| jobs: | |
| terraform: | |
| name: "Terraform" | |
| runs-on: ubuntu-latest | |
| defaults: | |
| run: | |
| shell: bash | |
| steps: | |
| - name: Checkout the repository to the runner | |
| uses: actions/checkout@v4 | |
| - name: Setup Terraform with specified version on the runner | |
| uses: hashicorp/setup-terraform@v3 | |
| with: | |
| terraform_version: 1.11.0 | |
| - name: Terraform init | |
| id: init | |
| run: terraform init | |
| - 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@v7 | |
| if: github.event_name == 'pull_request' | |
| env: | |
| PLAN: "terraform\n${{ steps.plan.outputs.stdout }}" | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| // 1. Retrieve existing bot comments for the PR | |
| const { data: comments } = await github.rest.issues.listComments({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| }); | |
| const botComment = comments.find(comment => { | |
| return comment.user.type === 'Bot' && comment.body.includes('<!-- GitHub Actions Terraform PR comment bot -->') | |
| }); | |
| // 2. Put together bot new comment contents for the PR | |
| const output = `<!-- GitHub Actions Terraform PR comment bot --> | |
| #### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\` | |
| #### Terraform Plan 📖\`${{ steps.plan.outcome }}\` | |
| <details><summary>Show Plan</summary> | |
| \`\`\`\n | |
| ${process.env.PLAN} | |
| \`\`\` | |
| </details> | |
| *Pushed by: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`; | |
| // 3. Delete previous comment for the PR | |
| if (botComment) { | |
| github.rest.issues.deleteComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: botComment.id, | |
| }); | |
| } | |
| // 4. Create a new comment | |
| github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| body: output | |
| }); | |
| - name: Terraform Plan Status | |
| if: steps.plan.outcome == 'failure' | |
| run: exit 1 | |
| - name: Terraform Apply | |
| if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
| run: terraform apply -auto-approve -input=false |