Skip to content

eddiewebb is testing out GitHub Actions πŸš€ #7

eddiewebb is testing out GitHub Actions πŸš€

eddiewebb is testing out GitHub Actions πŸš€ #7

Workflow file for this run

name: AWS IAC
run-name: ${{ github.actor }} is testing out GitHub Actions πŸš€
on:
pull_request:
types: [opened, reopened, ready_for_review, synchronize]
defaults:
run:
working-directory: core-env/aws
permissions:
id-token: write
pull-requests: write
jobs:
core_aws:
outputs:
tofu-plan-aws: ${{ steps.plan_output.outputs.output }}
tofu-fmt-aws: ${{ steps.fmt_outcome.outputs.output }}
defaults:
run:
working-directory: core-env/aws
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@main # Or a specific version
with:
role-to-assume: arn:aws:iam::218691292270:role/sedemo-iac-pipeline-role
aws-region: us-west-2
- name: Verify AWS identity
run: |
# Your commands that require AWS credentials
aws sts get-caller-identity
- name: Verify Tofu
uses: opentofu/setup-opentofu@v1
- name: OpenTofu fmt
id: fmt
run: tofu fmt -check
continue-on-error: true
- name: fmt output
id: fmt_outcome
run: echo "output=${{steps.fmt.outcome}}" >> "$GITHUB_OUTPUT"
- run: tofu init
- id: plan
run: tofu plan -no-color
continue-on-error: true
- name: plan output
id: plan_output
run: echo "output=${{steps.plan.outputs.stdout}}" >> "$GITHUB_OUTPUT"
eks_primary:
needs: core_aws
outputs:
tofu-plan-aws: ${{ steps.plan_output.outputs.output }}
tofu-fmt-aws: ${{ steps.fmt_outcome.outputs.output }}
defaults:
run:
working-directory: core-env/eks-clusters
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@main # Or a specific version
with:
role-to-assume: arn:aws:iam::218691292270:role/sedemo-iac-pipeline-role
aws-region: us-west-2
- name: Verify AWS identity
run: |
# Your commands that require AWS credentials
aws sts get-caller-identity
- name: Verify Tofu
uses: opentofu/setup-opentofu@v1
- name: OpenTofu fmt
id: fmt
run: tofu fmt -check
continue-on-error: true
- name: fmt output
id: fmt_outcome
run: echo "output=${{steps.fmt.outcome}}" >> "$GITHUB_OUTPUT"
- run: tofu init
- id: plan
run: tofu plan -no-color
continue-on-error: true
- name: plan output
id: plan_output
run: echo "output=${{steps.plan.outputs.stdout}}" >> "$GITHUB_OUTPUT"
pr_comment:
needs: eks_primary
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v6
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('OpenTofu Format and Style')
})
// 2. Prepare format of the comment
const output = `
#### OpenTofu Format and Style: AWS Core πŸ–Œ\`${{ needs.core_aws.outputs.fmt }}\`
#### OpenTofu Format and Style: EKS Primary Cluster πŸ–Œ\`${{ needs.eks_primary.outputs.fmt }}\`
#### OpenTofu Plan: AWS Core πŸ“–
<details><summary>Show Plan</summary>
\`\`\`\n
${{ needs.core_aws.outputs.plan }}
\`\`\`
</details>
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Workflow: \`${{ github.workflow }}\`*`;
// 3. 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
})
}