Skip to content

Build and publish release artefacts (Docker) #730

Build and publish release artefacts (Docker)

Build and publish release artefacts (Docker) #730

# Workflow to build and publish the libzim ASM and WASM arttefacts together with the JavaScript wrapper.
# If this workflow is triggered by the creation of a draft release, then the artefacts are uploaded to the release assets.
# If it is triggered by a push or pull request to main, or manually, then the artefacts are archived under the corresponding Action.
name: Build and publish release artefacts (Docker)
on:
schedule:
# Nightly run at 02:21 UTC
- cron: '21 02 * * *'
push:
branches: [ main ]
tags:
- 'v*' # Tag push events matching v*, i.e. v1.0, v20.15.10
pull_request:
branches: [ main ]
workflow_dispatch:
inputs:
version:
description: |
If you wish to create a draft release, set the tag version, like v9.9.9 (must not be an exisitng tag).
If left blank or incorrect format, archives will be archived instead of being uploaded to Releases.
required: false
default: ''
buildtype:
description: |
Choose the build type - 'source' (from source code, i.e., built from scratch - this takes a long time),
'release' (from libzim released binary and dependencies - recommended), or 'nightly' (from the latest libzim
nightly release)
type: choice
options:
- source
- release
- nightly
default: 'release'
required: true
# Define top-level environment vars we can refer to below
env:
VERSION: ${{ github.ref_name }}
DISPATCH_VERSION: ${{ github.event.inputs.version }}
DISPATCH_TYPE: ${{ github.event.inputs.buildtype }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SSH_KEY: ${{ secrets.SSH_KEY }}
BUILD_TYPE: ${{ github.event.inputs.buildtype }}
jobs:
build:
name: Build and publish W/ASM artefacts
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# Customizes the Emscripten docker container via the Dockerfile in this repo
- name: Build the Docker image
run: |
# Sometimes it might be necessary to use a different version of EMSDK for different scenarios
if [[ $BUILD_TYPE =~ 'source' ]]; then
BUILD_VERSION='3.1.41'
else
BUILD_VERSION='3.1.41'
fi
docker build -t "docker-emscripten-libzim:v3" ./docker --build-arg VERSION=$BUILD_VERSION
# If we're building release version
- name: Build release from libzim binaries
if: github.event_name == 'pull_request' || github.event_name == 'push' || github.event.inputs.buildtype == 'release'
run: |
make libzim_release
docker run --rm -v $(pwd):/src -u $(id -u):$(id -g) docker-emscripten-libzim:v3 make release
# If we're building nightly version
- name: Build nightly from libzim binaries
if: github.event.schedule || github.event.inputs.buildtype == 'nightly'
run: |
make libzim_nightly
docker run --rm -v $(pwd):/src -u $(id -u):$(id -g) docker-emscripten-libzim:v3 make nightly
# Creates the ASM and WASM artefacts, and the JS wrappers, using the Makefile in this repo
- name: Compile the libzim WASM artefacts from source
if: github.event.inputs.buildtype == 'source'
run: docker run --rm -v $(pwd):/src -u $(id -u):$(id -g) docker-emscripten-libzim:v3 make
- name: List directories with updated archives
run: |
echo -e "\nList ./ :"
ls -l
echo -e "\nList ./tests/prototype/ :"
ls -l tests/prototype/
echo -e "\nList ./tests/test_large_file_access/ :"
ls -l tests/test_large_file_access/
# If we are not creating a release, archive the artefacts under this Action run
- name: Archive build artefacts
if: |
github.event_name == 'pull_request' || github.event_name == 'push' && ! startsWith(github.ref_name, 'v')
|| github.event.inputs.buildtype != 'nightly' && ! github.event.schedule && ! startsWith(github.event.inputs.version, 'v')
uses: actions/upload-artifact@v3
with:
name: libzim-wasm-artefacts
path: |
libzim-wasm.*
libzim-asm.*
tests/test_large_file_access/large_file_access.*
# Test that these binaries work with the prototype
- name: Test the libzim WASM artefacts with the prototype
run: |
npm ci
npm test
# If it's a release, zip the artefacts into respective packages (asm and wasm), create and upload releases
- name: Zip the artefacts and create draft release
id: zip-release
if: github.event_name == 'push' && startsWith(github.ref_name, 'v') || startsWith(github.event.inputs.version, 'v')
run: |
if [[ ! $VERSION =~ ^v?[0-9.]+ ]]; then
VERSION=$DISPATCH_VERSION
fi
# Create a draft release and upload zipped artefacts as release assets
chmod +x ./scripts/create_draft_release.sh
./scripts/create_draft_release.sh
# If it's a nightly build, zip artefacts and upload releases
- name: Zip the artefacts and upload to nightly
if: github.event.schedule || github.event.inputs.buildtype == 'nightly'
run: |
echo "$SSH_KEY" > ./scripts/ssh_key
chmod 600 ./scripts/ssh_key
CURRENT_DATE=$(date +'%Y-%m-%d')
target="/data/openzim/nightly/$CURRENT_DATE"
zip libzim-javascript_wasm_$CURRENT_DATE.zip libzim-wasm.*
zip libzim-javascript_asm_$CURRENT_DATE.zip libzim-asm.*
for FILE in "libzim-javascript_wasm_$CURRENT_DATE.zip" "libzim-javascript_asm_$CURRENT_DATE.zip"
do
echo "Copying $FILE to $target"
scp -P 30022 -o StrictHostKeyChecking=no -i ./scripts/ssh_key "$FILE" [email protected]:$target
done