Release 1.0.0 #112
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: CMake on multiple platforms | |
on: | |
push: | |
branches: ["main"] | |
pull_request: null | |
workflow_dispatch: | |
inputs: | |
logLevel: | |
description: "Log level" | |
required: true | |
default: "warning" | |
type: choice | |
options: | |
- info | |
- warning | |
- debug | |
jobs: | |
build: | |
runs-on: ${{ matrix.os }} | |
strategy: | |
# Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable. | |
fail-fast: false | |
# Set up a matrix to run the following 3 configurations: | |
# 1. <Windows, Release, latest MSVC compiler toolchain on the default runner image, default generator> | |
# 2. <Linux, Release, latest GCC compiler toolchain on the default runner image, default generator> | |
# 3. <macOS, Release, latest Clang compiler toolchain on the macos-13 runner image, default generator> | |
# | |
# To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list. | |
matrix: | |
os: [macos-13, ubuntu-latest, windows-latest] | |
build_type: [Release] | |
c_compiler: [gcc] | |
include: | |
- os: windows-latest | |
c_compiler: cl | |
cpp_compiler: cl | |
build_type: Release | |
- os: macos-13 | |
arch: x64 | |
c_compiler: gcc | |
cpp_compiler: g++ | |
- os: ubuntu-latest | |
c_compiler: gcc | |
cpp_compiler: g++ | |
exclude: | |
- os: windows-latest | |
c_compiler: gcc | |
- os: windows-latest | |
c_compiler: clang | |
- os: ubuntu-latest | |
c_compiler: cl | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set reusable strings | |
# Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file. | |
id: strings | |
shell: bash | |
run: | | |
if [[ "${{ runner.os }}" == "Windows" ]]; then | |
echo "build-output-dir=${{ github.workspace }}\build" >> "$GITHUB_OUTPUT" | |
else | |
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" | |
fi | |
- name: Install oneDNN | |
if: runner.os == 'macOS' | |
run: brew install onednn | |
- name: Add Oracular repository | |
if: runner.os == 'Linux' | |
run: | | |
echo "deb http://archive.ubuntu.com/ubuntu oracular main restricted universe multiverse" | sudo tee /etc/apt/sources.list.d/oracular.list | |
- name: Update package lists | |
if: runner.os == 'Linux' | |
run: sudo apt update | |
- name: Install libdnnl-dev from oracular | |
if: runner.os == 'Linux' | |
run: sudo apt install -t oracular -y libdnnl-dev | |
- name: Pin libdnnl-dev | |
if: runner.os == 'Linux' | |
run: | | |
echo "Package: libdnnl-dev" | sudo tee /etc/apt/preferences.d/pin-oracular-package | |
echo "Pin: release n=oracular" | sudo tee -a /etc/apt/preferences.d/pin-oracular-package | |
echo "Pin-Priority: 1001" | sudo tee -a /etc/apt/preferences.d/pin-oracular-package | |
- name: Verify dependencies | |
if: runner.os == 'macOS' | |
run: | | |
brew list icu4c | |
brew list onednn | |
echo "ICU4C include directory: $(brew --prefix icu4c)/include" | |
echo "ICU4C library directory: $(brew --prefix icu4c)/lib" | |
echo "oneDNN include directory: $(brew --prefix onednn)/include" | |
echo "oneDNN library directory: $(brew --prefix onednn)/lib" | |
- name: Download ICU on Windows | |
if: runner.os == 'Windows' | |
run: | | |
curl.exe -L -O https://github.com/unicode-org/icu/releases/download/release-74-2/icu4c-74_2-src.zip --ssl-no-revoke | |
ls | |
Expand-Archive -Path .\icu4c-74_2-src.zip -DestinationPath c:\ | |
ls | |
- name: Install ICU on Windows | |
if: runner.os == 'Windows' | |
uses: ilammy/msvc-dev-cmd@v1 | |
- run: | | |
ls | |
cd c:\icu | |
ls | |
msbuild .\source\allinone\allinone.sln /p:Configuration=Release /p:Platform=x64 /p:SkipUWP=true | |
if: runner.os == 'Windows' | |
- name: Check ICU dir on windows | |
if: runner.os == 'Windows' | |
shell: pwsh | |
run: | | |
echo "ls c:\icu" | |
ls c:\icu | |
echo "ls c:\icu\bin64" | |
ls c:\icu\bin64 | |
- name: Install onednn on Windows | |
if: runner.os == 'Windows' | |
run: | | |
curl.exe -L -O https://github.com/oneapi-src/oneDNN/archive/refs/tags/v3.5.tar.gz --ssl-no-revoke | |
tar xf .\v3.5.tar.gz | |
ls | |
cd oneDNN-3.5 | |
cmake -DCMAKE_BUILD_TYPE=Release -DONEDNN_LIBRARY_TYPE=SHARED -DONEDNN_BUILD_EXAMPLES=OFF -DONEDNN_BUILD_TESTS=OFF -DONEDNN_ENABLE_WORKLOAD=INFERENCE -DONEDNN_ENABLE_PRIMITIVE="CONVOLUTION;REORDER" -DONEDNN_BUILD_GRAPH=OFF . | |
cmake --build . --config Release --target install --parallel 6 | |
- name: Configure CMake Unix | |
if: runner.os != 'Windows' | |
run: | | |
if [ "$RUNNER_OS" == "macOS" ]; then | |
export ICU_ROOT=$(brew --prefix icu4c) | |
export CMAKE_PREFIX_PATH=$ICU_ROOT | |
export PKG_CONFIG_PATH=$ICU_ROOT/lib/pkgconfig:$PKG_CONFIG_PATH | |
export LDFLAGS="-L$ICU_ROOT/lib $LDFLAGS" | |
export CPPFLAGS="-I$ICU_ROOT/include $CPPFLAGS" | |
export PATH="$ICU_ROOT/bin:$PATH" | |
fi | |
cmake -B ${{ steps.strings.outputs.build-output-dir }} -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -S ${{ github.workspace }} | |
- name: Configure CMake Windows | |
if: runner.os == 'Windows' | |
shell: pwsh | |
run: | | |
$env:INCLUDE = "C:\Program Files (x86)\oneDNN\include;c:\icu\include;$env:INCLUDE" | |
$env:LIB = "C:\Program Files (x86)\oneDNN\lib;C:\Program Files (x86)\oneDNN\bin;C:\icu\lib64;$env:LIB" | |
$env:PATH = "C:\icu\bin64;$env:PATH" | |
echo "LIB: $env:LIB" | |
echo "INCLUDE: $env:INCLUDE" | |
echo "Build type: ${{ matrix.build_type }}" | |
cmake -B ${{ steps.strings.outputs.build-output-dir }} -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -S ${{ github.workspace }} | |
- name: Build Unix | |
if: runner.os != 'Windows' | |
# Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). | |
run: | | |
if [ "$RUNNER_OS" == "macOS" ]; then | |
export ICU_ROOT=$(brew --prefix icu4c) | |
export CMAKE_PREFIX_PATH=$ICU_ROOT | |
export PKG_CONFIG_PATH=$ICU_ROOT/lib/pkgconfig:$PKG_CONFIG_PATH | |
export LDFLAGS="-L$ICU_ROOT/lib $LDFLAGS" | |
export CPPFLAGS="-I$ICU_ROOT/include $CPPFLAGS" | |
export PATH="$ICU_ROOT/bin:$PATH" | |
fi | |
cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} --parallel 6 | |
- name: Build Windows | |
if: runner.os == 'Windows' | |
run: | | |
$env:INCLUDE = "C:\Program Files (x86)\oneDNN\include;c:\icu\include;$env:INCLUDE" | |
$env:LIB = "C:\Program Files (x86)\oneDNN\lib;C:\Program Files (x86)\oneDNN\bin;C:\icu\lib64;$env:LIB" | |
$env:PATH = "C:\icu\bin64;$env:PATH" | |
echo "LIB: $env:LIB" | |
echo "INCLUDE: $env:INCLUDE" | |
echo "Build type: ${{ matrix.build_type }}" | |
$env:CMAKE_PREFIX_PATH = "C:\Program Files (x86)\oneDNN;C:\icu;C:\icu\bin64" | |
cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} --parallel 6 | |
- name: Test | |
working-directory: ${{ steps.strings.outputs.build-output-dir }} | |
# Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). | |
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail | |
run: ctest --build-config ${{ matrix.build_type }} | |
- name: Copy necessary .dylib files | |
if: runner.os == 'macOS' | |
run: | | |
mkdir -p ${{ steps.strings.outputs.build-output-dir }}/lib | |
cp ${{ steps.strings.outputs.build-output-dir }}/libmetaltranslate.dylib ${{ steps.strings.outputs.build-output-dir }}/lib/ | |
cp ${{ steps.strings.outputs.build-output-dir }}/libdnnl.3.5.dylib ${{ steps.strings.outputs.build-output-dir }}/lib/libdnnl.3.dylib | |
cp ${{ steps.strings.outputs.build-output-dir }}/libicuuc.74.2.dylib ${{ steps.strings.outputs.build-output-dir }}/lib/libicuuc.74.dylib | |
cp ${{ steps.strings.outputs.build-output-dir }}/libicudata.74.2.dylib ${{ steps.strings.outputs.build-output-dir }}/lib/libicudata.74.dylib | |
cp ${{ steps.strings.outputs.build-output-dir }}/external/lib/libctranslate2.4.3.1.dylib ${{ steps.strings.outputs.build-output-dir }}/lib/libctranslate2.4.dylib | |
cp ${{ steps.strings.outputs.build-output-dir }}/external/lib/libOpenNMTTokenizer.dylib ${{ steps.strings.outputs.build-output-dir }}/lib/ | |
cd ${{ steps.strings.outputs.build-output-dir }} | |
- name: Copy necessary .so files | |
if: runner.os == 'Linux' | |
run: | | |
mkdir -p ${{ steps.strings.outputs.build-output-dir }}/lib | |
cp ${{ steps.strings.outputs.build-output-dir }}/libmetaltranslate.so ${{ steps.strings.outputs.build-output-dir }}/lib/ | |
cp ${{ steps.strings.outputs.build-output-dir }}/libdnnl.so ${{ steps.strings.outputs.build-output-dir }}/lib/ | |
cp ${{ steps.strings.outputs.build-output-dir }}/libctranslate2.so ${{ steps.strings.outputs.build-output-dir }}/lib/ | |
cp ${{ steps.strings.outputs.build-output-dir }}/libOpenNMTTokenizer.so ${{ steps.strings.outputs.build-output-dir }}/lib/ | |
cd ${{ steps.strings.outputs.build-output-dir }} | |
- name: Copy necessary .dll files | |
if: runner.os == 'Windows' | |
run: | | |
New-Item -Path "${{ steps.strings.outputs.build-output-dir }}\lib" -ItemType Directory | |
Copy-Item -Path "${{ steps.strings.outputs.build-output-dir }}\bin\Release\metaltranslate.dll" -Destination "${{ steps.strings.outputs.build-output-dir }}\lib\" -Force | |
Copy-Item -Path "${{ steps.strings.outputs.build-output-dir }}\external\bin\ctranslate2.dll" -Destination "${{ steps.strings.outputs.build-output-dir }}\lib\" -Force | |
Copy-Item -Path "${{ steps.strings.outputs.build-output-dir }}\external\bin\OpenNMTTokenizer.dll" -Destination "${{ steps.strings.outputs.build-output-dir }}\lib\" -Force | |
Copy-Item -Path "c:\icu\bin64\icudt74.dll" -Destination "${{ steps.strings.outputs.build-output-dir }}\lib\" -Force | |
Copy-Item -Path "c:\icu\bin64\icuuc74.dll" -Destination "${{ steps.strings.outputs.build-output-dir }}\lib\" -Force | |
Copy-Item -Path "c:\Program Files (x86)\oneDNN\bin\dnnl.dll" -Destination "${{ steps.strings.outputs.build-output-dir }}\lib\" -Force | |
- name: Upload ZIP artifact for macOS | |
if: runner.os == 'macOS' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: darwin-x64 | |
path: ${{ steps.strings.outputs.build-output-dir }}/lib/*.dylib | |
- name: Upload ZIP artifact for Linux | |
if: runner.os == 'Linux' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: linux-x64 | |
path: ${{ steps.strings.outputs.build-output-dir }}/lib/*.so | |
- name: Upload ZIP artifact for Windows | |
if: runner.os == 'Windows' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: win32-x64 | |
path: ${{ steps.strings.outputs.build-output-dir }}\lib\*.dll | |
check_version: | |
name: Commit check | |
runs-on: ubuntu-latest | |
outputs: | |
contains_version: ${{ steps.check_message.outputs.contains_version }} | |
version_number: ${{ steps.check_message.outputs.version_number }} | |
steps: | |
- name: Check commit message for version number | |
id: check_message | |
shell: bash | |
run: | | |
if [[ "${{ github.event.head_commit.message }}" =~ ([0-9]+\.[0-9]+\.[0-9]+) ]]; then | |
echo "Commit message contains a version number." | |
echo "contains_version=true" >> $GITHUB_OUTPUT | |
echo "version_number=${BASH_REMATCH[1]}" >> $GITHUB_OUTPUT | |
else | |
echo "Commit message does not contain a version number." | |
echo "contains_version=false" >> $GITHUB_OUTPUT | |
fi | |
publish: | |
name: Publish | |
runs-on: ubuntu-latest | |
needs: | |
- build | |
- check_version | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Setup node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 18 | |
check-latest: true | |
- name: Install dependencies | |
run: | | |
cd nodejs | |
npm ci | |
- name: Download all artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
path: artifacts | |
- name: Check current location | |
run: ls | |
- name: Move Artifacts | |
run: mv ./artifacts ./nodejs/lib | |
- name: Check after move | |
run: ls | |
- name: Initialize Git user | |
run: | | |
git config --global user.email "[email protected]" | |
git config --global user.name "Release Workflow" | |
- name: Initialise the NPM config | |
run: npm config set //registry.npmjs.org/:_authToken $NPM_TOKEN | |
env: | |
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | |
- name: Run release | |
run: | | |
cd nodejs | |
if [ "${{ needs.check_version.outputs.contains_version }}" == "true" ]; then | |
npm run release ${{ needs.check_version.outputs.version_number }} | |
else | |
npm run release --ci | |
fi | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN}} | |
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |