Skip to content

feat: Automatically run the exporter when the queue is empty. #197

feat: Automatically run the exporter when the queue is empty.

feat: Automatically run the exporter when the queue is empty. #197

Workflow file for this run

name: Pull request checks
on:
pull_request:
jobs:
configs:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout source code
uses: actions/checkout@v4
- name: Find changed OpenTofu modules
id: modified
uses: ./.github/actions/changed-modules
with:
working-directory: tofu/config
- name: Strip prefix from modified configs
id: configs
uses: actions/github-script@v7
with:
script: |
const modules = ${{ steps.modified.outputs.modules }}
const configs = modules.map(m => m.replace(/^tofu\/config\//, ''))
core.setOutput('configs', configs)
- name: Show modified configs
run: |
echo "${{ steps.configs.outputs.configs }}"
outputs:
configs: ${{ steps.configs.outputs.configs }}
plan:
uses: ./.github/workflows/plan.yaml
needs: configs
permissions:
contents: read
id-token: write
strategy:
matrix:
config: ${{ fromJson(needs.configs.outputs.configs) }}
with:
environment: development
config: ${{ matrix.config }}
image_tag: ${{ github.sha }}
secrets:
AWS_REGION: ${{ secrets.AWS_REGION }}
AWS_ROLE_ARN: ${{ secrets.AWS_ROLE_ARN }}
TF_VAR_APPLY_DATABASE_UPDATES_IMMEDIATELY: ${{ secrets.TF_VAR_APPLY_DATABASE_UPDATES_IMMEDIATELY }}
TF_VAR_DATABASE_SKIP_FINAL_SNAPSHOT: ${{ secrets.TF_VAR_DATABASE_SKIP_FINAL_SNAPSHOT }}
TF_VAR_CONSUMER_CONTAINER_COUNT: ${{ secrets.TF_VAR_CONSUMER_CONTAINER_COUNT }}
TF_VAR_CONSUMER_CONTAINER_MAX: ${{ secrets.TF_VAR_CONSUMER_CONTAINER_MAX }}
TF_VAR_CONSUMER_CPU: ${{ secrets.TF_VAR_CONSUMER_CPU }}
TF_VAR_CONSUMER_MEMORY: ${{ secrets.TF_VAR_CONSUMER_MEMORY }}
TF_VAR_CONSUMER_MESSAGE_THRESHOLD: ${{ secrets.TF_VAR_CONSUMER_MESSAGE_THRESHOLD }}
TF_VAR_DELETION_PROTECTION: ${{ secrets.TF_VAR_DELETION_PROTECTION }}
TF_VAR_DEPLOYMENT_ENVIRONMENTS: ${{ secrets.TF_VAR_DEPLOYMENT_ENVIRONMENTS }}
TF_VAR_EXPORT_EXPIRATION: ${{ secrets.TF_VAR_EXPORT_EXPIRATION }}
TF_VAR_IMAGE_TAGS_MUTABLE: ${{ secrets.TF_VAR_IMAGE_TAGS_MUTABLE }}
TF_VAR_KEY_RECOVERY_PERIOD: ${{ secrets.TF_VAR_KEY_RECOVERY_PERIOD }}
TF_VAR_LOG_LEVEL: ${{ secrets.TF_VAR_LOG_LEVEL }}
TF_VAR_PROGRAM: ${{ secrets.TF_VAR_PROGRAM }}
TF_VAR_QUEUE_EMPTY_THRESHOLD: ${{ secrets.TF_VAR_QUEUE_EMPTY_THRESHOLD }}
TF_VAR_REDOER_CONTAINER_COUNT: ${{ secrets.TF_VAR_REDOER_CONTAINER_COUNT }}
TF_VAR_REDOER_CPU: ${{ secrets.TF_VAR_REDOER_CPU }}
TF_VAR_REDOER_MEMORY: ${{ secrets.TF_VAR_REDOER_MEMORY }}
TF_VAR_REPO_OIDC_ARN: ${{ secrets.TF_VAR_REPO_OIDC_ARN }}
TF_VAR_REPOSITORY: ${{ secrets.TF_VAR_REPOSITORY }}
TF_VAR_SENZING_LICENSE_BASE64: ${{ secrets.TF_VAR_SENZING_LICENSE_BASE64 }}
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:
- configs
- plan
permissions:
contents: read
pull-requests: write
strategy:
matrix:
config: ${{ fromJson(needs.configs.outputs.configs) }}
steps:
- name: Download plan file
uses: actions/download-artifact@v4
with:
name: ${{ matrix.config }}-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 for ${{ matrix.config }} config')
})
// 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 for ${{ matrix.config }} config\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
})
}