forked from microsoft/responsible-ai-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 1
242 lines (219 loc) · 9.69 KB
/
CD.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
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: CD
env:
folder_to_upload: dist/apps/dashboard
blob_account: responsibleai
blob_container_for_pull_request: pullrequest
blob_container_for_js: latest
blob_container_for_raiwidget: raiwidgets
blob_path_for_pull_request: ${{ github.event.pull_request.head.repo.full_name }}/${{ github.head_ref }}
node-version: 16.x
widgetDirectory: raiwidgets
raiDirectory: responsibleai
dashboardDirectory: dashboard
retentionDays: 90
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
jobs:
cd-build:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
#setup environment
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Use Node.js ${{ env.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ env.node-version }}
- id: publish_url_for_js
name: publish_url_for_js
run: |
if [[ '${{ github.event_name }}' == 'push' ]]
then
echo "url=https://${blob_account}.blob.core.windows.net/${blob_container_for_js}/index.html" >> $GITHUB_OUTPUT
elif [[ '${{ github.event_name }}' == 'pull_request' ]]
then
echo "url=https://${blob_account}.blob.core.windows.net/${blob_container_for_pull_request}/${blob_path_for_pull_request}/${dashboardDirectory}/index.html" >> $GITHUB_OUTPUT
else
echo "Invalid event $${{ github.event_name }}"
fi
- name: Install yarn
run: npm install yarn -g
- name: Install
run: yarn install --frozen-lock-file
- name: bump version
run: yarn auto-version
- name: Get version
id: version
run: echo "version=$(cat version.cfg)" >> $GITHUB_OUTPUT
- name: Build Typescript
run: yarn buildall
# run tests before publishing to PyPI
- name: update and upgrade pip, setuptools, wheel, and twine
run: |
python -m pip install --upgrade pip
pip install --upgrade setuptools wheel twine
- name: install requirements.txt for rai
run: |
pip install -r requirements.txt
pip install -r requirements-dev.txt
working-directory: ${{ env.raiDirectory }}
- name: install requirements.txt for widget
run: |
pip install -r requirements.txt
pip install -r requirements-dev.txt
working-directory: ${{ env.widgetDirectory }}
- name: Install rai_test_utils locally until next version is released
run: |
pip install -v -e .
working-directory: rai_test_utils
- name: pip freeze
run: pip freeze
- name: replace README for raiwidgets
run: |
sed -i 's/(.\/img\//(https:\/\/raw.githubusercontent.com\/microsoft\/responsible-ai-widgets\/main\/img\//g' README.md
cp ./README.md ${{ env.widgetDirectory }}
- name: build wheel for rai
run: python setup.py sdist bdist_wheel
working-directory: ${{ env.widgetDirectory }}
- name: build wheel for widget
run: python setup.py sdist bdist_wheel
working-directory: ${{ env.raiDirectory }}
# run tests before publishing
- name: install wheel locally for rai
run: find ./dist/ -name '*.whl' -exec pip install {} \;
working-directory: ${{ env.raiDirectory }}
# run tests before publishing
- name: install wheel locally for widget
run: find ./dist/ -name '*.whl' -exec pip install {} \;
working-directory: ${{ env.widgetDirectory }}
- name: run tests
run: pytest -s -v --durations=10
- name: Upload a Build result
uses: actions/upload-artifact@v3
with:
name: dist
path: dist
- name: Upload dashboard ${{steps.publish_url_for_js.outputs.url}}
uses: Azure/cli@v1.0.0
id: uploaddashboard
with:
azcliversion: 2.16.0
inlineScript: |
if [[ '${{ github.event_name }}' == 'push' ]]
then
az storage blob sync -c "${{env.blob_container_for_js}}" --account-name "${{env.blob_account}}" -s "${{env.folder_to_upload}}" --connection-string="${{secrets.AZURE_STORAGE_CONNECTION_STRING}}"
elif [[ '${{ github.event_name }}' == 'pull_request' ]]
then
az storage blob sync -c "${{env.blob_container_for_pull_request}}" --account-name "${{env.blob_account}}" -s "${{env.folder_to_upload}}" -d "${{env.blob_path_for_pull_request}}/${{ env.dashboardDirectory }}" --connection-string="${{secrets.AZURE_STORAGE_CONNECTION_STRING}}"
else
echo "Invalid event $${{ github.event_name }}"
fi
continue-on-error: true
- if: ${{ (github.event_name == 'pull_request') && (steps.uploaddashboard.outcome != 'failure') }}
uses: unsplash/comment-on-pr@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
msg: ${{steps.publish_url_for_js.outputs.url}}
check_for_duplicate_msg: true
- if: ${{ (steps.uploaddashboard.outcome != 'failure') }}
name: Upload responsible-ai
uses: Azure/cli@v1.0.0
with:
azcliversion: 2.16.0
inlineScript: |
if [[ '${{ github.event_name }}' == 'push' ]]
then
az storage blob sync -c "${{env.blob_container_for_raiwidget}}" --account-name "${{env.blob_account}}" -s "${{ env.raiDirectory }}/dist/" -d "${{steps.version.outputs.version}}/${{ env.raiDirectory }}" --connection-string="${{secrets.AZURE_STORAGE_CONNECTION_STRING}}"
elif [[ '${{ github.event_name }}' == 'pull_request' ]]
then
az storage blob sync -c "${{env.blob_container_for_pull_request}}" --account-name "${{env.blob_account}}" -s "${{ env.raiDirectory }}/dist/" -d "${{env.blob_path_for_pull_request}}/${{ env.raiDirectory }}" --connection-string="${{secrets.AZURE_STORAGE_CONNECTION_STRING}}"
else
echo "Invalid event $${{ github.event_name }}"
fi
- if: ${{ (steps.uploaddashboard.outcome != 'failure') }}
name: Upload raiwidgets
uses: Azure/cli@v1.0.0
with:
azcliversion: 2.16.0
inlineScript: |
if [[ '${{ github.event_name }}' == 'push' ]]
then
az storage blob sync -c "${{env.blob_container_for_raiwidget}}" --account-name "${{env.blob_account}}" -s "${{ env.widgetDirectory }}/dist/" -d "${{steps.version.outputs.version}}/${{ env.widgetDirectory }}" --connection-string="${{secrets.AZURE_STORAGE_CONNECTION_STRING}}"
elif [[ '${{ github.event_name }}' == 'pull_request' ]]
then
az storage blob sync -c "${{env.blob_container_for_pull_request}}" --account-name "${{env.blob_account}}" -s "${{ env.widgetDirectory }}/dist/" -d "${{env.blob_path_for_pull_request}}/${{ env.widgetDirectory }}" --connection-string="${{secrets.AZURE_STORAGE_CONNECTION_STRING}}"
else
echo "Invalid event $${{ github.event_name }}"
fi
- name: Get retention cut off date
id: retention_date
run: echo "date=$(date --date='${{env.retentionDays}} days ago' +'%Y-%m-%dT00:00Z')" >> $GITHUB_OUTPUT
- if: ${{ (steps.uploaddashboard.outcome != 'failure') }}
name: Delete old files before ${{steps.retention_date.outputs.date}}
uses: Azure/cli@v1.0.0
with:
azcliversion: 2.16.0
inlineScript: |
az storage blob delete-batch --account-name "${{env.blob_account}}" -s "${{env.blob_container_for_raiwidget}}" --if-unmodified-since "${{steps.retention_date.outputs.date}}" --connection-string="${{secrets.AZURE_STORAGE_CONNECTION_STRING}}"
az storage blob delete-batch --account-name "${{env.blob_account}}" -s "${{env.blob_container_for_pull_request}}" --if-unmodified-since "${{steps.retention_date.outputs.date}}" --connection-string="${{secrets.AZURE_STORAGE_CONNECTION_STRING}}"
continue-on-error: true
cd-typescript-publish:
if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }}
needs: cd-build
runs-on: ubuntu-latest
strategy:
matrix:
package:
[
core-ui,
forecasting,
mlchartlib,
dataset-explorer,
causality,
counterfactuals,
fairness,
interpret,
interpret-text,
interpret-vision,
localization,
error-analysis,
model-assessment,
e2e
]
steps:
- name: Use Node.js ${{ env.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ env.node-version }}
- id: download
name: Download a Build Artifact
uses: actions/download-artifact@v2
with:
name: dist
path: dist
- id: publish
name: NPM Publish
uses: JS-DevTools/npm-publish@v1
with:
token: ${{ secrets.NPM_TOKEN }}
package: ${{steps.download.outputs.download-path}}/libs/${{ matrix.package }}/package.json
dry-run: false
access: public
# tag: next
- if: steps.publish.type != 'none'
run: |
echo "Version changed: ${{ steps.publish.outputs.old-version }} => ${{ steps.publish.outputs.version }}"