-
Notifications
You must be signed in to change notification settings - Fork 59
295 lines (269 loc) · 9.67 KB
/
ci.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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
name: CI
on:
pull_request:
branches:
- master
push:
branches:
- master
schedule:
- cron: '0 0 * * *'
jobs:
build-desktop:
name: Build desktop application and docs
runs-on: ubuntu-latest
strategy:
matrix:
java: [17]
steps:
# Set up Java development environment.
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: ${{ matrix.java }}
distribution: 'microsoft'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
# Read the application version to use it in the name of the JAR.
- name: Read version from gradle.properties
id: read_version
uses: christian-draeger/read-properties@1.1.1
with:
path: 'gradle.properties'
properties: 'version'
# Compile the code, run unit tests, upload code coverage results.
- name: Compile Java code
run: ./gradlew compileJava
- name: Run unit tests
run: ./gradlew check
- name: Codecov
uses: codecov/codecov-action@v3.1.4
with:
token: ${{ secrets.CODECOV_TOKEN }}
# Build docs (PDF and HTML for the in-app help)
# The Python dependencies are fetched by Gradle.
- name: Build all docs
run: ./gradlew allDocs
# Build JAR file.
- name: Build JAR
run: ./gradlew jar
# Upload artifacts (manuals and JARs)
- name: Upload English Manual PDF
uses: actions/upload-artifact@v3.1.3
with:
name: English manual (PDF)
path: ./build/docs/en/pdf/EduMIPS64.pdf
- name: Upload Italian Manual PDF
uses: actions/upload-artifact@v3.1.3
with:
name: Italian manual (PDF)
path: ./build/docs/it/pdf/EduMIPS64.pdf
#
# Disabled due to not working properly
#
# - name: Upload Simplified Chinese Manual PDF
# uses: actions/upload-artifact@v3.1.2
# with:
# name: Chinese manual (PDF)
# path: ./build/docs/zh/pdf/EduMIPS64.pdf
- name: Upload JAR
uses: actions/upload-artifact@v3.1.3
with:
name: JAR
path: ./build/libs/edumips64-${{ steps.read_version.outputs.version }}.jar
build-msi:
name: Build Windows MSI
runs-on: windows-latest
needs: build-desktop
steps:
- uses: actions/checkout@v4
- name: Install Wix
uses: actions/checkout@v4
with:
repository: fbarresi/wix
path: wix
- name: Download JAR
uses: actions/download-artifact@v3.0.2
with:
name: JAR
path: build/libs
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'microsoft'
- name: Build MSI
run: ./gradlew MSI
- name: Upload MSI
uses: actions/upload-artifact@v3.1.3
with:
name: MSI
path: EduMIPS64-*.msi
build-web:
name: Build web application
runs-on: ubuntu-latest
steps:
# Set up JDK (necessary for the core that is cross-compiled to JS)
# and Node.JS (for the) web app itself.
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'microsoft'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build JS Worker (Java → JS)
run: ./gradlew war
- name: Set up Node.JS 18
uses: actions/setup-node@v3
with:
node-version: '18.12.1'
- name: Install JS dependencies
run: npm install
# Build JS application and upload artifacts for subsequent steps.
- name: Build JS application
run: npm run build
- uses: actions/upload-artifact@v3
name: Upload web application artifacts
with:
name: web
path: build/gwt/war/edumips64
deploy-web:
name: Deploy web application
permissions: write-all
runs-on: ubuntu-latest
needs: build-web
steps:
# This step behaves differently in PRs and on push to master / cron.
# Set up environment variables according to the triggering event.
- name: Set PR environment variables
if: ${{ github.event_name == 'pull_request' }}
run: |
echo "DEPLOYMENT_ENV=${{github.event.pull_request.number}}" >> $GITHUB_ENV
echo "PUSH_DIR=pr/" >> $GITHUB_ENV
echo "COMMIT_MESSAGE=Deploy code for PR ${{ github.event.pull_request.number }}" >> $GITHUB_ENV
echo "DEPLOYMENT_ENV_URL=https://edumips64ci.z16.web.core.windows.net/${{github.event.pull_request.number}}/" >> $GITHUB_ENV
- name: Set master push environment variables
if: ${{ github.event_name != 'pull_request' }}
run: |
echo "DEPLOYMENT_ENV=prod" >> $GITHUB_ENV
echo "PUSH_DIR=build/gwt/war/edumips64" >> $GITHUB_ENV
echo "COMMIT_MESSAGE=Update Web Frontend @ ${{ github.sha }}" >> $GITHUB_ENV
echo "DEPLOYMENT_ENV_URL=https://web.edumips.org" >> $GITHUB_ENV
# Download web application built in 'build-web'
- uses: actions/download-artifact@v3
name: Download web application artifacts
with:
name: web
path: build/gwt/war/edumips64
# Mark the deployment as started (allows the PR to display "Deployment started" messages.)
- name: Start deployment
uses: bobheadxi/deployments@v1.4.0
id: deployment
with:
step: start
token: ${{ secrets.GITHUB_TOKEN }}
env: ${{ env.DEPLOYMENT_ENV }}
ref: ${{ github.head_ref }}
# Deploy the code on Github Pages.
# Copy files to a directory to allow pushing to a subdir in the web.edumips.org repo.
- name: Copy files to run directory
run: mkdir -p pr/${{ github.event.pull_request.number }} && cp -r build/gwt/war/edumips64/* pr/${{ github.event.pull_request.number }}
if: ${{ github.event_name == 'pull_request' }}
# Upload to Azure blob if this is a PR.
- name: Login to Azure
uses: azure/login@v1
if: ${{ github.event_name == 'pull_request' }}
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Upload to Azure blob storage (${{ env.DEPLOYMENT_ENV_URL }})
uses: azure/CLI@v1
if: ${{ github.event_name == 'pull_request' }}
with:
inlineScript: |
az storage blob upload-batch --account-name edumips64ci --auth-mode key -d '$web/${{ github.event.pull_request.number }}' -s pr/${{ github.event.pull_request.number }} --overwrite
- name: Deploy master web application to web.edumips.org
if: ${{ success() && github.event_name != 'pull_request' }}
uses: crazy-max/ghaction-github-pages@v4
with:
target_branch: master
build_dir: ${{ env.PUSH_DIR }}
repo: EduMIPS64/web.edumips.org
keep_history: true
commit_message: ${{ env.COMMIT_MESSAGE }}
fqdn: web.edumips.org
env:
GH_PAT: ${{ secrets.PAT_WEBUI }}
# Mark the deployment as succeeded or failed.
- name: Update deployment status
uses: bobheadxi/deployments@v1.4.0
if: always() && github.head_ref
with:
step: finish
token: ${{ secrets.GITHUB_TOKEN }}
status: ${{ job.status }}
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
env_url: ${{ env.DEPLOYMENT_ENV_URL }}
env: ${{ env.DEPLOYMENT_ENV }}
# Test the deployed web application.
# This is only ran on pull request because runs triggered by push and schedule
# will deploy to web.edumips.org. Given that the deployment has some latency,
# the test will most likely run against the previously-deployed version,
# potentially giving a false sense of security if a developer sees the test being
# run immediately after the deployment.
#
# There is a separate job that periodically monitors web.edumips.org, which will
# catch regressions.
test-web:
name: Test web application
runs-on: ubuntu-latest
needs: deploy-web
if: ${{ github.event_name == 'pull_request' }}
steps:
- uses: actions/checkout@v4
- name: Set up Node.JS 18
uses: actions/setup-node@v3
with:
node-version: '18.12.1'
- name: Install JS dependencies
run: npm install
- name: Install Playwright dependencies
run: npx playwright install
# Run tests against the deployed code.
- name: Run web tests against deployed code
uses: nick-fields/retry@v2
env:
PLAYWRIGHT_TARGET_URL: https://edumips64ci.z16.web.core.windows.net/${{github.event.pull_request.number}}/
with:
max_attempts: 10
timeout_minutes: 2
retry_on: error
command: npm run test
build-snap:
name: Build Snapcraft package
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: snapcore/action-build@v1
id: snapcraft
- uses: actions/upload-artifact@v3
with:
name: snap
path: ${{ steps.snapcraft.outputs.snap }}
test-snap:
name: Test Snapcraft package
runs-on: ubuntu-latest
needs: build-snap
steps:
- uses: actions/download-artifact@v3
name: Download snap package
with:
name: snap
path: .
- name: Unpack and install snap
run: |
unsquashfs edumips64*.snap
sudo snap try squashfs-root/
echo "exit" | edumips64.edumips64-cli