generated from kedacore/github-template
-
Notifications
You must be signed in to change notification settings - Fork 7
140 lines (112 loc) · 3.87 KB
/
pr-validation.yaml
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
name: 'Validate PR'
on:
- pull_request_target
concurrency: terraform
permissions:
id-token: write
contents: read
pull-requests: read
jobs:
terraform:
name: 'Terraform'
runs-on: ubuntu-latest
env:
ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
ARM_USE_OIDC: true
GITHUB_TOKEN: ${{ secrets.GH_AUTOMATION_PAT }}
GITHUB_OWNER: kedacore
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Checkout Pull Request
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
id: checkout
run: |
gh pr checkout ${{ github.event.number }}
- name: Log into Azure using OIDC
uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Log into AWS using OIDC
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
aws-region: eu-west-2
- name: Log into GCP using OIDC
uses: google-github-actions/auth@v1
with:
workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }}
- name: Setup Terraform
uses: hashicorp/[email protected]
- name: Setup TFLint
uses: terraform-linters/setup-tflint@v3
- name: Terraform Format
id: fmt
run: terraform fmt -recursive -check
continue-on-error: true
working-directory: terraform
- name: Init TFLint
run: tflint --init
working-directory: terraform
- name: Run TFLint
run: tflint -f compact
working-directory: terraform
- name: Terraform Init
id: init
run: |
terraform init \
-backend-config=storage_account_name=${{ secrets.BACKEND_STORAGE_ACCOUNT_NAME}} \
-backend-config=container_name=${{ secrets.BACKEND_STORAGE_CONTAINER_NAME}} \
-backend-config=resource_group_name=${{ secrets.BACKEND_STORAGE_RESOURCE_GROUP_NAME}} \
-backend-config=subscription_id="$ARM_SUBSCRIPTION_ID"
working-directory: terraform
- name: Terraform Validate
id: validate
run: terraform validate -no-color
working-directory: terraform
- name: Terraform Plan
id: plan
run: terraform plan -no-color -input=false
continue-on-error: true
working-directory: terraform
- name: Create the plan summary
uses: actions/github-script@v6
if: always()
id: summary
env:
PLAN: '${{ steps.plan.outputs.stdout }}'
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
// 1. Prep the output
const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\`
#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
#### Terraform Validation 🤖\`${{ steps.validate.outcome }}\`
<details><summary>Validation Output</summary>
\`\`\`\n
${{ steps.validate.outputs.stdout }}
\`\`\`
</details>
#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
<details><summary>Show Plan</summary>
\`\`\`\n
${process.env.PLAN}
\`\`\`
</details>
*Pusher: @${{ github.actor }}*`;
// 2. Set the output variable
const fs = require('fs');
fs.writeFileSync('summary.md', output);
core.setOutput('summary', output);
- name: Write the step summary
if: always()
run: cat summary.md >> $GITHUB_STEP_SUMMARY
- name: Terraform Plan Status
if: steps.plan.outcome == 'failure'
run: exit 1