-
Notifications
You must be signed in to change notification settings - Fork 10
215 lines (185 loc) · 7.99 KB
/
mirror.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
name: Mirror to AWB
# Triggers the workflow on push events but only for the prod branch.
on:
pull_request:
types:
- closed
paths:
- 'instructions/**'
jobs:
matrixProd:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrixProd }}
steps:
# Any prerequisite steps
- uses: actions/checkout@master
- id: set-matrix
run: |
TASKS=$(echo $(cat $GITHUB_WORKSPACE/.github/workflows/mirror.json))
TASKS="${TASKS//'%'/'%25'}"
TASKS="${TASKS//$'\n'/'%0A'}"
TASKS="${TASKS//$'\r'/'%0D'}"
echo "matrixProd=$TASKS" >> $GITHUB_OUTPUT
matrixStaging:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrixStaging }}
steps:
# Any prerequisite steps
- uses: actions/checkout@master
- id: set-matrix
run: |
TASKS=$(echo $(cat $GITHUB_WORKSPACE/.github/workflows/StagingMirror.json))
TASKS="${TASKS//'%'/'%25'}"
TASKS="${TASKS//$'\n'/'%0A'}"
TASKS="${TASKS//$'\r'/'%0D'}"
echo "matrixStaging=$TASKS" >> $GITHUB_OUTPUT
singleMergedToProd:
name: Check if PR was a single Guide merged to Prod
if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'prod' && contains( github.event.pull_request.title,'Change to cloud-hosted')
runs-on: ubuntu-latest
steps:
- name: Upload guide name
run: |
echo The PR was merged
echo ${{ github.event.pull_request.title }} | sed 's/.* Change to //' > guide_name.txt
- uses: actions/upload-artifact@v4
with:
name: guide_name
path: guide_name.txt
deployProd:
needs: [singleMergedToProd, matrixProd]
# name: Start Mirror Containers for single Guide for Prod
continue-on-error: true
runs-on: ubuntu-latest
strategy:
matrix:
repo: ${{fromJson(needs.matrixProd.outputs.matrix)}}
steps:
- uses: actions/download-artifact@v4
with:
name: guide_name
- run: |
echo "GUIDENAME=$(cat guide_name.txt)" >> $GITHUB_ENV
# Any prerequisite steps
- uses: actions/checkout@master
- name: Check Files
run: |
if [ "${{ env.GUIDENAME }}" = "${{matrix.repo.github}}" ]; then
echo "Mirroring "${{ env.GUIDENAME }}" to AuthorWorkbench";
echo "awb url: https://author.skills.network/quicklabs/${{matrix.repo.quicklab_id}}/labs/${{matrix.repo.lab_id}}";
else
echo "Skipping "${{matrix.repo.github}}"";
exit 1;
fi
- name: Mirror to AWB
env:
LAB_ID: ${{ matrix.repo.lab_id }}
OAUTH_TOKEN: ${{ secrets.AWB_OAUTH_TOKEN }}
FILE_PATH: instructions/${{ matrix.repo.github }}/instructions.md
PUBLISH: true
run: |
chmod +x ${{ github.workspace }}/.github/workflows/deploy_guide.sh
${{ github.workspace }}/.github/workflows/deploy_guide.sh $LAB_ID $OAUTH_TOKEN $FILE_PATH "$(git log -1 --pretty=format:"%s" -- $FILE_PATH)" $PUBLISH "https://author.skills.network"
deployAllToProd:
needs: matrixProd
# name: Start Mirror Containers for all Guides for Prod
if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'prod' && contains( github.event.pull_request.title,'Change to multiple Guides')
continue-on-error: true
runs-on: ubuntu-latest
strategy:
matrix: # Uses an array of Json variables to pass the repo names.
# The names differ between Github and Gitlab so this is necessary.
# Add new cloud-hosted-guides here to add them to the mirror process.
# i.e. {"github":"new-lab-github-url","gitlab":"new-lab-gitlab-url"}
repo: ${{fromJson(needs.matrixProd.outputs.matrix)}}
steps:
# Any prerequisite steps
- uses: actions/checkout@master
- name: Mirror to AWB
env:
LAB_ID: ${{ matrix.repo.lab_id }}
OAUTH_TOKEN: ${{ secrets.AWB_OAUTH_TOKEN }}
FILE_PATH: instructions/${{ matrix.repo.github }}/instructions.md
PUBLISH: true
run: |
chmod +x ${{ github.workspace }}/.github/workflows/deploy_guide.sh
${{ github.workspace }}/.github/workflows/deploy_guide.sh $LAB_ID $OAUTH_TOKEN $FILE_PATH "$(git log -1 --pretty=format:"%s" -- $FILE_PATH)" $PUBLISH "https://author.skills.network"
singleMergedToStaging:
name: Check if PR was a single Guide merged to Staging
if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'staging' && contains( github.event.pull_request.title,'Change to cloud-hosted')
runs-on: ubuntu-latest
steps:
- name: Upload guide name
run: |
echo The PR was merged
# echo the PR title and trim only the guide name for example "To Prod: Change to cloud-hosted-guide-jakarta-websocket" = "cloud-hosted-guide-jakarta-websocket"
echo ${{ github.event.pull_request.title }} | sed 's/.* Change to //' > guide_name.txt
- uses: actions/upload-artifact@v4
with:
name: guide_name
path: guide_name.txt
deployStaging:
needs: [singleMergedToStaging, matrixStaging]
# name: Start Mirror Containers for single Guide for Staging
continue-on-error: true
runs-on: ubuntu-latest
strategy:
matrix:
repo: ${{fromJson(needs.matrixStaging.outputs.matrix)}}
steps:
- uses: actions/download-artifact@v4
with:
name: guide_name
- run: |
echo "GUIDENAME=$(cat guide_name.txt)" >> $GITHUB_ENV
# Any prerequisite steps
- uses: actions/checkout@master
with:
ref: staging
- name: Check Files
run: |
if [ "${{ env.GUIDENAME }}" = "${{matrix.repo.github}}" ]; then
echo "Mirroring "${{ env.GUIDENAME }}" to AuthorWorkbench";
echo "awb url: https://author-workbench.skills.network/quicklabs/${{matrix.repo.quicklab_id}}/labs/${{matrix.repo.lab_id}}";
else
echo "Skipping "${{matrix.repo.github}}"";
exit 1;
fi
- name: Mirror to AWB
env:
LAB_ID: ${{ matrix.repo.lab_id }}
OAUTH_TOKEN: "${{ secrets.AWB_OAUTH_TOKEN }}"
PUBLISH: false
FILE_PATH: "instructions/${{ matrix.repo.github }}/instructions.md"
run: |
chmod +x ${{ github.workspace }}/.github/workflows/deploy_guide.sh
${{ github.workspace }}/.github/workflows/deploy_guide.sh $LAB_ID $OAUTH_TOKEN $FILE_PATH "$(git log -1 --pretty=format:"%s" -- $FILE_PATH)" $PUBLISH "https://author.skills.network"
deployAllToStaging:
needs: matrixStaging
# name: Start Mirror Containers for all Guides for Staging
if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'staging' && contains( github.event.pull_request.title,'Change to multiple Guides')
continue-on-error: true
runs-on: ubuntu-latest
strategy:
matrix:
repo: ${{fromJson(needs.matrixStaging.outputs.matrix)}}
steps:
# Any prerequisite steps
- uses: actions/checkout@master
with:
ref: staging
- name: Mirror to AWB
env:
LAB_ID: ${{ matrix.repo.lab_id }}
OAUTH_TOKEN: "${{ secrets.AWB_OAUTH_TOKEN }}"
PUBLISH: false
FILE_PATH: "instructions/${{ matrix.repo.github }}/instructions.md"
run: |
chmod +x ${{ github.workspace }}/.github/workflows/deploy_guide.sh
${{ github.workspace }}/.github/workflows/deploy_guide.sh $LAB_ID $OAUTH_TOKEN $FILE_PATH "$(git log -1 --pretty=format:"%s" -- $FILE_PATH)" $PUBLISH "https://author.skills.network"
# Output link to staged files
- name: Print staging lab URL
run: echo "Staging quicklab available at https://labs.cognitiveclass.ai/tools/theiadocker/lab/tree?md_instructions_url=https://cf-course-data-staging.s3.us-east.cloud-object-storage.appdomain.cloud/${{matrix.repo.gitlab}}/instructions.md"
shell: bash