Build, test, release #676
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |