-
Notifications
You must be signed in to change notification settings - Fork 7
63 lines (56 loc) · 2.93 KB
/
terraform-version-check.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
name: "Terraform version check"
on:
workflow_dispatch:
pull_request:
paths:
- "aws/**"
- "env/**"
- ".github/workflows/terraform-version-check.yml"
env:
ENV: staging
jobs:
terraform-version-check:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Get latest versions
id: latest
run: |
TERRAFORM_LATEST="$(curl https://api.github.com/repos/hashicorp/terraform/releases/latest | jq --raw-output '.tag_name' | cut -c 2-)"
TERRAGRUNT_LATEST="$(curl https://api.github.com/repos/gruntwork-io/terragrunt/releases/latest | jq --raw-output '.tag_name' | cut -c 2-)"
echo "terraform=${TERRAFORM_LATEST}" >> $GITHUB_OUTPUT
echo "terragrunt=${TERRAGRUNT_LATEST}" >> $GITHUB_OUTPUT
- name: Get used versions
id: used
run: |
pip install yq
TERRAFORM_USED="$(yq -r .env.TERRAFORM_VERSION .github/workflows/terragrunt-apply-${{ env.ENV }}.yml)"
TERRAGRUNT_USED="$(yq -r .env.TERRAGRUNT_VERSION .github/workflows/terragrunt-apply-${{ env.ENV }}.yml)"
echo "terraform=${TERRAFORM_USED}" >> $GITHUB_OUTPUT
echo "terragrunt=${TERRAGRUNT_USED}" >> $GITHUB_OUTPUT
- name: Delete previous comments
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { data: comments } = await github.rest.issues.listComments({...context.repo, issue_number: context.issue.number});
const comment = comments.find(comment => comment.user.type === "Bot" && comment.body.indexOf("Terrform update available") > -1);
if (comment) {
await github.rest.issues.deleteComment({...context.repo, comment_id: comment.id});
}
- name: Add version comment
if: steps.latest.outputs.terraform != steps.used.outputs.terraform || steps.latest.outputs.terragrunt != steps.used.outputs.terragrunt
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const tf = { used: "${{ steps.used.outputs.terraform }}", latest: "${{ steps.latest.outputs.terraform }}" };
const tg = { used: "${{ steps.used.outputs.terragrunt }}", latest: "${{ steps.latest.outputs.terragrunt }}" };
const terraform = tf.used !== tf.latest ? `\nTerraform: ${tf.latest} (using ${tf.used})` : "";
const terragrunt = tg.used !== tg.latest ? `\nTerragrunt: ${tg.latest} (using ${tg.used})` : "";
github.rest.issues.createComment({
...context.repo,
issue_number: context.issue.number,
body: `## ⚠ Terrform update available\n\`\`\`yaml${terraform}${terragrunt}\n\`\`\``
})