forked from 1dot13/source
-
Notifications
You must be signed in to change notification settings - Fork 0
219 lines (189 loc) · 7.78 KB
/
build.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
name: build
on:
push:
branches:
- '**'
tags:
- 'v*'
# allows to manually trigger a build
workflow_dispatch:
inputs:
build_all_languages:
description: build all languages
required: false
default: false
type: boolean
assemble_release:
description: create release
required: false
default: false
type: boolean
permissions:
contents: write
jobs:
workflow_setup:
runs-on: ubuntu-latest
outputs:
languages_json_array: ${{ steps.global_vars.outputs.languages_json_array }}
assemble_release: ${{ steps.global_vars.outputs.assemble_release }}
steps:
- id: global_vars
name: Set global variables
run: |
set -eux
full_release='${{ ( github.repository == '1dot13/source' && github.ref_name == 'master' ) || startsWith(github.ref, 'refs/tags/v') }}'
if [[ '${{ inputs.build_all_languages }}' == 'true' || ( '${{ inputs.build_all_languages }}' == '' && "$full_release" == 'true' ) ]]
then
languages_json_array='["Chinese", "German", "English", "French", "Polish", "Italian", "Dutch", "Russian"]';
else
# English + some other language for compilation testing
languages_json_array='["German", "English"]'
fi
echo "languages_json_array=$languages_json_array" >> $GITHUB_OUTPUT
if [[ '${{ inputs.assemble_release }}' == 'true' || ( '${{ inputs.assemble_release }}' == '' && "$full_release" == 'true' ) ]]
then
assemble_release='true'
else
assemble_release='false'
fi
echo "assemble_release=$assemble_release" >> $GITHUB_OUTPUT
- name: Clone repos metadata
run: |
set -eux
GAMEDIR_REPOSITORY=1dot13/gamedir
GAMEDIR_LANGUAGES_REPOSITORY=1dot13/gamedir-languages
# filter tree is what makes this fast
git clone --config transfer.fsckobjects=false --tags --no-checkout --filter=tree:0 \
"https://github.com/$GITHUB_REPOSITORY" \
source
git clone --config transfer.fsckobjects=false --no-checkout --filter=tree:0 \
https://github.com/$GAMEDIR_REPOSITORY \
gamedir
git clone --config transfer.fsckobjects=false --no-checkout --filter=tree:0 \
https://github.com/$GAMEDIR_LANGUAGES_REPOSITORY \
gamedir-languages
mkdir dist/
echo -n "
GAMEDIR_REPOSITORY=$GAMEDIR_REPOSITORY
GAMEDIR_LANGUAGES_REPOSITORY=$GAMEDIR_LANGUAGES_REPOSITORY
" > dist/versions.env
- name: Generate source version information
working-directory: source
run: |
set -eux
SOURCE_COMMIT_DATETIME=$(TZ=UTC0 git log -1 --date=iso-strict-local --format=%cd $GITHUB_SHA)
SOURCE_COMMIT_DATE=$(TZ=UTC0 git log -1 --date=short-local --format=%cd $GITHUB_SHA)
# GAME_VERSION is used to detect outdated save games and is the main version used for tracking
if [[ "$GITHUB_REF_TYPE" == 'tag' ]]
then
# if we build for a specific tag, use that as the game version
# examples:
# - v1.13.1
# - v1.13.2-rc2
GAME_VERSION="$GITHUB_REF_NAME"
else
# uses `git describe`, which tries to find a tag in the commit hierarchy. or fall back to a v1.13 version
# example five (5) commits after v1.13:
# - v1.13-5-7g7ffa
GAME_VERSION="$(git describe --tags --match='v[0-9]*' $GITHUB_SHA || echo v0-$(git rev-list --skip 1 --count $GITHUB_SHA)-g${GITHUB_SHA:0:8})"
fi
# max 15 CHAR8
GAME_VERSION="${GAME_VERSION:0:15}"
GAME_BUILD_INFORMATION="$SOURCE_COMMIT_DATE GitHub $GITHUB_REPOSITORY"
# in case of a branch or if the tag is truncated
if [[ "$GAME_VERSION" != *"$GITHUB_REF_NAME"* ]]
then
GAME_BUILD_INFORMATION="$GAME_BUILD_INFORMATION $GITHUB_REF_TYPE $GITHUB_REF_NAME"
fi
# max 255 CHAR16
GAME_BUILD_INFORMATION="${GAME_BUILD_INFORMATION:0:255}"
echo -n "
SOURCE_COMMIT_DATETIME=$SOURCE_COMMIT_DATETIME
GAME_VERSION=$GAME_VERSION
GAME_BUILD_INFORMATION=$GAME_BUILD_INFORMATION
" >> ../dist/versions.env
# due to building everything in parallel, versions should be pinned at the start so everything builds based on the same versions
- name: Generate gamedir version information
working-directory: gamedir
run: |
set -eux
GAMEDIR_COMMIT_SHA=$(git rev-parse HEAD)
GAMEDIR_COMMIT_DATETIME=$(TZ=UTC0 git log -1 --date=iso-strict-local --format=%cd $GAMEDIR_COMMIT_SHA)
echo -n "
GAMEDIR_COMMIT_SHA=$GAMEDIR_COMMIT_SHA
GAMEDIR_COMMIT_DATETIME=$GAMEDIR_COMMIT_DATETIME
" >> ../dist/versions.env
# due to building everything in parallel, versions should be pinned at the start so everything builds based on the same versions
- name: Generate gamedir-languages version information
working-directory: gamedir-languages
run: |
set -eux
GAMEDIR_LANGUAGES_COMMIT_SHA=$(git rev-parse HEAD)
GAMEDIR_LANGUAGES_COMMIT_DATETIME=$(TZ=UTC0 git log -1 --date=iso-strict-local --format=%cd $GAMEDIR_LANGUAGES_COMMIT_SHA)
echo -n "
GAMEDIR_LANGUAGES_COMMIT_SHA=$GAMEDIR_LANGUAGES_COMMIT_SHA
GAMEDIR_LANGUAGES_COMMIT_DATETIME=$GAMEDIR_LANGUAGES_COMMIT_DATETIME
" >> ../dist/versions.env
- name: Show version information summary
run: |
set -eux
cat dist/versions.env
- name: Upload
uses: actions/upload-artifact@v4
with:
name: versions.env
path: dist/
build:
needs: [ workflow_setup ]
strategy:
fail-fast: false
matrix:
language: ${{ fromJson(needs.workflow_setup.outputs.languages_json_array) }}
uses: ./.github/workflows/build_language.yml
with:
language: ${{ matrix.language }}
assemble: ${{ needs.workflow_setup.outputs.assemble_release == 'true' }}
# at least English and some other lang have to work
continue-on-error: ${{ matrix.language != 'English' && matrix.language != 'German' }}
release:
needs: [ workflow_setup, build ]
if: needs.workflow_setup.outputs.assemble_release == 'true'
runs-on: ubuntu-latest
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: dist
pattern: '*_release'
merge-multiple: true
- name: Checkout Repo
if: github.ref == 'refs/heads/master'
uses: actions/checkout@v4
with:
path: source
fetch-depth: 1
sparse-checkout: 'README.md'
- name: Create latest pre-release
if: github.ref == 'refs/heads/master'
working-directory: source
run: |
gh release delete latest --cleanup-tag || true
git tag -d latest || true
git push --delete origin refs/tags/latest || true
git tag latest
git push --force origin refs/tags/latest
gh release create latest ../dist/* \
--generate-notes \
--title "Latest (unstable)" \
--verify-tag \
--prerelease
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload to tagged release
if: startsWith(github.ref, 'refs/tags/v')
working-directory: source
run: |
exit 0
gh release upload "$GITHUB_REF_NAME" ../dist/* --clobber
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}