-
Notifications
You must be signed in to change notification settings - Fork 8
231 lines (224 loc) · 8.67 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
name: Build, test, release
on:
push:
pull_request:
workflow_dispatch:
schedule:
- cron: "0 0 * * *"
env:
STABLE: ${{ (github.ref_name == 'stable' || startsWith(github.ref, 'refs/tags/v')) && 'yes' || 'no' }}
jobs:
minizinc:
name: Build wasm version of MiniZinc
runs-on: ubuntu-latest
container: emscripten/emsdk
outputs:
cache-key: ${{ steps.get-cache-key.outputs.key }}
cache-hit: ${{ steps.cache.outputs.cache-hit }}
steps:
- name: Workaround for https://github.com/actions/runner/issues/2033
run: |
git config --global --add safe.directory $GITHUB_WORKSPACE
- name: Checkout latest MiniZinc
if: ${{ env.STABLE == 'yes' }}
uses: actions/checkout@v4
with:
repository: minizinc/libminizinc
ref: master
- name: Checkout edge MiniZinc
if: ${{ env.STABLE == 'no' }}
uses: actions/checkout@v4
with:
repository: minizinc/libminizinc
ref: develop
- name: Download vendor
run: ./download_vendor
env:
MZNARCH: wasm
- name: Get MiniZinc cache key
id: get-cache-key
run: echo "key=minizinc-$(git rev-parse HEAD)-${{ hashFiles('vendor/version.json') }}" >> $GITHUB_OUTPUT
- name: Cache MiniZinc Build
id: cache
uses: actions/cache@v4
with:
path: minizinc
key: ${{ steps.get-cache-key.outputs.key }}
- name: Configure MiniZinc
if: steps.cache.outputs.cache-hit != 'true'
run: |
emcmake cmake -S . -B build \
-DCMAKE_FIND_ROOT_PATH="/" \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_REF=$GITHUB_RUN_ID \
-DGecode_ROOT="$GITHUB_WORKSPACE/vendor/gecode" \
-DOsiCBC_ROOT="$GITHUB_WORKSPACE/vendor/cbc" \
-DCMAKE_PREFIX_PATH="$GITHUB_WORKSPACE/vendor/highs/lib/cmake/highs:$GITHUB_WORKSPACE/vendor/chuffed/lib/cmake/chuffed" \
-DCMAKE_INSTALL_PREFIX="$GITHUB_WORKSPACE/minizinc"
- name: Build MiniZinc
if: steps.cache.outputs.cache-hit != 'true'
run: cmake --build build --config Release --target install -j 2
- name: Upload package artifact
uses: actions/upload-artifact@v4
with:
name: minizinc
path: minizinc/
build:
name: Build and test minizinc-js
runs-on: ubuntu-latest
needs: [minizinc]
if: github.event_name != 'schedule' || needs.minizinc.outputs.cache-hit != 'true'
env:
MZN_WASM_DIR: ${{ github.workspace }}/minizinc
MZN_NODE_BINARY: ${{ github.workspace }}/native/bin/minizinc
steps:
- uses: actions/checkout@v4
- name: Cache MiniZinc
id: cache
uses: actions/cache@v4
with:
path: minizinc
key: ${{ needs.minizinc.outputs.cache-key }}
- name: Fetch MiniZinc
if: steps.cache.outputs.cache-hit != 'true'
uses: actions/download-artifact@v4
with:
name: minizinc
path: ${{ github.workspace }}/minizinc
- name: Fetch latest MiniZinc image
if: ${{ env.STABLE == 'yes' }}
uses: docker://minizinc/minizinc:latest
with:
args: sh -c "mkdir -p $GITHUB_WORKSPACE/native && cp -v -r /usr/local/* $GITHUB_WORKSPACE/native"
- name: Fetch edge MiniZinc image
if: ${{ env.STABLE == 'no' }}
uses: docker://minizinc/minizinc:edge
with:
args: sh -c "mkdir -p $GITHUB_WORKSPACE/native && cp -v -r /usr/local/* $GITHUB_WORKSPACE/native"
- uses: actions/setup-node@v4
with:
node-version: lts/*
- name: Install dependencies
run: npm ci
- name: Bump edge version
if: ${{ env.STABLE == 'no' }}
run: |
npm version prerelease --preid=edge --no-git-tag-version > /dev/null
PACKAGE=$(jq -r .name package.json)
if PUBLISHED_EDGE=$(npm view "${PACKAGE}@edge" version 2>/dev/null); then
echo "Latest published edge version is ${PUBLISHED_EDGE}"
P1=$(echo "${PUBLISHED_EDGE}" | cut -d - -f 1)
P2=$(jq -r .version package.json | cut -d - -f 1)
if [[ "$P1" == "$P2" ]]; then
jq --arg new_version "${PUBLISHED_EDGE}" '.version|=$new_version' package.json > package.json.tmp
rm package.json
mv package.json.tmp package.json
npm version prerelease --preid=edge --no-git-tag-version > /dev/null
fi
fi
echo "Bumped edge version to $(jq -r .version package.json)"
- name: Build package
run: npm run build
- name: Run tests
run: npm test
- name: Build docs
run: npm run docs
- name: Create package
run: npm pack
- name: Upload docs artifact
uses: actions/upload-artifact@v4
with:
name: docs
path: docs/
- name: Upload package artifact
uses: actions/upload-artifact@v4
with:
name: package
path: minizinc-*.tgz
publish:
name: Publish minizinc-js
runs-on: ubuntu-latest
needs: [build]
if: ${{ github.event_name != 'pull_request' && ( startsWith(github.ref, 'refs/tags/v') || github.ref_name == 'develop' ) }}
steps:
- uses: actions/setup-node@v4
with:
node-version: lts/*
registry-url: https://registry.npmjs.org
- name: Fetch package
uses: actions/download-artifact@v4
with:
name: package
path: ${{ github.workspace }}
- name: Publish edge version
if: ${{ github.ref_name == 'develop' }}
run: |
if [ -z "$NODE_AUTH_TOKEN" ]; then
npm publish minizinc-*.tgz --tag edge --dry-run
else
npm publish minizinc-*.tgz --tag edge
fi
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish latest version
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
run: |
if [ -z "$NODE_AUTH_TOKEN" ]; then
npm publish minizinc-*.tgz --dry-run
else
npm publish minizinc-*.tgz
fi
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
pages:
name: Publish documentation
runs-on: ubuntu-latest
needs: [build]
if: ${{ github.event_name != 'pull_request' && ( github.ref_name == 'develop' || github.ref_name == 'stable' || startsWith(github.ref, 'refs/tags/v') ) }}
steps:
- name: Fetch documentation
uses: actions/download-artifact@v4
with:
name: docs
path: ${{ github.workspace }}/docs
- name: Inject version selector script and favicon into head
run: find ./docs -type f -name '*.html' -exec sh -c 'sed -i "s#</head>#<script src=\"$(realpath --relative-to={} versions.js)\"></script><link rel=\"icon\" type=\"image/png\" href=\"$(realpath --relative-to={} minizinc.png)\" /></head>#" {}' \;
- name: Set package usages to point to edge
if: ${{ github.ref_name == 'develop' }}
run: |
sed -i 's#/minizinc/dist/#/minizinc@edge/dist/#g' docs/index.html
sed -i 's/npm install minizinc/npm install minizinc@edge/g' docs/index.html
sed -i 's#https://js.minizinc.dev/docs/stable/#https://js.minizinc.dev/docs/develop/#g' docs/index.html
- name: Publish documentation
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs
destination_dir: docs/${{ github.ref_name }}
enable_jekyll: true
cname: ${{ vars.PAGES_CNAME }}
post_publish:
name: Post-publish minizinc-js
runs-on: ubuntu-latest
needs: [publish]
steps:
- name: Purge jsDelivr edge cache
if: ${{ github.ref_name == 'develop' }}
uses: gacts/purge-jsdelivr-cache@v1
with:
url: |
https://cdn.jsdelivr.net/npm/minizinc@edge/dist/minizinc.js
https://cdn.jsdelivr.net/npm/minizinc@edge/dist/minizinc.mjs
https://cdn.jsdelivr.net/npm/minizinc@edge/dist/minizinc-worker.js
https://cdn.jsdelivr.net/npm/minizinc@edge/dist/minizinc.wasm
https://cdn.jsdelivr.net/npm/minizinc@edge/dist/minizinc.data
- name: Purge jsDelivr latest cache
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
uses: gacts/purge-jsdelivr-cache@v1
with:
url: |
https://cdn.jsdelivr.net/npm/minizinc/dist/minizinc.js
https://cdn.jsdelivr.net/npm/minizinc/dist/minizinc.mjs
https://cdn.jsdelivr.net/npm/minizinc/dist/minizinc-worker.js
https://cdn.jsdelivr.net/npm/minizinc/dist/minizinc.wasm
https://cdn.jsdelivr.net/npm/minizinc/dist/minizinc.data