-
Notifications
You must be signed in to change notification settings - Fork 458
237 lines (216 loc) · 8.26 KB
/
registry-docs-pr-based.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
on:
workflow_call:
inputs:
repository:
description: "Repository to convert, e.g. 'terraform-providers/terraform-provider-aws'"
required: false
default: "${{ github.repository }}"
type: string
branch:
description: "Branch to convert, e.g. 'main'"
required: false
default: "main"
type: string
providerFqn:
description: "Provider FQN to convert, e.g. hashicorp/aws"
required: true
type: string
maxRunners:
description: "Maximum number of parallel runners to use"
required: false
default: 10
type: number
gitUser:
description: "Git user to commit as"
required: false
default: "team-tf-cdk"
type: string
gitEmail:
description: "Git email to commit as"
required: false
default: "[email protected]"
type: string
parallelFileConversions:
description: "Number of files to convert in parallel"
required: false
default: 1
type: number
parallelConversionsPerDocument:
description: "Number of conversions to run in parallel per document"
required: false
default: 3
type: number
languages:
description: "Languages to convert to as comma-separated list, e.g. 'typescript,python'"
required: false
default: "typescript,python"
type: string
files:
description: "Files to convert as comma-separated glob list, e.g. '*/ec2_*.html.markdown,*/s3_*.html.markdown'"
required: false
default: "**/*"
type: string
cdktfRegistryDocsVersion:
description: "Version of cdktf-registry-docs to use"
required: false
default: "1.27.0"
type: string
secrets:
GH_PR_TOKEN:
description: "GitHub token to create PRs with"
required: true
outputs:
prUrl:
description: "URL of the created PR"
value: ${{ jobs.cdktfDocsCreatePR.outputs.prUrl }}
name: CDKTF Provider Documentation
jobs:
cdktfDocsCleanupBranches:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
repository: ${{ inputs.repository }}
ref: ${{ inputs.branch }}
token: ${{ secrets.GH_PR_TOKEN }}
fetch-depth: 0 # complete checkout
# Delete all branches that start with d-cdktf-docs-
- run: |
BRANCHES_TO_DELETE=$(git branch -r | grep -Eo 'origin/d-cdktf-docs-[0-9]+-[0-9]+') || (echo "no branches to clean up" && exit 0)
for branch in $BRANCHES_TO_DELETE; do
branch_without_remote=${branch#origin/}
git push origin --delete $branch_without_remote
done
cdktfDocsSetupBranch:
runs-on: ubuntu-latest
needs:
- cdktfDocsCleanupBranches
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
repository: ${{ inputs.repository }}
ref: ${{ inputs.branch }}
token: ${{ secrets.GH_PR_TOKEN }}
- run: |
git config --global user.email "${{ inputs.gitEmail }}"
git config --global user.name "${{ inputs.gitUser }}"
git checkout -b d-cdktf-docs-${{ github.run_id }}-${{ github.run_number }}
git push origin d-cdktf-docs-${{ github.run_id }}-${{ github.run_number }}
cdktfDocsMatrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
container:
image: docker.mirror.hashicorp.services/hashicorp/jsii-terraform
env:
CHECKPOINT_DISABLE: "1"
timeout-minutes: 120
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
repository: ${{ inputs.repository }}
ref: ${{ inputs.branch }}
token: ${{ secrets.GH_PR_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: "20.x"
- name: Install cdktf-registry-docs
run: npm install -g cdktf-registry-docs@${{ inputs.cdktfRegistryDocsVersion }}
- name: Create plugin cache
run: |
mkdir -p ${{ steps.global-cache-dir-path.outputs.dir }}/terraform-plugins
- id: set-matrix
run: |
matrix=$(cdktf-registry-docs ci-matrix --max-runners=${{ inputs.maxRunners }} --files='${{ inputs.files }}' .)
echo "matrix=$matrix" >> $GITHUB_OUTPUT
env:
TF_PLUGIN_CACHE_DIR: ${{ steps.global-cache-dir-path.outputs.dir }}/terraform-plugins
cdktfDocsConvert:
needs:
- cdktfDocsSetupBranch
- cdktfDocsMatrix
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
files: ${{fromJSON(needs.cdktfDocsMatrix.outputs.matrix)}}
container:
image: docker.mirror.hashicorp.services/hashicorp/jsii-terraform
env:
CHECKPOINT_DISABLE: "1"
timeout-minutes: 360
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
repository: ${{ inputs.repository }}
ref: ${{ inputs.branch }}
token: ${{ secrets.GH_PR_TOKEN }}
- run: |
git config --global user.email "${{ inputs.gitEmail }}"
git config --global user.name "${{ inputs.gitUser }}"
git config --global --add safe.directory $(pwd)
- name: Setup Node.js
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: "20.x"
- name: Install cdktf-registry-docs
run: npm install -g cdktf-registry-docs@${{ inputs.cdktfRegistryDocsVersion }}
- name: Run conversion
run: |
cdktf-registry-docs convert \
--files='${{ matrix.files }}' \
--languages='${{inputs.languages}}' \
--parallel-file-conversions=${{ inputs.parallelFileConversions }} \
--parallel-conversions-per-document=${{ inputs.parallelConversionsPerDocument }}\
--provider-from-registry="${{ inputs.providerFqn }}" \
.
env:
TF_PLUGIN_CACHE_DIR: ${{ steps.global-cache-dir-path.outputs.dir }}/terraform-plugins
- name: Find changes
id: changes
run: |-
git add .
git diff --staged --patch --exit-code > /dev/null || echo "changes_happened=true" >> $GITHUB_OUTPUT
- name: Commit changes
if: steps.changes.outputs.changes_happened
run: |
git checkout -b d-cdktf-docs-${{ github.run_id }}-${{ github.run_number }}
git add .
git commit -m "cdktf: update ${{ matrix.files }}"
git push origin d-cdktf-docs-${{ github.run_id }}-${{ github.run_number }}
cdktfDocsCreatePR:
needs:
- cdktfDocsConvert
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
repository: ${{ inputs.repository }}
fetch-depth: 0 # complete checkout
- name: Create Pull Request
run: |
set -ex
git config --global user.email "${{ inputs.gitEmail }}"
git config --global user.name "${{ inputs.gitUser }}"
git fetch
git checkout d-cdktf-docs-${{ github.run_id }}-${{ github.run_number }}
git pull origin d-cdktf-docs-${{ github.run_id }}-${{ github.run_number }} --rebase
HAS_COMMITS=$(git log --oneline origin/main..HEAD | wc -l)
if [ $HAS_COMMITS -eq 0 ]; then
echo "No changes to commit"
exit 0
fi
TITLE="cdktf: update documentation"
# Close existing PRs with the same title
for i in $(gh pr list --state open --search "$TITLE" --json number | jq -r '.[].number'); do
gh pr close $i -d -c='Superseded by newer PR.'
done
gh pr create \
--title="$TITLE" \
--body "This PR was automatically created by the [cdktf-docs-conversion workflow](https://github.com/hashicorp/terraform-cdk/blob/main/.github/workflows/cdktf-provider-docs-rollout.yml)." \
--base main \
--repo ${{ inputs.repository }} \
-f
env:
GITHUB_TOKEN: ${{ secrets.GH_PR_TOKEN }}