Skip to content

Consumer app and utils #64

Consumer app and utils

Consumer app and utils #64

Workflow file for this run

name: Pull request checks
on:
pull_request:
jobs:
plan:
uses: ./.github/workflows/plan.yaml
permissions:
contents: read
id-token: write
with:
environment: development
secrets:
AWS_REGION: ${{ secrets.AWS_REGION }}
AWS_ROLE_ARN: ${{ secrets.AWS_ROLE_ARN }}
TF_VAR_EXPORT_EXPIRATION: ${{ secrets.TF_VAR_EXPORT_EXPIRATION }}
TF_VAR_KEY_RECOVERY_PERIOD: ${{ secrets.TF_VAR_KEY_RECOVERY_PERIOD }}
TF_VAR_PROGRAM: ${{ secrets.TF_VAR_PROGRAM }}
TF_VAR_VPC_CIDR: ${{ secrets.TF_VAR_VPC_CIDR }}
TF_VAR_VPC_PRIVATE_SUBNET_CIDRS: ${{ secrets.TF_VAR_VPC_PRIVATE_SUBNET_CIDRS }}
TF_VAR_VPC_PUBLIC_SUBNET_CIDRS: ${{ secrets.TF_VAR_VPC_PUBLIC_SUBNET_CIDRS }}
comment:
runs-on: ubuntu-latest
needs: plan
permissions:
contents: read
pull-requests: write
env:
CONFIG_PATH: ./tofu/config/development
steps:
- name: Download plan file
uses: actions/download-artifact@v4
with:
name: tfplan
- uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
// Retrieve existing bot comments for the pull request.
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('## Plan output')
})
// Read the contents of the plan.
const fs = require('fs');
const plan = fs.readFileSync('./plan.txt', 'utf8');
// Prepare the format of the comment.
const output = `## Plan output\n\n\`\`\`\n${plan}\n\`\`\``
// If we have a comment, update it. Otherwise, create a new one.
if (botComment) {
github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: output
})
} else {
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
}