-
Notifications
You must be signed in to change notification settings - Fork 3
147 lines (143 loc) · 5.24 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
# 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: 'Version increment type'
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: ${{ github.event.inputs.action == 'publish' && github.event.inputs.mode == 'release' && 'write' || 'read' }}
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
- name: install global deps
run: npm i -g typescript yarn
- 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: build makefile
working-directory: box2d3-wasm
run: shell/0_build_makefile.sh
env:
FLAVOUR: simd
TARGET_TYPE: ${{ steps.build-type.outputs.target_type }}
- name: emmake
working-directory: box2d3-wasm
run: emmake make -j8 -C cmake-build
- name: build wasm
working-directory: box2d3-wasm
run: shell/1_build_wasm.sh
env:
FLAVOUR: simd
TARGET_TYPE: ${{ steps.build-type.outputs.target_type }}
# Pack mode: Create prerelease version without git tags
- name: Version for pack
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)"
npm version $PRERELEASE_VERSION --no-git-tag-version
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: npm-package
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"
- name: version and tag
if: github.event.inputs.action == 'publish' && github.event.inputs.mode == 'release'
working-directory: box2d3-wasm
run: |
npm version ${{ github.event.inputs.version_type }} -m "Release %s [skip ci]"
- name: publish to npm
if: github.event.inputs.action == 'publish' && github.event.inputs.mode == 'release'
working-directory: box2d3-wasm
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
- name: Push changes
if: github.event.inputs.action == 'publish' && github.event.inputs.mode == 'release'
working-directory: box2d3-wasm
run: |
echo "Pushing commits and tags..."
git push
git push --tags
echo "Done!"
- name: Trigger deploy workflow
if: github.event.inputs.action == 'publish' && github.event.inputs.mode == 'release'
uses: peter-evans/repository-dispatch@v2
with:
event-type: deploy-triggered
token: ${{ secrets.GITHUB_TOKEN }}