Build opus #23
This file contains hidden or 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 opus | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - master | |
| paths: | |
| - '.github/workflows/opus.yml' | |
| env: | |
| COMMON_CMAKE_FLAGS: "-DOPUS_BUILD_SHARED_LIBRARY=ON -DCMAKE_BUILD_TYPE=Release" | |
| jobs: | |
| build: | |
| name: Build opus | |
| runs-on: ${{ matrix.os }} | |
| outputs: | |
| version: ${{ steps.print-version.outputs.version }} | |
| strategy: | |
| fail-fast: false # Run the other two OSs even if one fails | |
| matrix: | |
| os: [ windows-latest, ubuntu-latest, macos-latest ] | |
| steps: | |
| - name: Clone opus repo | |
| uses: actions/checkout@v4.2.2 | |
| with: | |
| repository: DSharpPlus/opus | |
| submodules: recursive | |
| - name: Checkout latest Tag | |
| id: print-version | |
| shell: bash | |
| run: | | |
| git fetch --tags | |
| LATEST_TAG=$(git tag | grep -E ^v[0-9]+.[0-9]+.[0-9]+$ | tail -1) | |
| git checkout "$LATEST_TAG" | |
| echo "version=$LATEST_TAG" >> $GITHUB_OUTPUT | |
| - name: Build opus | |
| shell: bash | |
| run: | | |
| if [[ "${{ matrix.os }}" == "windows-latest" ]]; then | |
| for arch in x64 ARM64; do # We dont want Win32 | |
| mkdir -p output/$arch | |
| mkdir build-$arch | |
| cd build-$arch | |
| cmake $COMMON_CMAKE_FLAGS -A $arch .. | |
| cmake --build . -j 4 --config Release | |
| cp Release/opus.dll ../output/$arch/libopus.dll | |
| cd .. | |
| done | |
| elif [[ "${{ matrix.os }}" == "ubuntu-latest" ]]; then | |
| for arch in x64 ARM64; do | |
| mkdir -p output/$arch | |
| mkdir build-$arch | |
| cd build-$arch | |
| if [[ "$arch" == "ARM64" ]]; then | |
| sudo apt update | |
| sudo apt install cmake gcc-aarch64-linux-gnu g++-aarch64-linux-gnu | |
| cmake $COMMON_CMAKE_FLAGS -DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc -DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++ .. | |
| else | |
| cmake $COMMON_CMAKE_FLAGS .. | |
| fi | |
| cmake --build . -j 4 | |
| cp libopus.so ../output/$arch/libopus.so | |
| cd .. | |
| done | |
| elif [[ "${{ matrix.os }}" == "macos-latest" ]]; then | |
| mkdir build output | |
| cd build | |
| cmake $COMMON_CMAKE_FLAGS "-DCMAKE_OSX_ARCHITECTURES=arm64;arm64e;x86_64;x86_64h" .. | |
| cmake --build . -j 4 --config Release | |
| cp libopus.dylib ../output/libopus.dylib | |
| cd .. | |
| fi | |
| - name: Publish Artifacts | |
| uses: actions/upload-artifact@v4.4.3 | |
| with: | |
| name: opus-${{ matrix.os }} | |
| path: output | |
| compression-level: 9 # Prefer smaller downloads over a shorter workflow runtime | |
| build-musl: | |
| name: Build opus (alpine-musl) | |
| runs-on: ubuntu-latest | |
| # We sadly cant use a matrix to run x64 and ARM64, because it would give use 2 artifacts | |
| steps: | |
| - name: Clone opus repo | |
| uses: actions/checkout@v4.2.2 | |
| with: | |
| repository: xiph/opus | |
| submodules: recursive | |
| - name: Checkout latest Tag | |
| shell: bash | |
| run: | | |
| git fetch --tags | |
| LATEST_TAG=$(git tag | grep -E ^v[0-9]+.[0-9]+.[0-9]+$ | tail -1) | |
| git checkout "$LATEST_TAG" | |
| - name: Setup Alpine Linux for x64 | |
| uses: jirutka/setup-alpine@v1 | |
| with: | |
| packages: > | |
| build-base | |
| cmake | |
| git | |
| make | |
| gcc | |
| g++ | |
| - name: Build opus for x64 (musl) | |
| shell: alpine.sh {0} | |
| run: | | |
| mkdir -p output/x64 | |
| mkdir build-x64 | |
| cd build-x64 | |
| cmake $COMMON_CMAKE_FLAGS .. | |
| cmake --build . -j 4 | |
| cp libopus.so ../output/x64/libopus.musl.so | |
| cd .. | |
| - name: Setup Alpine Linux for ARM64 | |
| uses: jirutka/setup-alpine@v1 | |
| with: | |
| arch: aarch64 | |
| packages: > | |
| build-base | |
| cmake | |
| git | |
| make | |
| gcc | |
| g++ | |
| - name: Build opus for ARM64 (musl) | |
| shell: alpine.sh {0} | |
| run: | | |
| mkdir -p output/ARM64 | |
| mkdir build-ARM64 | |
| cd build-ARM64 | |
| cmake $COMMON_CMAKE_FLAGS .. | |
| cmake --build . -j 4 | |
| cp libopus.so ../output/ARM64/libopus.musl.so | |
| cd .. | |
| - name: Publish Artifacts | |
| uses: actions/upload-artifact@v4.4.3 | |
| with: | |
| name: opus-alpine-latest | |
| path: output | |
| compression-level: 9 # Prefer smaller downloads over a shorter workflow runtime | |
| publish-nuget: | |
| needs: [build, build-musl] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout CSPROJ files | |
| uses: actions/checkout@v4.2.2 | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: 9 | |
| - name: Download Artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: temp | |
| pattern: opus-* | |
| merge-multiple: true | |
| - name: Move Artifacts | |
| run: | | |
| mkdir -p lib/opus/win-x64/native | |
| mkdir -p lib/opus/linux-x64/native | |
| mkdir -p lib/opus/win-arm64/native | |
| mkdir -p lib/opus/linux-arm64/native | |
| mkdir -p lib/opus/osx/native | |
| mkdir -p lib/opus/linux-musl-x64/native | |
| mkdir -p lib/opus/linux-musl-arm64/native | |
| cp temp/x64/libopus.dll lib/opus/win-x64/native/libopus.dll | |
| cp temp/x64/libopus.so lib/opus/linux-x64/native/libopus.so | |
| cp temp/ARM64/libopus.dll lib/opus/win-arm64/native/libopus.dll | |
| cp temp/ARM64/libopus.so lib/opus/linux-arm64/native/libopus.so | |
| cp temp/libopus.dylib lib/opus/osx/native/libopus.dylib | |
| cp temp/x64/libopus.musl.so lib/opus/linux-musl-x64/native/libopus.so | |
| cp temp/ARM64/libopus.musl.so lib/opus/linux-musl-arm64/native/libopus.so | |
| - name: Pack DSharpPlus.Natives.Opus | |
| shell: bash | |
| env: | |
| NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} | |
| VERSION: ${{ needs.build.outputs.version }} | |
| run: | | |
| VERSION="${VERSION:1}" | |
| dotnet pack ./build/DSharpPlus.Natives.Opus.csproj -c Release -p:Version="$VERSION.${{ github.run_number }}" | |
| dotnet nuget push "artifacts/**" --skip-duplicate -k "$NUGET_API_KEY" -s https://api.nuget.org/v3/index.json |