name: CI on: push: pull_request: workflow_dispatch: inputs: tag: description: 'Tag to force the cross build on' required: false type: string default: '' jobs: pre_job: # continue-on-error: true # Uncomment once integration is finished runs-on: ubuntu-latest # Map a step output to a job output outputs: should_skip: ${{ steps.skip_check.outputs.should_skip }} && ! (startsWith(github.ref, 'refs/tags/') && github.event_name == 'push') steps: - id: skip_check uses: fkirc/skip-duplicate-actions@v5 with: # All of these options are optional, so you can remove them if you are happy with the defaults concurrent_skipping: "same_content_newer" skip_after_successful_duplicate: "false" native: needs: pre_job if: needs.pre_job.outputs.should_skip != 'true' name: native runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: os: [ubuntu-22.04, windows-2022, macos-12, macos-14] # macos-14+ is arm64 steps: - uses: actions/checkout@v4 name: Checkout onto ${{ runner.os }} - if: runner.os == 'Linux' name: apt install gstreamer run: | sudo apt update sudo apt install -y aptitude sudo aptitude install -y libgstrtspserver-1.0-dev libgstreamer1.0-dev libgtk2.0-dev protobuf-compiler libssl-dev - if: runner.os == 'Windows' name: Install Gstreamer run: | # Gstreamer choco install -y --no-progress gstreamer --version=1.20.0 choco install -y --no-progress gstreamer-devel --version=1.20.0 $env:GSTREAMER_1_0_ROOT_MSVC_X86_64=$env:SYSTEMDRIVE + '\gstreamer\1.0\msvc_x86_64\' # Github runners work on both C or D drive and figuring out which was used is difficult if (-not (Test-Path -Path "$env:GSTREAMER_1_0_ROOT_MSVC_X86_64" -PathType Container)) { $env:GSTREAMER_1_0_ROOT_MSVC_X86_64='D:\\gstreamer\1.0\msvc_x86_64\' } echo "GSTREAMER_1_0_ROOT_MSVC_X86_64=$env:GSTREAMER_1_0_ROOT_MSVC_X86_64" # Proto buffers choco install -y --no-progress protoc --version=24.2.0 # Open SSL choco install -y --no-progress openssl --version=1.1.1.2100 $env:OPENSSL_DIR=$env:SYSTEMDRIVE + '\Program Files\OpenSSL-Win64\' # Alternative openssl location (depends on version that gets installed by choco) if (-not (Test-Path -Path "$env:OPENSSL_DIR" -PathType Container)) { $env:OPENSSL_DIR=$env:SYSTEMDRIVE + '\Program Files\OpenSSL\' } # Github runners work on both C or D drive and figuring out which was used is difficult if (-not (Test-Path -Path "$env:OPENSSL_DIR" -PathType Container)) { $env:OPENSSL_DIR='D:\\Program Files\OpenSSL-Win64\' } # Or course we could be on alternative location and drive.... if (-not (Test-Path -Path "$env:OPENSSL_DIR" -PathType Container)) { $env:OPENSSL_DIR='D:\\Program Files\OpenSSL\' } # Set up pkgconfig for gstreamer $env:PKG_CONFIG_PATH += ';' + $env:GSTREAMER_1_0_ROOT_MSVC_X86_64 + '\lib\pkgconfig' # Set github vars Add-Content -Path $env:GITHUB_ENV -Value "GSTREAMER_1_0_ROOT_MSVC_X86_64=$env:GSTREAMER_1_0_ROOT_MSVC_X86_64" Add-Content -Path $env:GITHUB_PATH -Value "$env:GSTREAMER_1_0_ROOT_MSVC_X86_64\bin" Add-Content -Path $env:GITHUB_PATH -Value "%GSTREAMER_1_0_ROOT_MSVC_X86_64%\bin" Add-Content -Path $env:GITHUB_ENV -Value "OPENSSL_DIR=$env:OPENSSL_DIR" Add-Content -Path $env:GITHUB_ENV -Value "PKG_CONFIG_PATH=$env:PKG_CONFIG_PATH" # One last check on directories dir "$env:GSTREAMER_1_0_ROOT_MSVC_X86_64" dir "$env:OPENSSL_DIR" - if: runner.os == 'macOS' name: Install Gstreamer on macOS run: | curl -L 'https://gstreamer.freedesktop.org/data/pkg/osx/1.20.4/gstreamer-1.0-devel-1.20.4-universal.pkg' -o "$(pwd)/gstreamer-devel.pkg" sudo installer -verbose -pkg "$(pwd)/gstreamer-devel.pkg" -target / PKG_CONFIG_PATH="/Library/Frameworks/GStreamer.framework/Versions/1.0/lib/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}" PKG_CONFIG_GSTREAMER_1_0_PREFIX="/Library/Frameworks/GStreamer.framework/Versions/1.0" echo "PKG_CONFIG_PATH=${PKG_CONFIG_PATH}" >> "${GITHUB_ENV}" echo "PKG_CONFIG_GSTREAMER_1_0_PREFIX=${PKG_CONFIG_GSTREAMER_1_0_PREFIX}" >> "${GITHUB_ENV}" echo "PKG_CONFIG_PATH=${PKG_CONFIG_PATH}" brew install pkg-config protobuf openssl@1.1 echo "OPENSSL_INCLUDE_DIR=$(brew --prefix openssl@1.1)/include/" >> "${GITHUB_ENV}" echo "OPENSSL_LIB_DIR=$(brew --prefix openssl@1.1)/lib/" >> "${GITHUB_ENV}" - name: Cache cargo registry uses: actions/cache@v4 with: path: ~/.cargo/registry key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} - name: Cache cargo index uses: actions/cache@v4 with: path: ~/.cargo/git key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }} - name: Cache cargo build if: runner.os != 'macOS' # Random missing crates on macOS, unclear why uses: actions/cache@v4 with: path: target key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }} - name: Build shell: bash run: | echo "PATH=${PATH}" echo "GSTREAMER_1_0_ROOT_MSVC_X86_64=${GSTREAMER_1_0_ROOT_MSVC_X86_64}" echo "PKG_CONFIG_PATH=${PKG_CONFIG_PATH}" # pkg-config --variable pc_path pkg-config export JEMALLOC_SYS_WITH_LG_PAGE=16 cargo build --release --all-features - uses: actions/upload-artifact@v4 with: name: release-${{ matrix.os }} path: "target/release/neolink*" cross: needs: pre_job if: needs.pre_job.outputs.should_skip != 'true' name: cross runs-on: ubuntu-latest container: "node:current-bullseye-slim" strategy: fail-fast: false matrix: # Everyone has a slightly different screwball naming scheme; # Rust uses the target triple, GCC generally targets a family # with a specific prefix, and dpkg's arch does its own thing include: - arch: amd64 target: x86_64-unknown-linux-gnu gcc: x86-64-linux-gnu pkgconfig: x86_64-linux-gnu - arch: armhf target: armv7-unknown-linux-gnueabihf gcc: arm-linux-gnueabihf pkgconfig: arm-linux-gnueabihf - arch: arm64 target: aarch64-unknown-linux-gnu gcc: aarch64-linux-gnu pkgconfig: aarch64-linux-gnu - arch: i386 target: i686-unknown-linux-gnu gcc: i686-linux-gnu # on i686, the pkgconfig path doesn't match the prefix! pkgconfig: i386-linux-gnu steps: - uses: actions/checkout@v4 with: ref: ${{ github.event.inputs.tag }} - name: Install basic tools run: | apt-get update apt-get install --assume-yes --no-install-recommends curl ca-certificates protobuf-compiler - name: Install ${{ matrix.arch }} cross compiler and gstreamer id: setup run: | dpkg --add-architecture ${{ matrix.arch }} apt-get update apt-get install --assume-yes --no-install-recommends \ build-essential \ gcc-${{ matrix.gcc }} \ g++-${{ matrix.gcc }} \ libgstrtspserver-1.0-dev:${{ matrix.arch }} \ libgstreamer1.0-dev:${{ matrix.arch }} \ libgtk2.0-dev:${{ matrix.arch }} \ libglib2.0-dev:${{ matrix.arch }} \ libssl-dev:${{ matrix.arch }} - name: Install rustup run: | curl https://sh.rustup.rs -sSf | sh -s -- --no-modify-path --quiet -y echo "${HOME}/.cargo/bin" >> "${GITHUB_PATH}" - name: Install ${{ matrix.arch }} Rust toolchain run: | rustup default 1.79.0 rustup target add ${TARGET} env: TARGET: ${{ matrix.target }} - name: Build run: | cargo build --release --verbose --all-features --target=${TARGET} env: # Retarget pkg-config as described in https://www.freedesktop.org/wiki/Software/pkg-config/CrossCompileProposal/ PKG_CONFIG_ALLOW_CROSS: 1 PKG_CONFIG_LIBDIR: /usr/lib/${{ matrix.pkgconfig }}/pkgconfig TARGET: ${{ matrix.target }} JEMALLOC_SYS_WITH_LG_PAGE: 16 - uses: actions/upload-artifact@v4 with: name: release-${{ matrix.arch }}-bookworm path: "target/${{ matrix.target }}/release/neolink*" push_to_registry: name: Build Docker image if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name runs-on: ubuntu-latest needs: - "cross" steps: - name: Check token is set id: vars shell: bash run: | unset HAS_SECRET if [ -n $SECRET ]; then HAS_SECRET='true' ; fi echo "HAS_SECRET_TOKEN=${HAS_SECRET}" >> $GITHUB_OUTPUT env: SECRET: "${{ secrets.DOCKER_TOKEN }}" - name: Check out the repo uses: actions/checkout@v4 with: ref: ${{ github.event.inputs.tag }} if: ${{ steps.vars.outputs.HAS_SECRET_TOKEN }} - name: Convert username to lower case for docker id: string_user uses: ASzc/change-string-case-action@v6 with: string: ${{ github.repository_owner }} - name: Convert repo to lower case for docker id: string_repo uses: ASzc/change-string-case-action@v6 with: string: ${{ github.repository }} - name: Set up QEMU if: ${{ steps.vars.outputs.HAS_SECRET_TOKEN }} uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx if: ${{ steps.vars.outputs.HAS_SECRET_TOKEN }} uses: docker/setup-buildx-action@v3 - name: Login to Docker Hub if: ${{ steps.vars.outputs.HAS_SECRET_TOKEN }} uses: docker/login-action@v3 with: registry: docker.io username: ${{ vars.DOCKER_USERNAME || steps.string_user.outputs.lowercase }} password: ${{ secrets.DOCKER_TOKEN }} - name: Set Docker name with owner (package name) depending on if DOCKER_USERNAME is set if: ${{ steps.vars.outputs.HAS_SECRET_TOKEN }} id: docker_repo shell: bash run: | if [ -z $DOCKER_USERNAME ]; then echo "DOCKER_NWO=${GITHUB_NWO}" >> $GITHUB_OUTPUT else IFS='/' read -ra NWO_SPLIT <<< "$GITHUB_NWO" REPO_NAME=${NWO_SPLIT[1]} echo "DOCKER_NWO=${DOCKER_USERNAME}/${REPO_NAME}" >> $GITHUB_OUTPUT fi env: DOCKER_USERNAME: ${{ vars.DOCKER_USERNAME }} GITHUB_NWO: ${{ steps.string_repo.outputs.lowercase }} - name: Get tag name if: ${{ steps.vars.outputs.HAS_SECRET_TOKEN }} id: tags shell: bash run: | tags=( ) gittag="$(git tag --points-at HEAD)" branch="$(git rev-parse --abbrev-ref HEAD)" if [[ -n "${gittag}" ]]; then tags=( "${tags[@]}" "${REPO_NAME}:${gittag}" ) fi if [[ -n "${branch}" ]]; then branch="$(echo "${branch}" | sed -E 's|[/]|-|g')" tags=( "${tags[@]}" "${REPO_NAME}:${branch}" ) if [ "${branch}" == "master" ]; then tags=( "${tags[@]}" "${tags},${REPO_NAME}:latest" ) fi fi function join_by { local d=${1-} f=${2-} if shift 2; then printf %s "$f" "${@/#/$d}" fi } tagstr="$(join_by "," "${tags[@]}")" echo "TAGS=${tagstr}" echo "TAGS=${tagstr}" >> "${GITHUB_OUTPUT}" env: REPO_NAME: ${{ steps.docker_repo.outputs.DOCKER_NWO }} - name: Install latest rust run: | rustup toolchain install stable - name: Install toml-cli run: | cargo install toml-cli - name: Get project version id: toml run: | NEOLINK_VERSION="$(toml get Cargo.toml package.version | sed 's|"||g')" echo "version=${NEOLINK_VERSION}" >> $GITHUB_OUTPUT - name: Prepare directory run: | mkdir linux mkdir linux/arm mkdir linux/arm64 - name: Download Linux x86_64 uses: actions/download-artifact@v4 with: name: release-amd64-bookworm path: linux/amd64 - name: Download Linux armv7 uses: actions/download-artifact@v4 with: name: release-armhf-bookworm path: linux/arm/v7 - name: Download Linux arm64 uses: actions/download-artifact@v4 with: name: release-arm64-bookworm path: linux/arm64 - name: Download Linux i386 uses: actions/download-artifact@v4 with: name: release-i386-bookworm path: linux/386 - name: Push to Docker Hub if: ${{ steps.vars.outputs.HAS_SECRET_TOKEN }} uses: docker/build-push-action@v5 with: platforms: linux/amd64,linux/arm/v7,linux/arm64,linux/386 context: . push: true file: Dockerfile tags: ${{ steps.tags.outputs.TAGS }} build-args: VERSION=${{ steps.toml.outputs.version }}, REPO=${{ github.repository }}, OWNER=${{ vars.DOCKER_USERNAME || github.repository_owner }} env: DOCKER_BUILDKIT: 1 create_release: name: Create Release runs-on: ubuntu-latest if: startsWith(github.ref, 'refs/tags/') && github.event_name == 'push' # Ensure this only runs on a tag or expect issues needs: - "cross" - "native" steps: - name: Checkout code uses: actions/checkout@v4 - name: Install latest rust run: | rustup toolchain install stable - name: Install toml-cli run: | cargo install toml-cli - name: Get project version id: toml run: | NEOLINK_VERSION="$(toml get Cargo.toml package.version | sed 's|"||g')" echo "version=${NEOLINK_VERSION}" >> $GITHUB_OUTPUT - name: Download Windows uses: actions/download-artifact@v4 with: name: release-windows-2022 path: neolink_windows - name: Download Macos uses: actions/download-artifact@v4 with: name: release-macos-12 path: neolink_macos_intel - name: Download Macos arm64 uses: actions/download-artifact@v4 with: name: release-macos-14 path: neolink_macos_m1 - name: Download Linux x86_64 uses: actions/download-artifact@v4 with: name: release-ubuntu-22.04 path: neolink_linux_x86_64_ubuntu - name: Download Linux x86_64 uses: actions/download-artifact@v4 with: name: release-amd64-bookworm path: neolink_linux_x86_64_bookworm - name: Download Linux armhf uses: actions/download-artifact@v4 with: name: release-armhf-bookworm path: neolink_linux_armhf - name: Download Linux arm64 uses: actions/download-artifact@v4 with: name: release-arm64-bookworm path: neolink_linux_arm64 - name: Download Linux i386 uses: actions/download-artifact@v4 with: name: release-i386-bookworm path: neolink_linux_i386 - name: Prepare releases run: | dirs=( neolink_windows neolink_macos_intel neolink_macos_m1 neolink_linux_x86_64_ubuntu neolink_linux_x86_64_bookworm neolink_linux_armhf neolink_linux_arm64 neolink_linux_i386 ) for d in "${dirs[@]}"; do chmod +x "${d}/neolink"* zip -r "${d}.zip" "${d}" done - name: release uses: softprops/action-gh-release@v1 with: name: Neolink ${{steps.toml.outputs.version}} files: | neolink_windows.zip neolink_macos_intel.zip neolink_macos_m1.zip neolink_linux_x86_64_ubuntu.zip neolink_linux_x86_64_bookworm.zip neolink_linux_armhf.zip neolink_linux_arm64.zip neolink_linux_i386.zip body: | Neolink release ${{steps.toml.outputs.version}} draft: true prerelease: ${{ contains(github.ref_name, 'rc') }}