Skip to content

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

eddiewebb is testing out GitHub Actions πŸš€

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

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]
permissions:
id-token: write
pull-requests: write
jobs:
# core_aws:
# outputs:
# plan: ${{ steps.plan_outcome.outputs.output }}
# fmt: ${{ 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 > /tmp/fmt.out
# 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 > /tmp/plan.out
# continue-on-error: true
# - name: plan output
# id: plan_outcome
# run: echo "output=${{steps.plan.outcome}}" >> "$GITHUB_OUTPUT"
# - name: Upload plan
# uses: actions/upload-artifact@v4
# with:
# name: output-aws
# path: /tmp/*.out
# eks_primary:
# needs: core_aws
# outputs:
# plan: ${{ steps.plan_output.outputs.output }}
# fmt: ${{ 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 > /tmp/fmt.out
# 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 > /tmp/plan.out
# continue-on-error: true
# - name: plan output
# id: plan_outcome
# run: echo "output=${{steps.plan.outcome}}" >> "$GITHUB_OUTPUT"
# - name: Upload plan
# uses: actions/upload-artifact@v4
# with:
# name: output-eks
# path: /tmp/*.out
pr_comment:
# needs:
# - eks_primary
# - core_aws
runs-on: ubuntu-latest
steps:
# - name: Download artifact
# uses: actions/download-artifact@v4
- name: Display structure of downloaded files
run: |
mkdir output-aws
mkdir output-eks
echo "this is file content" >> output-aws/plan.out
echo "this is file content" >> output-eks/plan.out
ls -R .
- 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 awsCorePlan = fs.readFileSync('output-aws/plan.out', 'utf8');
const eksPrimaryPlan = fs.readFileSync('output-eks/plan.out', 'utf8');
const output = `
### AWS Core
#### OpenTofu Format and Style πŸ–Œ\`${{ needs.core_aws.outputs.fmt }}\`
#### OpenTofu Plan πŸ“–
<details><summary>Show Plan</summary>
\`\`\`\n
${awsCorePlan}
${{ needs.core_aws.outputs.plan }}
\`\`\`
</details>
### EKS Primary Cluster
#### 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
})
}