Added the automation code #8
Workflow file for this run
This file contains 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
name: CI | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
jobs: | |
validate-helm: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Setup Helm | |
uses: azure/setup-helm@v1 | |
with: | |
version: v3.8.0 | |
- name: Validate Helm charts | |
run: | | |
helm lint helm-charts/redis | |
helm lint helm-charts/rollouts-demo | |
terraform-plan: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Setup Terraform | |
uses: hashicorp/setup-terraform@v2 | |
with: | |
terraform_version: 1.0.0 | |
- name: Terraform Init | |
run: terraform init | |
- name: Terraform Validate | |
run: terraform validate | |
- name: Terraform Plan | |
id: plan | |
run: terraform plan -no-color -out=tfplan | |
continue-on-error: true | |
- name: Show Terraform Plan | |
id: show | |
run: | | |
terraform show -json tfplan > tfplan.json | |
cat tfplan.json | |
- name: Debug JSON Output | |
run: | | |
echo "Content of tfplan.json:" | |
cat tfplan.json | |
- name: Format Terraform Plan Output | |
id: format | |
run: | | |
echo "### Terraform Plan" > plan.md | |
echo '```' >> plan.md | |
cat tfplan.json | jq -r '.resource_changes[] | select(.change.actions | contains(["create","update","delete"])) | [.type, .name, .change.actions[]] | @tsv' >> plan.md | |
echo '```' >> plan.md | |
env: | |
PR_NUMBER: ${{ github.event.pull_request.number }} | |
- name: Comment PR with Terraform Plan | |
if: github.event_name == 'pull_request' | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const fs = require('fs'); | |
const plan = fs.readFileSync('plan.md', 'utf8'); | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: plan | |
}); |