-
Notifications
You must be signed in to change notification settings - Fork 0
76 lines (64 loc) · 2.11 KB
/
terraform.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
64
65
66
67
68
69
70
71
72
73
74
75
76
---
name: Terraform
on:
pull_request:
paths:
- "**.tf"
- ".terraform-version"
pull_request_target:
paths:
- "**.tf"
jobs:
terraform:
name: Terraform
# If the PR is coming from a fork (pull_request_target), ensure it's opened by "dependabot[bot]".
# Otherwise, clone it normally.
if: |
(github.event_name == 'pull_request_target' && github.actor == 'dependabot[bot]') ||
(github.event_name != 'pull_request_target' && github.actor != 'dependabot[bot]')
runs-on: ubuntu-22.04
defaults:
run:
shell: bash
steps:
- name: Checkout
if: ${{ github.event_name != 'pull_request_target' }}
uses: actions/[email protected]
- name: Checkout
if: ${{ github.event_name == 'pull_request_target' }}
uses: actions/[email protected]
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Get Terraform version
id: terraform_version
uses: juliangruber/[email protected]
with:
path: ./.terraform-version
- name: Setup Terraform
uses: hashicorp/[email protected]
with:
terraform_version: ${{ steps.terraform_version.outputs.content }}
- name: Terraform Format
id: fmt
run: terraform fmt -recursive -check
- name: Terraform Init
id: init
run: terraform init -upgrade
- name: Terraform Validate
id: validate
run: terraform validate -no-color
- name: Comment on PR
uses: actions/[email protected]
if: always()
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const output = `#### Terraform Format and Style \`${{ steps.fmt.outcome }}\`
#### Terraform Initialization \`${{ steps.init.outcome }}\`
#### Terraform Validation ${{ steps.validate.outputs.stdout }}`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})