Skip to content

Updated workflow to mozilla sccache-action v0.0.5 #66

Updated workflow to mozilla sccache-action v0.0.5

Updated workflow to mozilla sccache-action v0.0.5 #66

Workflow file for this run

name: Build NN Inference Template
on:
workflow_dispatch: # lets you run a build from github.com
# Runs the workflow on push events but only for the develop branch
push:
branches:
- main
- develop
# This is needed otherwise the github.ref is not set with ref/tags/v...
tags:
- 'v*.*.*'
# When pushing new commits, cancel any running builds on that branch
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
env:
PROJECT_NAME: nn-inference-template
TARGET_NAME: NN_Inference_Template
RELEASE_NAME: "NN Inference Template"
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release
# Use up to 4 cpus to build juceaide, etc
CMAKE_BUILD_PARALLEL_LEVEL: 4
# Name of the build directory
BUILD_DIR: build
# Needed for mozilla sccache action
SCCACHE_GHA_ENABLED: "true"
jobs:
build:
name: ${{ matrix.name }}
strategy:
fail-fast: false # show all errors for each platform (vs. cancel jobs on error)
matrix:
include:
- name: Linux-x86_64
os: ubuntu-latest
- name: macOS-x86_64
os: macOS-latest
- name: macOS-arm64
os: macOS-latest
- name: Windows-x86_64
os: windows-latest
runs-on: ${{ matrix.os }}
steps:
#A simple printout of the matrix
- name: printout
shell: bash
run: |
echo ${{ github.ref }}
echo "TARGET_NAME=${{ env.TARGET_NAME }}";
echo "RELEASE_NAME=${{ env.RELEASE_NAME }}";
echo "matrix.name=${{ matrix.name }}";
echo "matrix.os=${{ matrix.os }}";
# We need the osxutils to get the codesign and notorization tools
# We need to install ccache here for Windows to grab the right version
- name: install deps
shell: bash
run: |
if [ "${{ matrix.name }}" == "Linux-x86_64" ]; then
sudo apt-get update && sudo apt install libasound2-dev libx11-dev libxcomposite-dev libxcursor-dev libxext-dev libxinerama-dev libxrandr-dev libxrender-dev ninja-build
elif [ "${{ matrix.name }}" == "macOS-x86_64" ]; then
brew install osxutils ninja
echo "brew prefix: $(brew --prefix)"
elif [ "${{ matrix.name }}" == "macOS-arm64" ]; then
if [ "$(uname -m)" == "arm64" ]; then
brew install libomp
fi;
brew install osxutils ninja
echo "brew prefix: $(brew --prefix)"
elif [ "${{ matrix.name }}" == "Windows-x86_64" ]; then
choco install ninja
else
echo "Unknown OS";
fi;
# With this we checkout to our repo
- name: get repo and submodules
uses: actions/checkout@v4
# Here we get the submodules like juce
with:
submodules: true
# We cache the build to speed up the build process
- name: cache the build
uses: mozilla-actions/[email protected]
# Typical cmake configuration with default generator
# With DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" we can build universal binaries for apple computers, but for this we would also need universal libs
- name: cmake configure
shell: bash
run: |
if [ "${{ matrix.name }}" == "Linux-x86_64" ]; then
cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache -DNNITEMPLATE_WITH_INSTALL=ON
elif [ "${{ matrix.name }}" == "macOS-x86_64" ]; then
cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache -DCMAKE_OSX_ARCHITECTURES="x86_64" -DNNITEMPLATE_WITH_INSTALL=ON
elif [ "${{ matrix.name }}" == "macOS-arm64" ]; then
cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache -DCMAKE_OSX_ARCHITECTURES="arm64" -DNNITEMPLATE_WITH_INSTALL=ON
else
cmake -B build -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache -DNNITEMPLATE_WITH_INSTALL=ON
fi;
# Build the project
- name: cmake build
shell: bash
run: cmake --build build --config ${{ env.BUILD_TYPE }} --parallel ${{ env.CMAKE_BUILD_PARALLEL_LEVEL }}
# Test the project
- name: install target
shell: bash
run: cmake --install build
- name: define the current version
shell: bash
run: |
version=$(grep 'CMAKE_PROJECT_VERSION:STATIC' build/CMakeCache.txt | cut -d'=' -f2)
echo "VERSION_NUMBER=${version}" >> $GITHUB_ENV
echo "current version number: ${version}"
# Declaring the product name and the packaging directory
- name: declare artefact variables
shell: bash
run: |
echo "PACKAGE_DIR=artefacts/${{ env.PROJECT_NAME }}-${{ env.VERSION_NUMBER }}-${{ matrix.name }}" >> $GITHUB_ENV
echo "PRODUCT_NAME=${{ env.PROJECT_NAME }}-${{ env.VERSION_NUMBER }}-${{ matrix.name }}" >> $GITHUB_ENV
# Moving the artefacts to a packaging directory
- name: move artefacts
shell: bash
run: |
mkdir -p ${{ env.PACKAGE_DIR }}
rm -r ${{ env.BUILD_DIR }}/${{ env.TARGET_NAME }}-${{ env.VERSION_NUMBER }}/lib/cmake
# Add the libs
if [ "${{ matrix.name }}" == "Linux-x86_64" ]; then
mv ${{ env.BUILD_DIR }}/${{ env.TARGET_NAME }}-${{ env.VERSION_NUMBER }}/bin ${{ env.PACKAGE_DIR }};
mv "${{ env.BUILD_DIR }}/${{ env.TARGET_NAME }}_artefacts/${{ env.BUILD_TYPE }}/VST3/${{ env.RELEASE_NAME }}.vst3" ${{ env.PACKAGE_DIR }};
mv "${{ env.BUILD_DIR }}/${{ env.TARGET_NAME }}-${{ env.VERSION_NUMBER }}/lib/${{ env.RELEASE_NAME }}.so" "${{ env.PACKAGE_DIR }}/${{ env.RELEASE_NAME }}.vst3/Contents/x86_64-linux/"
mv ${{ env.BUILD_DIR }}/${{ env.TARGET_NAME }}-${{ env.VERSION_NUMBER }}/lib ${{ env.PACKAGE_DIR }}
cp -r ${{ env.PACKAGE_DIR }}/lib "${{ env.PACKAGE_DIR }}/${{ env.RELEASE_NAME }}.vst3/Contents/"
elif [ "${{ matrix.os }}" == "macOS-latest" ]; then
mv ${{ env.BUILD_DIR }}/${{ env.TARGET_NAME }}-${{ env.VERSION_NUMBER }}/bin/* ${{ env.PACKAGE_DIR }};
mv "${{ env.BUILD_DIR }}/${{ env.TARGET_NAME }}-${{ env.VERSION_NUMBER }}/lib/${{ env.RELEASE_NAME }}.vst3" ${{ env.PACKAGE_DIR }}/
mv "${{ env.BUILD_DIR }}/${{ env.TARGET_NAME }}-${{ env.VERSION_NUMBER }}/lib/${{ env.RELEASE_NAME }}.component" ${{ env.PACKAGE_DIR }}/
# for macOS the libs are added after codesigning
elif [ "${{ matrix.name }}" == "Windows-x86_64" ]; then
mkdir -p ${{ env.PACKAGE_DIR }}/lib
mv ${{ env.BUILD_DIR }}/${{ env.TARGET_NAME }}-${{ env.VERSION_NUMBER }}/bin/*.exe ${{ env.PACKAGE_DIR }}/;
mv ${{ env.BUILD_DIR }}/${{ env.TARGET_NAME }}-${{ env.VERSION_NUMBER }}/lib/*.vst3 ${{ env.PACKAGE_DIR }}/;
mv ${{ env.BUILD_DIR }}/${{ env.TARGET_NAME }}-${{ env.VERSION_NUMBER }}/lib/*.dll ${{ env.PACKAGE_DIR }}/lib/;
else
echo "Unknown OS";
fi;
- name: copy models to package
shell: bash
run: |
mkdir -p ${{ env.PACKAGE_DIR }}/extras/nn-inference-template/GuitarLSTM/pytorch-version/models/model_0
mkdir -p ${{ env.PACKAGE_DIR }}/extras/nn-inference-template/GuitarLSTM/tensorflow-version/models/model_0
cp modules/GuitarLSTM/pytorch-version/models/model_0/*.pt ${{ env.PACKAGE_DIR }}/extras/nn-inference-template/GuitarLSTM/pytorch-version/models/model_0/
cp modules/GuitarLSTM/pytorch-version/models/model_0/*.onnx ${{ env.PACKAGE_DIR }}/extras/nn-inference-template/GuitarLSTM/pytorch-version/models/model_0/
cp modules/GuitarLSTM/tensorflow-version/models/model_0/*.tflite ${{ env.PACKAGE_DIR }}/extras/nn-inference-template/GuitarLSTM/tensorflow-version/models/model_0/
cp modules/GuitarLSTM/tensorflow-version/models/model_0/*.onnx ${{ env.PACKAGE_DIR }}/extras/nn-inference-template/GuitarLSTM/tensorflow-version/models/model_0/
- name: copy install instructions
shell: bash
run: |
if [ "${{ matrix.name }}" == "Linux-x86_64" ]; then
cp assets/docs/install_linux.md ${{ env.PACKAGE_DIR }}/README.md
elif [ "${{ matrix.os }}" == "macOS-latest" ]; then
cp assets/docs/install_mac.md ${{ env.PACKAGE_DIR }}/README.md
elif [ "${{ matrix.name }}" == "Windows-x86_64" ]; then
cp assets/docs/install_win.md ${{ env.PACKAGE_DIR }}/README.md
else
echo "Unknown OS";
fi;
# We need to import the apple developer certificate so that we can codesign our binaries
- name: import certificates (macOS)
uses: apple-actions/import-codesign-certs@v2
if: ${{ matrix.os == 'macOS-latest' }}
with:
# GitHub encrypted secrets
p12-file-base64: ${{ secrets.DEV_ID_APP_CERT }}
p12-password: ${{ secrets.DEV_ID_APP_PWD }}
# Codesigning all the binaries
- name: codesign (macOS)
if: ${{ matrix.os == 'macOS-latest' }}
run: |
# codesign all libs
codesign --force -s "${{ secrets.DEV_ID_APP }}" -v ${{ env.BUILD_DIR }}/${{ env.TARGET_NAME }}-${{ env.VERSION_NUMBER }}/lib/*.dylib --deep --strict --options=runtime --timestamp;
# Then we add the libs to the bundles
cp -r "${{ env.BUILD_DIR }}/${{ env.TARGET_NAME }}-${{ env.VERSION_NUMBER }}/lib" "${{ env.PACKAGE_DIR }}/${{ env.RELEASE_NAME }}.vst3/Contents/"
cp -r "${{ env.BUILD_DIR }}/${{ env.TARGET_NAME }}-${{ env.VERSION_NUMBER }}/lib" "${{ env.PACKAGE_DIR }}/${{ env.RELEASE_NAME }}.component/Contents/"
cp -r "${{ env.BUILD_DIR }}/${{ env.TARGET_NAME }}-${{ env.VERSION_NUMBER }}/lib" "${{ env.PACKAGE_DIR }}/${{ env.RELEASE_NAME }}.app/Contents/"
# codesign the plugins
codesign --force -s "${{ secrets.DEV_ID_APP }}" -v "${{ env.PACKAGE_DIR }}/${{ env.RELEASE_NAME }}.vst3" --deep --strict --options=runtime --timestamp;
codesign --force -s "${{ secrets.DEV_ID_APP }}" -v "${{ env.PACKAGE_DIR }}/${{ env.RELEASE_NAME }}.component" --deep --strict --options=runtime --timestamp;
# The standalone needs to have specific entitlements, which we need to add when we codesign the files. Since we have set the entitlements in the CMakeLists.txt we can use the generated file in the location below
codesign --entitlements "${{ env.BUILD_DIR }}/${{ env.TARGET_NAME }}_artefacts/JuceLibraryCode/${{ env.TARGET_NAME }}_Standalone.entitlements" --force -s "${{ secrets.DEV_ID_APP }}" -v "${{ env.PACKAGE_DIR }}/${{ env.RELEASE_NAME }}.app" --deep --strict --options=runtime --timestamp;
# Here we check the code signitures
codesign -dv --verbose=4 "${{ env.PACKAGE_DIR }}/${{ env.RELEASE_NAME }}.vst3";
codesign -dv --verbose=4 "${{ env.PACKAGE_DIR }}/${{ env.RELEASE_NAME }}.component";
codesign -dv --verbose=4 "${{ env.PACKAGE_DIR }}/${{ env.RELEASE_NAME }}.app";
# Zip the artefact
- name: zip artefacts
working-directory: ${{github.workspace}}/artefacts
shell: bash
run: |
if [ "${{ matrix.os }}" == "macOS-latest" ]; then
zip -vr ${{ env.PRODUCT_NAME }}.zip ${{ env.PRODUCT_NAME }}/ -x "*.DS_Store"
elif [ "${{ matrix.name }}" == "Windows-x86_64" ]; then
pwsh -command "Compress-Archive -Path '${{ env.PRODUCT_NAME }}/' -DestinationPath '${{ env.PRODUCT_NAME }}.zip'"
elif [ "${{ matrix.name }}" == "Linux-x86_64" ]; then
zip -r ${{ env.PRODUCT_NAME }}.zip ${{ env.PRODUCT_NAME }}/
else
echo "Unknown OS";
fi;
# Let's now notarize the zip file and with it all its contents / binaries
- name: notarize (macOS)
working-directory: ${{github.workspace}}/artefacts
if: ${{ matrix.os == 'macOS-latest' }}
run: |
# In contrast to dmg files zip files do not need to be codesigned before notarization
xcrun notarytool submit ${{ env.PRODUCT_NAME }}.zip --apple-id ${{ secrets.APPLE_DEV_ID }} --password ${{ secrets.APPLE_DEV_PWD }} --team-id ${{ secrets.TEAM_ID }} --wait
# Then we need to unzip it and staple the ticket for the gatekeeper to all binaries
unzip ${{ env.PRODUCT_NAME }}.zip && rm ${{ env.PRODUCT_NAME }}.zip
cd ${{ env.PRODUCT_NAME }}
xcrun stapler staple "${{ env.RELEASE_NAME }}.vst3";
xcrun stapler staple "${{ env.RELEASE_NAME }}.component";
xcrun stapler staple "${{ env.RELEASE_NAME }}.app";
cd ..
# And finally zip it again
zip -vr ${{ env.PRODUCT_NAME }}.zip ${{ env.PRODUCT_NAME }}/ -x "*.DS_Store"
- name: upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.PRODUCT_NAME }}.zip
path: artefacts/${{ env.PRODUCT_NAME }}.zip
release:
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
needs: build
steps:
- name: Get Artifacts
uses: actions/download-artifact@v4
- name: Create Release
uses: softprops/action-gh-release@v2
with:
files: |
*/*.zip