-
Notifications
You must be signed in to change notification settings - Fork 79
243 lines (201 loc) · 8.01 KB
/
generate-docs-for-dbt-core.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
238
239
240
241
242
243
# **what?**
# Generate the new index.html for dbt-core and more over all associated changelog files.
# Cleans up all changelog files once they are committed to dbt-core.
# **why?**
# Automate the process of generating the new index.html and bringing in changelog entries.
# **when?**
# This will run when called in manually. It may eventually be folded into the release process for dbt-core.
name: Generate Updated Docs for dbt-core
on:
workflow_dispatch:
inputs:
no_changelog:
description: 'No changelog expected (will error if changelog yaml is found)'
type: boolean
required: false
defaults:
run:
shell: bash
permissions:
contents: write # adds new commits
pull-requests: write # opens new PRs
jobs:
set_variables:
runs-on: ubuntu-latest
outputs:
branch_name: ${{ steps.set.outputs.BRANCH_NAME }}
index_artifact_name: ${{ steps.set.outputs.INDEX_ARTIFACT_NAME }}
changie_artifact_name: ${{ steps.set.outputs.CHANGIE_ARTIFACT_NAME }}
pr_title: ${{ steps.set.outputs.PR_TITLE }}
pr_body: ${{ steps.set.outputs.PR_BODY }}
steps:
- name: Set variables
id: set
run: |
echo "BRANCH_NAME=dbt-docs-release/$(date +%Y%m%d-%H%M%S)_$GITHUB_RUN_ID" >> $GITHUB_OUTPUT
echo "INDEX_ARTIFACT_NAME=index_file" >> $GITHUB_OUTPUT
echo "CHANGIE_ARTIFACT_NAME=changie_yamls" >> $GITHUB_OUTPUT
echo "PR_TITLE=Add most recent dbt-docs changes" >> $GITHUB_OUTPUT
echo "PR_BODY=Auto generated changes from generate-docs-for-dbt-core.yml workflow" >> $GITHUB_OUTPUT
- name: Print variables
id: print_variables
run: |
echo "no_changelog input ${{ inputs.no_changelog }}"
echo "Branch name: ${{ steps.set.outputs.BRANCH_NAME }}"
echo "Index Artifact Name: ${{ steps.set.outputs.INDEX_ARTIFACT_NAME }}"
echo "Changie Artifact Name: ${{ steps.set.outputs.CHANGIE_ARTIFACT_NAME }}"
echo "PR Title: ${{ steps.set.outputs.PR_TITLE }}"
echo "PR Body: ${{ steps.set.outputs.PR_BODY }}"
gather_changelogs:
needs: [set_variables]
runs-on: ubuntu-latest
steps:
- name: Checkout dbt-docs repo
uses: actions/checkout@v4
- name: upload changelog artifacts
id: retrieve_changelogs
uses: actions/upload-artifact@v4
with:
name: ${{ needs.set_variables.outputs.changie_artifact_name }}
path: |
.changes/unreleased/*.yaml
if-no-files-found: error
retention-days: 15
- name: Fail if no changelogs found, but were expected
if: steps.retrieve_changelogs.outcome == 'failure' && inputs.no_changelog == false
run: |
echo "Changelog yaml files were not found, but the no_changelog input was set to false"
exit 1
- name: Fail if changelogs are found, but none were expected
if: steps.retrieve_changelogs.outcome == 'success' && inputs.no_changelog == true
run: |
echo "Changelog yaml files were found, but the no_changelog input was set to true"
exit 1
build_index:
needs: [set_variables, gather_changelogs]
runs-on: ubuntu-latest
steps:
- name: Checkout dbt-docs repo
uses: actions/checkout@v4
- name: Update submodules
run: git submodule update --init --recursive
- name: Use Node.js v14.18.2
uses: actions/setup-node@v4
with:
node-version: 14.18.2
- name: Use Ruby v2.7.5
uses: ruby/setup-ruby@v1
with:
ruby-version: '2.7.5'
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- name: build the css files required for webpack
run: |
cd styles
bundle exec jekyll build
cd -
- name: Download the package and dependencies
run: npm install
- name: build the index.html file
run: npx webpack
- name: upload index.html artifact
uses: actions/upload-artifact@v4
with:
name: ${{ needs.set_variables.outputs.index_artifact_name }}
path: dist/index.html
if-no-files-found: error
retention-days: 15
commit_dbt_core:
needs: [set_variables, build_index]
runs-on: ubuntu-latest
steps:
- name: Check out dbt-core main branch
uses: actions/checkout@v4
with:
repository: dbt-labs/dbt-core
ref: main
token: ${{ secrets.FISHTOWN_BOT_PAT }}
- name: Create branch
run: |
git checkout -b ${{ needs.set_variables.outputs.branch_name }}
git push -u origin ${{ needs.set_variables.outputs.branch_name }}
- name: Print branch status
run: |
git status
- name: Download index artifact
uses: actions/download-artifact@v4
with:
name: ${{ needs.set_variables.outputs.index_artifact_name }}
path: "core/dbt/task/docs"
- name: Download changelog artifact(s)
uses: actions/download-artifact@v4
with:
name: ${{ needs.set_variables.outputs.changie_artifact_name }}
path: ".changes/unreleased"
- name: Print branch status
run: |
git status
# note that if nothing has changed with the repo, the index file won't be
# committed since there are no changes, even if there are changelogs.
- name: Commit & Push changes
run: |
git config user.name 'Github Build Bot'
git config user.email 'buildbot@fishtownanalytics.com'
git pull
git add .
git commit -m "Add new index.html and changelog yaml files from dbt-docs"
git push
- name: Create Pull Request
run: |
gh pr create --title "${{ needs.set_variables.outputs.pr_title }}" \
--body "${{ needs.set_variables.outputs.pr_body }}" \
--base main \
--head ${{ needs.set_variables.outputs.branch_name }} \
--label dbt-docs
env:
GITHUB_TOKEN: ${{ secrets.FISHTOWN_BOT_PAT }}
clean_up_changie:
needs: [set_variables, commit_dbt_core]
if: ${{ inputs.no_changelog }} == false
runs-on: ubuntu-latest
steps:
- name: Checkout dbt-docs repo
uses: actions/checkout@v4
with:
repository: dbt-labs/dbt-docs # redundant but calling it out for clarity
# if there are no changie files to delete the job fails because the PR has 0
# changes, so catch it here for clarity.
- name: Check for changed changie yaml files
id: changie_check
run: |
if [[ -z $(find ./.changes/unreleased -type f -name "*.yaml") ]]; then
echo "No changie yaml files to delete. This is unexpected."
exit 1
fi
- name: Create branch
run: |
git checkout -b ${{ needs.set_variables.outputs.branch_name }}
git push -u origin ${{ needs.set_variables.outputs.branch_name }}
- name: Check current branch
run: |
git status
- name: Remove changie yaml files
id: rm_yml
run: |
find ./.changes/unreleased -type f -name "*.yaml" -delete
- name: Commit & Push changes
run: |
git config user.name 'Github Build Bot'
git config user.email 'buildbot@fishtownanalytics.com'
git pull
git add .changes/unreleased
git commit -m "Delete changie files that were moved to dbt-core for release"
git push
- name: Create Pull Request
run: |
gh pr create --title "Remove moved changie yml files" \
--body "${{ needs.set_variables.outputs.pr_body }}" \
--base main \
--head ${{ needs.set_variables.outputs.branch_name }} \
--label "Skip Changelog"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}