Skip to content

Commit

Permalink
experiment with reusable build workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
mmomtchev committed Sep 27, 2024
1 parent dfe94cb commit f31d2bf
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 63 deletions.
107 changes: 107 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: Build & test magickwand.js

on:
workflow_dispatch:
inputs:
platform:
type: string
required: true
dependencies:
type: string
default: 'conan'
description: dependencies origin ('conan' or 'system')
native:
type: boolean
required: true
description: build the native module
wasm:
type: boolean
required: true
description: build the WASM module
integration:
type: string
required: true
description: integration tests to run ('node' and/or 'browser')
light:
type: boolean
default: false
description: do not expect that all delegates are included
extralight:
type: boolean
default: false
description: do not expect the PNG delegate
install_cmd:
type: string
description: install command to use for the integration tests

jobs:
build:
name: Build & test ${{ inputs.wasm && 'WASM' || '' }} ${{ inputs.native && 'native' || '' }} ${{ inputs.platform }}/${{ inputs.dependencies }}
runs-on: ${{ inputs.platform }}

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true
- name: Use Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Download the SWIG-generated wrappers
uses: actions/download-artifact@v4
with:
name: swig
path: swig
- name: Install the xpacks
run: |
npm install xpm
npx xpm install
- name: Get conan home
shell: bash
id: conan_home
run: |
npx xpm run -q conan -- version
echo path=`npx xpm run -q conan -- config home` >> $GITHUB_OUTPUT
- name: Cache conan artifacts
id: conan-artifacts
uses: actions/cache@v4
with:
path: ${{ steps.conan_home.outputs.path }}
key: conan-${{ inputs.platform }}
- name: Install fonts on Ubuntu
run: sudo apt-get install -y fonts-ubuntu || true
if: startsWith(inputs.platform, 'ubuntu')
- name: Install libpng-dev and libjpeg-dev on Ubuntu 24.04
run: sudo apt-get install -y libpng-dev libjpeg-dev
if: inputs.platform == 'ubuntu-24.04' && inputs.dependencies == 'system'
- name: Do not use GHA pkg-config on Windows
shell: bash
run: rm `which pkg-config`*
if: runner.os == 'Windows'
- name: Build magickwand.js
run: |
npm install --verbose --foreground-scripts \
${{ inputs.native && '--build-from-source' || '--skip-magickwand-native' }}
${{ inputs.wasm && '--build-wasm-from-source' || '--skip-magickwand-wasm' }}
${{ inputs.dependencies == 'conan' && '--enable-conan' || '--disable-conan' }}
# Because of https://github.com/mmomtchev/hadron/issues/37
env:
C_INCLUDE_PATH: /usr/local/include
CPLUS_INCLUDE_PATH: /usr/local/include
- name: Locate addon file
shell: bash
id: addon
run: node -p '"addon=" + path.resolve(__dirname, "lib", "binding", `${os.platform()}-${os.arch()}`, "magickwand.node")' >> $GITHUB_OUTPUT
- name: List linked libraries (Linux)
run: ldd ${{ steps.addon.outputs.addon }}
if: runner.os == 'Linux'
- name: List linked libraries (macOS)
run: otool -L ${{ steps.addon.outputs.addon }}
if: runner.os == 'macOS'
- run: npx mocha test/node.test.ts test/integration.test.ts
env:
MOCHA_INTEGRATION: ${{ inputs.integration }}
MOCHA_MAGICK_INSTALL: ${{ inputs.install }}
MOCHA_LIGHT: ${{ inputs.light }}
MOCHA_EXTRALIGHT: ${{ inputs.extralight }}
73 changes: 10 additions & 63 deletions .github/workflows/test-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ jobs:
path: swig/*

native:
runs-on: ${{ matrix.platform }}
needs: swig

strategy:
Expand All @@ -71,68 +70,16 @@ jobs:
- system
- conan

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true
- name: Use Node.js 18.x
uses: actions/setup-node@v4
with:
node-version: 18.x
- name: Download the SWIG-generated wrappers
uses: actions/download-artifact@v4
with:
name: swig
path: swig
- name: Install the xpacks
run: |
npm install xpm
npx xpm install
- name: Get conan home
shell: bash
id: conan_home
run: |
npx xpm run -q conan -- version
echo path=`npx xpm run -q conan -- config home` >> $GITHUB_OUTPUT
- name: Cache conan artifacts
id: conan-artifacts
uses: actions/cache@v4
with:
path: ${{ steps.conan_home.outputs.path }}
key: conan-${{ matrix.platform }}
- name: Install fonts on Ubuntu
run: sudo apt-get install -y fonts-ubuntu || true
if: startsWith(matrix.platform, 'ubuntu')
- name: Install libpng-dev and libjpeg-dev on Ubuntu 24.04
run: sudo apt-get install -y libpng-dev libjpeg-dev
if: matrix.platform == 'ubuntu-24.04' && matrix.dependencies == 'system'
- name: Do not use GHA pkg-config on Windows
shell: bash
run: rm `which pkg-config`*
if: runner.os == 'Windows'
- name: Build magickwand.js
run: npm install --build-from-source --verbose --foreground-scripts --skip-magickwand-wasm ${{ matrix.dependencies == 'conan' && '--enable-conan' || '--disable-conan' }}
# Because of https://github.com/mmomtchev/hadron/issues/37
env:
C_INCLUDE_PATH: /usr/local/include
CPLUS_INCLUDE_PATH: /usr/local/include
- name: Locate addon file
shell: bash
id: addon
run: node -p '"addon=" + path.resolve(__dirname, "lib", "binding", `${os.platform()}-${os.arch()}`, "magickwand.node")' >> $GITHUB_OUTPUT
- name: List linked libraries (Linux)
run: ldd ${{ steps.addon.outputs.addon }}
if: runner.os == 'Linux'
- name: List linked libraries (macOS)
run: otool -L ${{ steps.addon.outputs.addon }}
if: runner.os == 'macOS'
- run: npx mocha test/node.test.ts test/integration.test.ts
env:
MOCHA_INTEGRATION: node
MOCHA_MAGICK_INSTALL: "node -e \"fs.symlinkSync(process.env.GITHUB_WORKSPACE, path.resolve('node_modules', 'magickwand.js'), os.platform() == 'win32' ? 'junction': 'dir')\""
MOCHA_LIGHT: ${{ matrix.dependencies == 'conan' && '' || '1' }}
MOCHA_EXTRALIGHT: ${{ (matrix.dependencies == 'system' && runner.os == 'Windows') && '1' || '' }}
uses:
mmomtchev/magickwand.js/.github/workflows/build.yml@${{ github.ref_name }}

with:
platform: ${{ matrix.platform }}
dependencies: ${{ matrix.dependencies }}
integration: 'node'
install_cmd: "node -e \"fs.symlinkSync(process.env.GITHUB_WORKSPACE, path.resolve('node_modules', 'magickwand.js'), os.platform() == 'win32' ? 'junction': 'dir')\""
light: ${{ matrix.dependencies == 'conan' && '' || '1' }}
extralight: ${{ matrix.dependencies == 'system' && startsWith(matrix.platform, 'windows') }}

native-light:
runs-on: ${{ matrix.platform }}
Expand Down

0 comments on commit f31d2bf

Please sign in to comment.