-
Notifications
You must be signed in to change notification settings - Fork 8
246 lines (192 loc) · 8.12 KB
/
pull_metadata.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
244
245
# This is a workflow to pull all of the metadata from all of the modules into a single file
# each time something is merged to main, this workflow will run and rebuild the metadata file.
name: Process Module Metadata
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches: "main" #CHANGE TO MAIN BEFORE MERGING
paths-ignore:
- 'assets/**'
- '_for_authors/**'
- '_module_templates/**'
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
run_script:
name: Pull module metadata
runs-on: ubuntu-latest
# Map a step output to a job output
# outputs:
# changes: ${{ steps.check_if_changed.outputs.changes }}
steps:
- uses: actions/checkout@v4
# Process all the metadata using the script for that
- name: Process Metadata
run: |
bash .github/scripts/process_metadata.sh
- name: Upload json file as an artifact
uses: actions/upload-artifact@v4
with:
name: json_artifact
path: module_data.json
check_for_changes:
name: Has metadata changed?
runs-on: ubuntu-latest
needs: run_script
# Map a step output to a job output
outputs:
changes: ${{ steps.check_if_changed.outputs.changes }}
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: json_artifact
# Check if processing the data has changed the python file at all
- name: Check if anything changed
id: check_if_changed
run: |
wget https://raw.githubusercontent.com/arcus/education_modules/metadata_workflow/assets/metadata/module_data.json -O current_data_file.txt
wc current_data_file.txt
changes=$(diff module_data.json current_data_file.txt | wc -l)
echo there are $changes changed lines
changes=$([ $changes -gt 0 ] && echo "true" || echo "false")
echo the changes variable is now $changes
echo "changes=$changes" >> "$GITHUB_OUTPUT"
# This message is for me to check that things ran correctly even if nothing actually updated
nothing_to_update_message:
name: No - nothing to update
runs-on: ubuntu-latest
needs: check_for_changes
if: needs.check_for_changes.outputs.changes != 'true'
steps:
- env:
OUTPUT3: ${{needs.check_for_changes.outputs.changes}}
name: Nothing was committed
run: echo "Nothing was committed because the any_change variable was $OUTPUT3"
# This message is for me to check that things ran correctly even if nothing actually updated
metadata_changed_message:
name: Yes - updates needed
runs-on: ubuntu-latest
needs: check_for_changes
if: needs.check_for_changes.outputs.changes == 'true'
steps:
- env:
OUTPUT3: ${{needs.check_for_changes.outputs.changes}}
name: Metadata has changed
run: echo "The any_change variable was $OUTPUT3 so now the changes need to be propagated"
# If changes were made to the json file, push those changes to the metadata_workflow branch
update_metadata_workflow_branch:
name: Module repo - Push to branch metadata_workflow
runs-on: ubuntu-latest
needs: metadata_changed_message
steps:
- env:
OUTPUT3: ${{needs.run_script.outputs.changes}}
run: echo "The changes variable is $OUTPUT3"
- uses: actions/checkout@v4
- name: Download json artifact
uses: actions/download-artifact@v4
with:
name: json_artifact
- name: Check that artifacts downloaded
run: |
wc module_data.json
- name: Commit newly updated files
run: |
git config --local user.name actions-user
git config --local user.email "actions@github.com"
git fetch
git checkout metadata_workflow
mv -f module_data.json assets/metadata/
git add assets/metadata/module_data.json
git commit -am "update metadata records"
git push origin metadata_workflow
# The module_discovery repository automatically checks weekly to see if the module data has changed, but a message here informs users how to manually run that workflow.
update_module_discovery_repository:
name: App - Sun. cron job or manual update
runs-on: ubuntu-latest
needs: metadata_changed_message
steps:
- env:
OUTPUT3: ${{needs.run_script.outputs.changes}}
run: echo "The changes variable is $OUTPUT3"
- name: Print module_discovery instructions
run: |
echo "The module_discovery repository will automatically update on Sunday morning. If you have changed metadata that needs to be updated there immediately, please manually activate that workflow at https://github.com/arcus/module_discovery/actions/workflows/update_module_data.yml"
# If the metadata changed, generate the list of modules for arcus.github.io/education_modules
generate_webpage_markdown:
name: Website - Generate page
runs-on: ubuntu-latest
needs: metadata_changed_message
steps:
- uses: actions/checkout@v4
- name: Build webpage markdown file
run: |
bash .github/scripts/public_list_of_modules.sh
- name: Upload webpage file as an artifact
uses: actions/upload-artifact@v4
with:
name: webpage_artifact
path: new_list_of_modules.md
# It is possible for the metadata to change without any of the things displayed on the public facing website actually needing to be updated.
check_list_of_modules_for_changes:
name: Website - Did it change?
runs-on: ubuntu-latest
needs: generate_webpage_markdown
# Map a step output to a job output
outputs:
changes: ${{ steps.check_if_website_changed.outputs.changes }}
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: webpage_artifact
# Check if processing the data has changed the webpage file at all
- name: Check if anything changed
id: check_if_website_changed
run: |
wget https://raw.githubusercontent.com/arcus/education_modules/gh-pages/docs/list_of_modules.md -O current_webpage.txt
wc current_webpage.txt
changes=$(diff new_list_of_modules.md current_webpage.txt | wc -l)
echo there are $changes changed lines
changes=$([ $changes -gt 0 ] && echo "true" || echo "false")
echo the changes variable is now $changes
echo "changes=$changes" >> "$GITHUB_OUTPUT"
# Maybe the public facing website doesn't need updates
no_update_to_gh-pages:
name: Website - No changes
runs-on: ubuntu-latest
needs: check_list_of_modules_for_changes
if: needs.check_list_of_modules_for_changes.outputs.changes != 'true'
steps:
- env:
OUTPUT3: ${{needs.check_list_of_modules_for_changes.outputs.changes}}
name: Nothing was committed
run: echo "Nothing was committed because the any_change variable was $OUTPUT3"
# The public facing website does need updates.
update_gh-pages:
name: Update website
runs-on: ubuntu-latest
needs: check_list_of_modules_for_changes
if: needs.check_list_of_modules_for_changes.outputs.changes == 'true'
steps:
- uses: actions/checkout@v4
- name: Download webpage artifact
uses: actions/download-artifact@v4
with:
name: webpage_artifact
- name: Check that artifacts downloaded
run: |
wc new_list_of_modules.md
- name: Commit newly updated file
run: |
git config --local user.name actions-user
git config --local user.email "actions@github.com"
git fetch
git checkout gh-pages
mv -f new_list_of_modules.md docs/list_of_modules.md
git add docs/list_of_modules.md
git commit -am "update webpage records"
git push origin gh-pages