-
Notifications
You must be signed in to change notification settings - Fork 5
291 lines (276 loc) · 11.5 KB
/
main.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
name: Test and build SEE
on:
pull_request:
types: [opened, reopened, synchronize, ready_for_review, closed]
branches: [master]
workflow_dispatch:
inputs:
windows:
description: 'Create Windows build?'
default: true
type: boolean
linux:
description: 'Create Linux build?'
default: true
type: boolean
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
permissions: read-all
jobs:
setup:
name: Setup Repository
# The following condition filters out pull requests that are closed, but not merged.
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.state != 'closed' || github.event.pull_request.merged }}
runs-on: [self-hosted, see-ci]
outputs:
runner: ${{ steps.remember.outputs.runner }}
steps:
- name: Fix permissions
shell: bash
run: sudo /mnt/scripts/set-work-permissions.sh
- name: Setup GitLab LFS
run: |
echo "$CREDENTIALS" > ~/.git-credentials
git config --global credential.helper store
git config --global lfs.url ${CREDENTIALS}project-see/see-lfs.git/info/lfs
env:
# NOTE: must be of the form https://koschke:token-here@gitlab.informatik.uni-bremen.de/
CREDENTIALS: ${{secrets.GITLAB_LFS_TOKEN}}
- uses: actions/checkout@v3
name: Checkout Repository
with:
lfs: true
fetch-depth: 0
- name: Confirm LFS pull
run: git lfs pull
- name: Remember runner
id: remember
# We remember this to make sure all jobs are run on the same machine.
run: echo "runner=${{ runner.name }}" >> $GITHUB_OUTPUT
gitscripts:
name: Run GitScript checks
runs-on: ${{ needs.setup.outputs.runner }}
needs: [setup]
if: ${{ github.event_name != 'workflow_dispatch' }}
steps:
- name: Run GitScripts checks
run: ./GitScripts/run_all
static:
name: Run static checks
runs-on: [self-hosted, see-ci]
if: ${{ !github.event.pull_request.draft && github.event_name != 'workflow_dispatch' && !github.event.pull_request.merged }}
permissions:
contents: read
issues: read
pull-requests: write
steps:
- name: Collect bad patterns
run: |
if [ -n $GITHUB_BASE_REF ] && ! PATTERNS=$(curl -H 'Accept: application/vnd.github.v3.diff' -H 'Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' -f 'https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.number }}' | ./GitScripts/check_for_bad_patterns.py); then
DELIMITER=7MApgggGyx6C0
echo "PATTERNS<<$DELIMITER" >> $GITHUB_ENV
echo "$PATTERNS" >> $GITHUB_ENV
echo "$DELIMITER" >> $GITHUB_ENV
else
echo "PATTERNS=none" >> $GITHUB_ENV
fi
- uses: actions/github-script@v6
name: Check for bad patterns
with:
retries: 3
script: |
const PATTERNS = process.env.PATTERNS;
const helper = require('./GitScripts/review_helper.js');
if (PATTERNS === "none") {
console.log("Found no bad patterns in changed files.");
} else {
let comments = JSON.parse(PATTERNS);
console.log("::warning::Found " + comments.length + " bad patterns!");
if (context.ref === 'refs/heads/master') {
console.log("However, we are on master, so we ignore them.");
} else {
await helper.filter_out_existing_comments(github, context, comments);
if (comments.length > 0) {
console.log("Submitting PR review...");
let limitMessage = '';
if (comments.length > 50) {
limitMessage = `\n\n**NOTE: Only the first 50 (out of ${comments.length}) review comments are included.** `;
limitMessage += 'Remaining comments will appear when the CI is triggered next.';
comments.splice(50);
}
try {
github.rest.pulls.createReview({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
event: 'COMMENT',
body: 'There are a few bad patterns I found which you should check.' + limitMessage,
comments: comments
});
} catch (error) {
console.error("Could not submit review for pull request. Please check the error message and, below it, the comments for this PR.\n" + error);
console.log("Original comments:");
for (let comment of comments) {
console.warn(`${comment['path']}, line ${comment['line']}: ${comment['body']}`);
}
}
} else {
console.log("After filtering, no new comments are left. Not submitting a review.");
}
}
}
test:
name: Run editmode tests
runs-on: ${{ needs.setup.outputs.runner }}
needs: [setup, gitscripts]
if: ${{ ! github.event.pull_request.draft && github.event_name != 'workflow_dispatch' }}
permissions: write-all
steps:
- uses: actions/cache@v3
name: Cache Library
env:
SEGMENT_DOWNLOAD_TIMEOUT_MINS: 11
with:
path: ./Library
key: Library-SEE-Tests-${{ hashFiles('./ProjectSettings/ProjectVersion.txt') }}
restore-keys: |
Library-SEE-Tests
Library-SEE
- uses: game-ci/unity-test-runner@v3
timeout-minutes: 45
name: Run Tests
id: tests
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
with:
githubToken: ${{ secrets.GITHUB_TOKEN }}
checkName: Test Results
testMode: EditMode # PlayMode tests get stuck in batchmode
customParameters: -testCategory "!NonDeterministic"
coverageOptions: 'generateAdditionalMetrics;generateHtmlReport;assemblyFilters:+SEE'
- uses: actions/upload-artifact@v3
continue-on-error: true
name: Upload test results
if: ${{ !cancelled() }}
with:
name: Test results
path: ${{ steps.tests.outputs.artifactsPath }}
- uses: actions/upload-artifact@v3
continue-on-error: true
name: Upload coverage results
# Coverage results can get quite large, so only upload on merge into master.
if: ${{ github.event.pull_request.merged }}
with:
name: Coverage results
path: ${{ steps.tests.outputs.coveragePath }}
setup_build_targets:
name: Setup build targets
if: ${{ ! github.event.pull_request.draft }}
runs-on: [self-hosted, see-ci]
outputs:
targetPlatforms: ${{ steps.rememberPlatforms.outputs.targetPlatforms }}
steps:
- id: rememberPlatforms
name: Choose platforms for which to create builds
run: |
if ${{ github.event_name != 'workflow_dispatch' }}; then
# Include all target platforms.
echo 'targetPlatforms=["StandaloneWindows64", "StandaloneLinux64"]' >> $GITHUB_OUTPUT
else
# Set targetPlatform based on inputs.
targetPlatforms=()
if ${{ github.event.inputs.windows == true }}; then
targetPlatforms+=("StandaloneWindows64")
fi
if ${{ github.event.inputs.linux == true }}; then
targetPlatforms+=("StandaloneLinux64")
fi
echo "targetPlatforms=$(jq --compact-output --null-input '$ARGS.positional' --args -- ${targetPlatforms[@]})" >> $GITHUB_OUTPUT
fi
build:
name: Create build
runs-on: ${{ needs.setup.outputs.runner }}
needs: [setup, setup_build_targets, test, gitscripts]
strategy:
matrix:
targetPlatform: ${{ fromJson(needs.setup_build_targets.outputs.targetPlatforms) }}
if: ${{ ! github.event.pull_request.draft }}
steps:
- name: Cleanup any modifications
run: |
sudo /mnt/scripts/set-work-permissions.sh # Permissions may be messed up here
git reset --hard ${{ github.sha }} # Test or previous build may have changed files
# Try deleting any previous build, but not other zip files that we may need later.
git clean -fd -e 'build-*.zip'
rm -rf build "build-${{ matrix.targetPlatform }}.zip" || true
- uses: game-ci/unity-builder@v3
timeout-minutes: 45
name: Build project
id: build
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
with:
targetPlatform: ${{ matrix.targetPlatform }}
buildName: ${{ matrix.targetPlatform }}
allowDirtyBuild: true
- name: Compress build
# Compress only if manually triggered or merged into master, otherwise we won't upload.
if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.merged }}
run: zip -r build-${{ matrix.targetPlatform }}.zip build/${{ matrix.targetPlatform }}
- uses: actions/upload-artifact@v3
continue-on-error: true
name: Upload build
# Upload only if manually triggered, because for master merges we create a release below anyway.
if: ${{ github.event_name == 'workflow_dispatch' }}
with:
name: SEE-${{ matrix.targetPlatform }}-${{ github.sha }}.zip
path: build-${{ matrix.targetPlatform }}.zip
retention-days: 7 # Due to high space usage.
release:
name: Release
runs-on: ${{ needs.setup.outputs.runner }}
permissions: write-all
needs: [setup, build]
# We only want to create a release after merging a PR into master.
# Note that we will not create a release if the PR is labelled 'no release'.
# This label should be set when a PR does not lead to a noticeable change in the build.
if: ${{ github.event.pull_request.merged && !contains(github.event.pull_request.labels.*.name, 'no release') }}
steps:
- name: Create release tag
uses: rickstaa/action-create-tag@v1
with:
tag: pr-${{ github.event.pull_request.number }}
message: ${{ github.event.pull_request.title }}
- name: Publish release
uses: softprops/action-gh-release@v1
with:
prerelease: true
name: ${{ github.event.pull_request.title }}
tag_name: pr-${{ github.event.pull_request.number }}
fail_on_unmatched_files: true
files: |
build-*.zip
body: |
This release incorporates the changes by @${{ github.event.pull_request.user.login }} from pull request #${{ github.event.pull_request.number }}.
Builds for Windows and Linux are available below.
## Details
${{ github.event.pull_request.body }}
---
> [See original pull request for details.](${{ github.event.pull_request.html_url }})
cleanup:
name: Cleanup
runs-on: ${{ needs.setup.outputs.runner }}
if: ${{ always() }}
needs: [setup, test, build, release] # "test", "build" and "release" use docker and sometimes mess up permissions.
strategy:
fail-fast: false
steps:
- name: Kill Unity
if: always()
shell: bash
run: ./.github/scripts/stop-docker.sh
- name: Fix permissions
if: always()
shell: bash
run: sudo /mnt/scripts/set-work-permissions.sh