-
Notifications
You must be signed in to change notification settings - Fork 96
182 lines (148 loc) · 5.34 KB
/
preview.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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# Copyright 2023 Terramate GmbH
# SPDX-License-Identifier: MPL-2.0
name: preview
on:
pull_request:
branches:
- main
jobs:
preview:
name: Changed Terramate stacks
runs-on: ${{ matrix.os }}
permissions:
id-token: write
contents: read
pull-requests: write
strategy:
matrix:
os: ["ubuntu-20.04", "macos-12", "macos-13"]
go: ["1.22"]
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
fetch-depth: 0
- uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}
### Create Pull Request comment
- name: Prepare pull request preview comment
if: github.event.pull_request
uses: marocchino/sticky-pull-request-comment@v2
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
header: preview
message: |
## Preview of Project changes in ${{ github.event.pull_request.head.sha }}
:warning: preview is being created... please stand by!
### Install tooling
- name: Install Terramate
uses: terramate-io/terramate-action@i4k-fix-macos
# TODO(i4k): remove this once v0.5.0 is released.
- name: build Terramate
shell: bash
run: make build
### Linting
- name: Check Terramate formatting
shell: bash
run: terramate fmt --check
### Check for changed stacks
- name: List changed stacks
shell: bash
id: list
run: terramate list --changed
- name: checking go mod tidyness
shell: bash
if: steps.list.outputs.stdout
run: make mod/check
- name: linting code
shell: bash
if: steps.list.outputs.stdout
run: make lint
- name: checking license on source code
shell: bash
if: steps.list.outputs.stdout
run: make license/check
### Run the terramate preview script
- name: check cloud info
shell: bash
if: steps.list.outputs.stdout
run: terramate run --tags golang --no-recursive -- terramate cloud info || true
env:
TMC_API_HOST: api.stg.terramate.io
- name: Golang test preview
shell: bash
if: steps.list.outputs.stdout
run: |
echo >preview_url.txt "https://cloud.stg.terramate.io/o/test/review-requests"
./bin/terramate script run --parallel=10 --tags golang --changed -- test preview
env:
TMC_API_HOST: api.stg.terramate.io
GITHUB_TOKEN: ${{ github.token }}
### Update Pull Request comment
- name: Generate preview details
shell: bash
if: steps.list.outputs.stdout
id: comment
run: |
echo >>pr-comment.txt "## Preview of Terramate changes in ${{ github.event.pull_request.head.sha }}"
echo >>pr-comment.txt
echo >>pr-comment.txt "[:mag: View Details on Terramate Cloud]($(cat preview_url.txt))"
echo >>pr-comment.txt
echo >>pr-comment.txt "### Changed Stacks"
echo >>pr-comment.txt
echo >>pr-comment.txt '```bash'
echo >>pr-comment.txt "${{ steps.list.outputs.stdout }}"
echo >>pr-comment.txt '```'
cat pr-comment.txt >>$GITHUB_STEP_SUMMARY
- name: Generate preview when no stacks changed
shell: bash
if: success() && !steps.list.outputs.stdout
run: |
echo >>pr-comment.txt "## Preview of Terramate changes in ${{ github.event.pull_request.head.sha }}"
echo >>pr-comment.txt
echo >>pr-comment.txt "### Changed Stacks"
echo >>pr-comment.txt
echo >>pr-comment.txt 'No changed stacks, no detailed preview will be generated.'
cat pr-comment.txt >>$GITHUB_STEP_SUMMARY
- name: Generate preview when things failed
shell: bash
if: failure()
run: |
echo >>pr-comment.txt "## Preview of Terraform changes in ${{ github.event.pull_request.head.sha }}"
echo >>pr-comment.txt
echo >>pr-comment.txt "[:mag: View Details on Terramate Cloud]($(cat preview_url.txt))"
echo >>pr-comment.txt
echo >>pr-comment.txt "### Changed Stacks"
echo >>pr-comment.txt
echo >>pr-comment.txt '```bash'
echo >>pr-comment.txt "${{ steps.list.outputs.stdout }}"
echo >>pr-comment.txt '```'
echo >>pr-comment.txt ':boom: Generating preview failed. Please see details in Actions output.'
cat pr-comment.txt >>$GITHUB_STEP_SUMMARY
- name: Publish generated preview as GitHub commnent
uses: marocchino/sticky-pull-request-comment@v2
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
header: preview
path: pr-comment.txt
release_dry_run:
name: Release Dry Run
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
with:
ref: ${{github.event.pull_request.head.ref}}
repository: ${{github.event.pull_request.head.repo.full_name}}
fetch-depth: 0
- uses: actions/setup-go@v5
with:
go-version: '1.21'
- name: release dry run
run: make release/dry-run
required_checks:
needs:
- preview
runs-on: ubuntu-20.04
steps:
- uses: Kesin11/actions-timeline@v1