-
Notifications
You must be signed in to change notification settings - Fork 0
187 lines (159 loc) · 6.52 KB
/
lint-test-and-generate.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
183
184
185
186
187
name: lint-test-and-generate
on:
push:
branches:
- main
pull_request:
permissions:
contents: read
jobs:
golangci:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
with:
go-version: 1.19
- uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b # v3.2.0
- name: golangci-lint
uses: golangci/golangci-lint-action@5f1fec7010f6ae3b84ea4f7b2129beb8639b564f # v3.5.0
with:
version: v1.50.1
args: "--timeout=10m"
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b # v3.2.0
- uses: hashicorp/setup-terraform@633666f66e0061ca3b725c73b2ec20cd13a8fdd1 # v2.0.3
with:
terraform_version: 1.3.6
terraform_wrapper: false
- uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
with:
go-version: 1.19
cache: true
cache-dependency-path: go.sum
- name: install jsonnet-bundler
run: |
go install github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb@latest
- name: run tests
run: |
go test -v ./...
generate:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
needs:
- golangci
- test
outputs:
entries: ${{ steps.load-managed-cfg.outputs.entries }}
steps:
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
- uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v3.3.1
with:
go-version: 1.19
- name: setup jb packages for docsonnet steps
run: |
go install github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb@latest
jb install
mkdir generator-out
mv vendor generator-out/vendor
- name: run libgenerator with stored config
run: |
go run ./cmd/libgenerator \
gen --out "$(pwd)/generator-out" --config "$(pwd)/cfg/managed.json" --loglevel debug
- name: tar artifact
run: |
tar -czf generator-out.tar.gz ./generator-out
- name: create artifact
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
with:
name: generator-out
path: generator-out.tar.gz
# Set the contents of cfg/managed.json as a github output so that we can run a matrix job where a GitHub Action
# job runs for each entry in the config.
- id: load-managed-cfg
run: echo entries="$(cat "$(pwd)/cfg/managed.json" | jq -Mc .)" >> "$GITHUB_OUTPUT"
copy:
if: github.event_name == 'pull_request'
needs: generate
runs-on: ubuntu-latest
strategy:
matrix:
entry: ${{ fromJSON(needs.generate.outputs.entries) }}
steps:
- name: download generated code
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
with:
name: generator-out
- name: untar generated code
run: |
tar -xvf ./generator-out.tar.gz
- uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
with:
go-version: 1.19
- name: generator docs with docsonnet
run: |
# TODO: Replace with jsonnet-libs when relevant PRs are merged
go install github.com/yorinasub17/docsonnet@installable
docsonnet \
-J "$(pwd)/generator-out/vendor" \
-o "$(pwd)/generator-out/${{ matrix.entry.repo }}/docs/${{ matrix.entry.subdir }}" \
"$(pwd)/generator-out/${{ matrix.entry.repo }}/${{ matrix.entry.subdir }}/main.libsonnet"
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
with:
token: ${{ secrets.TFLIBSONNET_CI_GITHUB_TOKEN }}
repository: tf-libsonnet/${{ matrix.entry.repo }}
path: ${{ matrix.entry.repo }}
fetch-depth: 0
- name: switch to pr branch or create
run: |
cd ${{ matrix.entry.repo }}
git switch "$PR_BRANCH" || git switch -c "$PR_BRANCH"
env:
PR_BRANCH: pr-${{ github.event.pull_request.number }}
- name: clear tracked files before generating (to support deletes)
run: |
rm -vr ${{ matrix.entry.repo }}/docs/${{ matrix.entry.subdir }} || true
rm -vr ${{ matrix.entry.repo }}/${{ matrix.entry.subdir }} || true
- name: copy generated code and update permissions
run: |
rsync -va ./generator-out/${{ matrix.entry.repo }}/ ${{ matrix.entry.repo }}
tree ${{ matrix.entry.repo }}
cd ${{ matrix.entry.repo }}
git status
- name: import gpg signing key
uses: crazy-max/ghaction-import-gpg@72b6676b71ab476b77e676928516f6982eef7a41 # v5.3.0
with:
gpg_private_key: ${{ secrets.TFLIBSONNET_CI_GPG_KEY }}
passphrase: ${{ secrets.TFLIBSONNET_CI_GPG_PASSPHRASE }}
git_config_global: true
git_user_signingkey: true
git_commit_gpgsign: true
git_committer_name: "tflibsonnet-ci"
git_committer_email: "[email protected]"
- name: commit generated code to new branch if files changed
id: auto-commit-action
uses: stefanzweifel/git-auto-commit-action@3ea6ae190baf489ba007f7c92608f33ce20ef04a # v4.16.0
with:
repository: ${{ matrix.entry.repo }}
branch: pr-${{ github.event.pull_request.number }}
commit_message: "Generate libsonnet source from libgenerator PR ${{ github.event.pull_request.html_url }}"
commit_options: "-S -s"
commit_user_name: "tflibsonnet-ci"
commit_user_email: "[email protected]"
- name: open PR if changes were made
if: steps.auto-commit-action.outputs.changes_detected == 'true'
run: |
cd ${{ matrix.entry.repo }}
if [[ -z "$(gh pr view "$PR_BRANCH" --json state -q 'select(.state == "OPEN")')" ]]; then
gh pr create \
-t "$PR_TITLE" \
-b "$(echo -e "_(original: $PR_HTML_URL)_\n\n$PR_BODY")" \
-B main -H "$PR_BRANCH"
fi
env:
PR_BRANCH: pr-${{ github.event.pull_request.number }}
PR_TITLE: ${{ github.event.pull_request.title }}
PR_HTML_URL: ${{ github.event.pull_request.html_url }}
PR_BODY: ${{ github.event.pull_request.body }}
GITHUB_TOKEN: ${{ secrets.TFLIBSONNET_CI_GITHUB_TOKEN }}