-
Notifications
You must be signed in to change notification settings - Fork 4
188 lines (184 loc) · 7.48 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
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
name: Build box2d3-wasm
on:
workflow_dispatch:
inputs:
mode:
description: 'Build mode'
required: true
type: choice
options:
- debug
- relwithdebinfo
- release
action:
description: 'Package action'
required: true
type: choice
options:
- pack
- publish
default: pack
version_type:
description: '[if publish] Version bump'
required: true
type: choice
options:
- major
- minor
- patch
env:
EM_VERSION: 3.1.73
EM_CACHE_FOLDER: 'emsdk-cache'
jobs:
build:
runs-on: ubuntu-latest
# Only use release environment if we're publishing
environment: ${{ (github.event.inputs.action == 'publish' && github.event.inputs.mode == 'release') && 'release' || '' }}
permissions:
contents: write # this permission is only exercised in mode == 'release'
id-token: write # for npm publish --provenance # https://docs.npmjs.com/generating-provenance-statements
actions: write # for triggering other workflows
steps:
- name: validate inputs
run: |
if [ "${{ github.event.inputs.action }}" = "publish" ] && [ "${{ github.event.inputs.mode }}" != "release" ]; then
echo "::error::Publish action is only allowed in release mode"
exit 1
fi
- uses: actions/checkout@v4
with:
submodules: recursive
- name: setup cache
id: cache-system-libraries
uses: actions/cache@v4
with:
path: ${{env.EM_CACHE_FOLDER}}
key: ${{env.EM_VERSION}}-${{ runner.os }}
- uses: mymindstorm/setup-emsdk@v14
with:
version: ${{env.EM_VERSION}}
actions-cache-folder: ${{env.EM_CACHE_FOLDER}}
- uses: actions/setup-node@v4
with:
node-version: 20
registry-url: "https://registry.npmjs.org"
- name: install global deps
run: npm i -g typescript yarn
- name: install local deps
run: npm ci
working-directory: box2d3-wasm
- name: set build type
id: build-type
run: |
if [ "${{ github.event.inputs.mode }}" = "debug" ]; then
echo "target_type=Debug" >> $GITHUB_OUTPUT
elif [ "${{ github.event.inputs.mode }}" = "relwithdebinfo" ]; then
echo "target_type=RelWithDebInfo" >> $GITHUB_OUTPUT
else
echo "target_type=Release" >> $GITHUB_OUTPUT
fi
- name: "SIMD: build makefile"
working-directory: box2d3-wasm
run: shell/0_build_makefile.sh
env:
FLAVOUR: simd
TARGET_TYPE: ${{ steps.build-type.outputs.target_type }}
- name: "SIMD: emmake"
working-directory: box2d3-wasm
run: emmake make -j8 -C cmake-build-simd
- name: "SIMD: build wasm"
working-directory: box2d3-wasm
run: shell/1_build_wasm.sh
env:
FLAVOUR: simd
TARGET_TYPE: ${{ steps.build-type.outputs.target_type }}
- name: "Standard: build makefile"
working-directory: box2d3-wasm
run: shell/0_build_makefile.sh
env:
FLAVOUR: standard
TARGET_TYPE: ${{ steps.build-type.outputs.target_type }}
- name: "Standard: emmake"
working-directory: box2d3-wasm
run: emmake make -j8 -C cmake-build-standard
- name: "Standard: build wasm"
working-directory: box2d3-wasm
run: shell/1_build_wasm.sh
env:
FLAVOUR: standard
TARGET_TYPE: ${{ steps.build-type.outputs.target_type }}
# Pack mode: Create prerelease version without git tags
- name: version for pack
id: pack_version
if: github.event.inputs.action == 'pack'
working-directory: box2d3-wasm
run: |
# Get current version and add prerelease suffix
CURRENT_VERSION=$(node -p "require('./package.json').version")
PRERELEASE_VERSION="${CURRENT_VERSION}-pre.$(date +%Y%m%d%H%M%S)"
# Use the full version string with npm version
npm version "${PRERELEASE_VERSION}" --no-git-tag-version
echo "version=${PRERELEASE_VERSION}" >> $GITHUB_OUTPUT
echo "Created prerelease version ${PRERELEASE_VERSION}"
- name: pack and upload
if: github.event.inputs.action == 'pack'
working-directory: box2d3-wasm
run: |
npm pack
echo "Package created:"
ls *.tgz
- name: upload package artifact
if: github.event.inputs.action == 'pack'
uses: actions/upload-artifact@v4
with:
name: box2d3-wasm-${{ steps.pack_version.outputs.version }}-${{ github.event.inputs.mode }}
path: box2d3-wasm/*.tgz
- name: configure git
if: github.event.inputs.action == 'publish' && github.event.inputs.mode == 'release'
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
- name: version and tag
if: github.event.inputs.action == 'publish' && github.event.inputs.mode == 'release'
id: versioning
working-directory: box2d3-wasm
# we use --no-git-tag-version because npm version can't use git from a subdirectory of a repository(?) https://github.com/npm/cli/issues/2010
run: |
NEW_VERSION=$(npm version ${{ github.event.inputs.version_type }} --no-git-tag-version -m "release %s [skip ci]")
# Remove the 'v' prefix
NEW_VERSION=${NEW_VERSION#v}
echo "version=${NEW_VERSION}" >> $GITHUB_OUTPUT
- name: commit updated version
if: github.event.inputs.action == 'publish' && github.event.inputs.mode == 'release'
working-directory: box2d3-wasm
run: |
git add package.json package-lock.json
git commit -m "box2d3-wasm v${{ steps.versioning.outputs.version }} [skip ci]"
- name: tag updated version
if: github.event.inputs.action == 'publish' && github.event.inputs.mode == 'release'
working-directory: box2d3-wasm
run: git tag "v${{ steps.versioning.outputs.version }}"
- name: publish to npm
if: github.event.inputs.action == 'publish' && github.event.inputs.mode == 'release'
working-directory: box2d3-wasm
run: npm publish --provenance
env:
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
- name: push box2d3-wasm changes
if: github.event.inputs.action == 'publish' && github.event.inputs.mode == 'release'
working-directory: box2d3-wasm
run: |
echo "Pushing commits and tags..."
git push || { echo "Push failed"; exit 1; }
git push --tags || { echo "Push tags failed"; exit 1; }
echo "Done!"
- name: trigger update-gh-pages workflow
if: github.event.inputs.action == 'publish' && github.event.inputs.mode == 'release'
uses: peter-evans/repository-dispatch@v3
with:
event-type: box2d3-wasm-released
token: ${{ secrets.GITHUB_TOKEN }}
client-payload: '{"version": "${{ steps.versioning.outputs.version }}"}'