-
Notifications
You must be signed in to change notification settings - Fork 92
325 lines (285 loc) · 11.2 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
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
name: Build Binaries and Containers
on:
push:
branches:
- master
paths-ignore:
- '**.md'
- 'docgen/**'
- 'builder.Dockerfile'
pull_request:
branches:
- master
paths-ignore:
- '**.md'
- 'docgen/**'
- 'builder.Dockerfile'
env:
CC: gcc-7 -m64
CXX: g++-7 -m64
concurrency:
group: "build"
cancel-in-progress: false
jobs:
build:
runs-on: ubuntu-20.04
container:
image: docker://nwnxee/builder:latest
steps:
- uses: actions/checkout@v3
- run: git config --system --add safe.directory /__w/unified/unified
- name: Set outputs
id: vars
run: |
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "/usr/lib/ccache" >> $GITHUB_PATH
echo "nwn_build=$(grep 'set(TARGET_NWN_BUILD ' CMakeLists.txt | cut -d' ' -f2 | sed 's/)//')" >> $GITHUB_OUTPUT
echo "nwn_build_revision=$(grep 'set(TARGET_NWN_BUILD_REVISION ' CMakeLists.txt | cut -d' ' -f2 | sed 's/)//')" >> $GITHUB_OUTPUT
echo "nwn_build_postfix=$(grep 'set(TARGET_NWN_BUILD_POSTFIX ' CMakeLists.txt | cut -d' ' -f2 | sed 's/)//')" >> $GITHUB_OUTPUT
- name: Prepare ccache timestamp
id: ccache_cache_timestamp
run: |
echo "timestamp=$(date --utc +%Y%m%d_%H%M%SZ)" >> $GITHUB_OUTPUT
- name: ccache cache files
uses: actions/cache@v3
with:
path: .ccache
key: gcc-ccache-${{ steps.ccache_cache_timestamp.outputs.timestamp }}
restore-keys: |
gcc-ccache-
- name: Create Build Environment
run: cmake -E make_directory ${{runner.workspace}}/build
- name: Configure CMake
shell: cmake -P {0}
run: |
set(ENV{PATH} "$ENV{GITHUB_WORKSPACE}:$ENV{PATH}")
execute_process(
COMMAND cmake
-S .
-B build
-D CMAKE_BUILD_TYPE=$ENV{BUILD_TYPE}
-D CMAKE_C_COMPILER_LAUNCHER=ccache
-D CMAKE_CXX_COMPILER_LAUNCHER=ccache
RESULT_VARIABLE result
)
if (NOT result EQUAL 0)
message(FATAL_ERROR "Bad exit status")
endif()
- name: Build
shell: cmake -P {0}
run: |
execute_process(COMMAND /usr/sbin/update-ccache-symlinks)
file(TO_CMAKE_PATH "$ENV{GITHUB_WORKSPACE}" ccache_basedir)
set(ENV{CCACHE_BASEDIR} "${ccache_basedir}")
set(ENV{CCACHE_DIR} "${ccache_basedir}/.ccache")
set(ENV{CCACHE_COMPRESS} "true")
set(ENV{CCACHE_COMPRESSLEVEL} "6")
set(ENV{CCACHE_MAXSIZE} "400M")
execute_process(COMMAND ccache -p)
execute_process(COMMAND ccache -z)
execute_process(
COMMAND cmake --build build -j 4
RESULT_VARIABLE result
)
if (NOT result EQUAL 0)
message(FATAL_ERROR "Build failed")
endif()
execute_process(COMMAND ccache -s)
- name: Drop timestamp into Binaries folder
if: github.event_name == 'push'
working-directory: ${{runner.workspace}}/unified/Binaries
run: echo "${{ steps.ccache_cache_timestamp.outputs.timestamp }}" > ${{ steps.vars.outputs.sha_short }}.txt
- name: Pack the Binaries
if: github.event_name == 'push'
working-directory: ${{runner.workspace}}/unified/Binaries
run: cmake -E tar cfv ../NWNX-EE.zip --format=zip .
- name: Pack the Binaries for Docker
if: github.event_name == 'push'
working-directory: ${{runner.workspace}}/unified/Binaries
run: cmake -E tar cfv ../NWNX-EE.tar .
- name: Pack the Scripts
if: github.event_name == 'push'
working-directory: ${{runner.workspace}}/unified
shell: bash
run: zip -j ./NWScript.zip `find . -name "*.nss" | grep -Pv '_t+[0-9]{0,1}.nss'`
- name: Upload Binaries
uses: actions/upload-artifact@v4
if: github.event_name == 'push'
with:
path: ./NWNX-EE.zip
name: NWNX-EE.zip
- name: Upload Scripts
uses: actions/upload-artifact@v4
if: github.event_name == 'push'
with:
path: ./NWScript.zip
name: NWScript.zip
- name: Upload Tar Binaries for Docker
uses: actions/upload-artifact@v4
if: github.event_name == 'push'
with:
name: NWNX-EE.tar
path: ./NWNX-EE.tar
- name: Delete Old Version Release
uses: dev-drprasad/[email protected]
if: github.event_name == 'push'
with:
tag_name: "build${{ steps.vars.outputs.nwn_build }}.${{ steps.vars.outputs.nwn_build_revision }}.${{ steps.vars.outputs.nwn_build_postfix }}-HEAD"
github_token: "${{ secrets.GITHUB_TOKEN }}"
delete_release: true
- name: Delete Old Latest Release
uses: dev-drprasad/[email protected]
if: github.event_name == 'push'
with:
tag_name: "latest"
github_token: "${{ secrets.GITHUB_TOKEN }}"
delete_release: true
- name: Tag With Version and Release
uses: "ncipollo/release-action@v1"
if: github.event_name == 'push'
with:
token: "${{ secrets.GITHUB_TOKEN }}"
tag: "build${{ steps.vars.outputs.nwn_build }}.${{ steps.vars.outputs.nwn_build_revision }}.${{ steps.vars.outputs.nwn_build_postfix }}-HEAD"
commit: "master"
prerelease: false
draft: false
generateReleaseNotes: true
name: "build${{ steps.vars.outputs.nwn_build }}.${{ steps.vars.outputs.nwn_build_revision }}.${{ steps.vars.outputs.nwn_build_postfix }}-HEAD"
artifacts: "NWNX-EE.zip,NWScript.zip"
- name: Tag With Latest and Release
uses: "ncipollo/release-action@v1"
if: github.event_name == 'push'
with:
token: "${{ secrets.GITHUB_TOKEN }}"
tag: "latest"
commit: "master"
prerelease: false
draft: false
generateReleaseNotes: true
name: "build${{ steps.vars.outputs.nwn_build }}.${{ steps.vars.outputs.nwn_build_revision }}.${{ steps.vars.outputs.nwn_build_postfix }}-HEAD"
artifacts: "NWNX-EE.zip,NWScript.zip"
docker:
runs-on: ubuntu-20.04
if: github.event_name == 'push'
needs: build
steps:
- uses: actions/checkout@v3
- name: Set outputs
id: vars
run: |
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
echo "nwn_build=$(grep 'set(TARGET_NWN_BUILD ' CMakeLists.txt | cut -d' ' -f2 | sed 's/)//')" >> $GITHUB_OUTPUT
echo "nwn_build_revision=$(grep 'set(TARGET_NWN_BUILD_REVISION ' CMakeLists.txt | cut -d' ' -f2 | sed 's/)//')" >> $GITHUB_OUTPUT
echo "nwn_build_postfix=$(grep 'set(TARGET_NWN_BUILD_POSTFIX ' CMakeLists.txt | cut -d' ' -f2 | sed 's/)//')" >> $GITHUB_OUTPUT
- name: Download Binaries
uses: actions/download-artifact@v4
with:
name: NWNX-EE.tar
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ secrets.GHCR_USERNAME }}
password: ${{ secrets.CR_PAT }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v4
with:
context: ./
file: ./gha.Dockerfile
push: true
build-args: NWNXEE_BASE_IMAGE=ghcr.io/${{ github.repository_owner }}/nwnxee-base
labels: |
org.opencontainers.image.title=NWNX:EE
org.opencontainers.image.description=This is the NWNX:EE image. NWNX:EE is a framework that developers can use to modify existing hardcoded rules or inject brand new functionality into Neverwinter Nights: Enhanced edition.
org.opencontainers.image.author=NWNX:EE Community
org.opencontainers.image.vendor=NWNX:EE Community
org.opencontainers.image.source=https://github.com/${{ github.repository_owner }}/unified
org.opencontainers.image.created=${{ steps.vars.outputs.created }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.documentation=https://nwnxee.github.io/unified
tags: |
${{ github.repository }}:latest
${{ github.repository }}:build${{ steps.vars.outputs.nwn_build }}.${{ steps.vars.outputs.nwn_build_revision }}
${{ github.repository }}:build${{ steps.vars.outputs.nwn_build }}.${{ steps.vars.outputs.nwn_build_revision }}.${{ steps.vars.outputs.nwn_build_postfix }}
${{ github.repository }}:${{ steps.vars.outputs.sha_short }}
ghcr.io/${{ github.repository }}:latest
ghcr.io/${{ github.repository }}:build${{ steps.vars.outputs.nwn_build }}.${{ steps.vars.outputs.nwn_build_revision }}
ghcr.io/${{ github.repository }}:build${{ steps.vars.outputs.nwn_build }}.${{ steps.vars.outputs.nwn_build_revision }}.${{ steps.vars.outputs.nwn_build_postfix }}
ghcr.io/${{ github.repository }}:${{ steps.vars.outputs.sha_short }}
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
release:
if: contains(github.ref, 'tags/build')
runs-on: ubuntu-20.04
needs: build
steps:
- name: Create Release
id: create_release
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
- name: Store Release url
run: |
echo "${{ steps.create_release.outputs.upload_url }}" > ./upload_url
- uses: actions/upload-artifact@v4
with:
path: ./upload_url
name: upload_url
publish:
if: contains(github.ref, 'tags/build')
runs-on: ubuntu-20.04
needs: release
steps:
- name: Download Binaries
uses: actions/download-artifact@v4
with:
name: NWNX-EE.zip
path: ./
- name: Download Scripts
uses: actions/download-artifact@v4
with:
name: NWScript.zip
path: ./
- name: Download URL
uses: actions/download-artifact@v4
with:
name: upload_url
path: ./
- id: set_upload_url
run: |
upload_url=`cat ./upload_url`
echo "upload_url=$upload_url" >> $GITHUB_OUTPUT
- name: Upload Binaries to Release
id: upload_binaries_to_release
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.set_upload_url.outputs.upload_url }}
asset_path: ./NWNX-EE.zip
asset_name: NWNX-EE.zip
asset_content_type: application/zip
- name: Upload Scripts to Release
id: upload_scripts_to_release
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.set_upload_url.outputs.upload_url }}
asset_path: ./NWScript.zip
asset_name: NWScript.zip
asset_content_type: application/zip