-
Notifications
You must be signed in to change notification settings - Fork 6
300 lines (289 loc) · 11.7 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
291
292
293
294
295
296
297
298
299
300
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: main-${{ github.ref }}
cancel-in-progress: true
permissions: read-all
jobs:
conds:
name: Ensure Conditions
# 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: ubuntu-latest
steps:
- name: Do nothing
run: "echo 'Nothing to do in this job, job just ensures global conditions.'"
gitscripts:
name: Run GitScript checks
needs: [conds]
runs-on: [self-hosted, sts5]
if: ${{ github.event_name != 'workflow_dispatch' }}
steps:
- uses: uni-bremen-agst/clone-see-action@main
with:
lfs-token: ${{ secrets.GITLAB_LFS_TOKEN }}
fetch-depth: "0"
- name: Run GitScripts checks
run: ./GitScripts/run_all
static:
name: Run static checks
runs-on: ubuntu-latest
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: Checkout actions
uses: actions/checkout@v4
with:
sparse-checkout: GitScripts
lfs: false
- name: Collect bad patterns
run: |
if [ -n "$GITHUB_BASE_REF" ]; then
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 || true)
if [ "$PATTERNS" != "[]" ]; then
DELIMITER=7MApgggGyx6C0
echo "PATTERNS<<$DELIMITER" >> $GITHUB_ENV
echo "$PATTERNS" >> $GITHUB_ENV
echo "$DELIMITER" >> $GITHUB_ENV
exit 0
fi
fi
echo "PATTERNS=none" >> $GITHUB_ENV
- uses: actions/github-script@v7
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
needs: [conds]
runs-on: [self-hosted, sts5]
if: ${{ ! github.event.pull_request.draft && github.event_name != 'workflow_dispatch' }}
permissions: write-all
steps:
- uses: uni-bremen-agst/clone-see-action@main
with:
lfs-token: ${{ secrets.GITLAB_LFS_TOKEN }}
- name: Restore Cache
shell: bash
env:
KEY: SEE-${{ hashFiles('./ProjectSettings/ProjectVersion.txt') }}
OPERATION: restore
run: ./.github/scripts/cache.sh
- name: Restore NuGet packages
run: /home/falko1/.dotnet/tools/nugetforunity restore .
- uses: game-ci/unity-test-runner@v4
timeout-minutes: 60
name: Run Tests
id: tests
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
with:
githubToken: ${{ secrets.GITHUB_TOKEN }}
checkName: Test Results
testMode: EditMode # PlayMode tests get stuck in batchmode
runAsHostUser: true
customParameters: -testCategory "!SkipOnCI"
coverageOptions: "generateAdditionalMetrics;generateHtmlReport;assemblyFilters:+SEE"
- uses: actions/upload-artifact@v4
continue-on-error: true
name: Upload test results
if: ${{ !cancelled() }}
with:
name: Test results
path: ${{ steps.tests.outputs.artifactsPath }}
- uses: actions/upload-artifact@v4
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 }}
- name: Save Cache
shell: bash
env:
KEY: SEE-${{ hashFiles('./ProjectSettings/ProjectVersion.txt') }}
OPERATION: store
run: ./.github/scripts/cache.sh
setup_build_targets:
name: Setup build targets
needs: [conds]
if: ${{ ! github.event.pull_request.draft }}
runs-on: ubuntu-latest
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 ${{ inputs.windows == true }}; then
targetPlatforms+=("StandaloneWindows64")
fi
if ${{ 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: [self-hosted, sts5]
needs: [conds, setup_build_targets]
strategy:
matrix:
targetPlatform: ${{ fromJson(needs.setup_build_targets.outputs.targetPlatforms) }}
if: ${{ ! github.event.pull_request.draft }}
steps:
- uses: uni-bremen-agst/clone-see-action@main
with:
lfs-token: ${{ secrets.GITLAB_LFS_TOKEN }}
- name: Restore Cache
shell: bash
env:
KEY: SEE-${{ hashFiles('./ProjectSettings/ProjectVersion.txt') }}
OPERATION: restore
run: ./.github/scripts/cache.sh
- name: Cleanup any modifications
run: |
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
- name: Restore NuGet packages
run: /home/falko1/.dotnet/tools/nugetforunity restore .
- uses: game-ci/unity-builder@v4
timeout-minutes: 90
name: Build project
id: build
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
with:
targetPlatform: ${{ matrix.targetPlatform }}
buildName: ${{ matrix.targetPlatform }}
buildMethod: CITools.BuildScript.Build
runAsHostUser: true
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@v4
continue-on-error: true
name: Upload build
if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.merged }}
with:
name: SEE-${{ matrix.targetPlatform }}-${{ github.sha }}.zip
path: build-${{ matrix.targetPlatform }}.zip
retention-days: 7 # Due to high space usage.
- name: Store Cache
shell: bash
env:
KEY: SEE-${{ hashFiles('./ProjectSettings/ProjectVersion.txt') }}
OPERATION: store
run: ./.github/scripts/cache.sh
release:
name: Release
runs-on: ubuntu-latest
permissions: write-all
needs: [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: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
lfs: false
- uses: actions/download-artifact@v4
id: download
with:
pattern: SEE-*.zip
- 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@v2
with:
prerelease: true
name: ${{ github.event.pull_request.title }}
tag_name: pr-${{ github.event.pull_request.number }}
fail_on_unmatched_files: true
files: |
${{ steps.download.outputs.download-path }}/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 }})