Build umi-transfer #16
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 umi-transfer | |
| on: | |
| workflow_dispatch: | |
| release: | |
| types: [published] | |
| jobs: | |
| # Thanks to Alex Hallam, from whose tidy-viewer release Action all compilation steps were copied (released under UNLICENSE terms) | |
| # https://github.com/alexhallam/tv | |
| # https://raw.githubusercontent.com/alexhallam/tv/main/.github/workflows/release.yml | |
| build_binaries: | |
| ##if: github.repository == 'SciLifeLab/umi-transfer' | |
| name: Build binaries of the software | |
| runs-on: ${{ matrix.os }} | |
| env: | |
| # For some builds, we use cross to test on 32-bit and big-endian | |
| # systems. | |
| CARGO: cargo | |
| # When CARGO is set to CROSS, this is set to `--target matrix.target`. | |
| TARGET_FLAGS: "" | |
| # When CARGO is set to CROSS, TARGET_DIR includes matrix.target. | |
| TARGET_DIR: ./target | |
| # Emit backtraces on panics. | |
| RUST_BACKTRACE: 1 | |
| # Build static releases with PCRE2. | |
| PCRE2_SYS_STATIC: 1 | |
| strategy: | |
| fail-fast: false | |
| # See https://github.com/actions/runner-images for available images. | |
| matrix: | |
| build: [linux, linux-arm, macos, macos-intel, win-msvc, win-gnu, win32-msvc] | |
| include: | |
| - build: linux | |
| os: ubuntu-latest | |
| rust: nightly | |
| target: x86_64-unknown-linux-gnu | |
| - build: linux | |
| os: ubuntu-latest | |
| rust: nightly | |
| target: x86_64-unknown-linux-musl | |
| - build: linux-arm | |
| os: ubuntu-latest | |
| rust: nightly | |
| target: arm-unknown-linux-gnueabihf | |
| - build: macos | |
| os: macos-latest | |
| rust: nightly | |
| target: aarch64-apple-darwin | |
| - build: macos-intel | |
| os: macos-15-intel | |
| rust: nightly | |
| target: x86_64-apple-darwin | |
| - build: win-msvc | |
| os: windows-latest | |
| rust: nightly | |
| target: x86_64-pc-windows-msvc | |
| - build: win-gnu | |
| os: ubuntu-latest | |
| rust: nightly-x86_64-gnu | |
| target: x86_64-pc-windows-gnu | |
| - build: win32-msvc | |
| os: windows-latest | |
| rust: nightly | |
| target: i686-pc-windows-msvc | |
| steps: | |
| - name: Check out the repo | |
| uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 | |
| - name: Set software version (release) | |
| if: github.event_name == 'release' | |
| run: | | |
| echo "SOFTWARE_VERSION=${{ github.event.release.tag_name }}" >> ${GITHUB_ENV} | |
| - name: Set software version (PR) | |
| if: matrix.os == 'ubuntu-latest' && (github.event_name == 'pull-request' || github.event_name == 'workflow_dispatch' || github.event_name == 'push' ) | |
| run: | | |
| echo "SOFTWARE_VERSION=$(grep -Po -m 1 '(?<=version\s=\s\")[^\"]+' Cargo.toml)" >> ${GITHUB_ENV} | |
| - name: Install packages (Ubuntu) | |
| if: matrix.os == 'ubuntu-latest' | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y --no-install-recommends \ | |
| asciidoctor \ | |
| zsh xz-utils liblz4-tool musl-tools | |
| - name: Install packages (macOS) | |
| if: matrix.os == 'macos-latest' || matrix.os == 'macos-15-intel' | |
| run: | | |
| brew install asciidoctor | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@master | |
| with: | |
| toolchain: ${{ matrix.rust }} | |
| targets: ${{ matrix.target }} | |
| - name: Cache Rust toolchain | |
| uses: Swatinem/rust-cache@v2 | |
| with: | |
| # Without including the target in the cache key, the cache would be shared across targets. | |
| # Each target will now maintain its own cache, avoiding cross-architecture conflicts. | |
| key: ${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }} | |
| - name: Use Cross | |
| shell: bash | |
| run: | | |
| cargo install cross | |
| echo "CARGO=cross" >> $GITHUB_ENV | |
| echo "TARGET_FLAGS=--target ${{ matrix.target }}" >> $GITHUB_ENV | |
| echo "TARGET_DIR=./target/${{ matrix.target }}" >> $GITHUB_ENV | |
| - name: Show command used for Cargo | |
| run: | | |
| echo "cargo command is: ${{ env.CARGO }}" | |
| echo "target flag is: ${{ env.TARGET_FLAGS }}" | |
| echo "target dir is: ${{ env.TARGET_DIR }}" | |
| - name: Build release binary | |
| run: ${{ env.CARGO }} build --verbose --release ${{ env.TARGET_FLAGS }} | |
| - name: Strip release binary (linux and macos) | |
| if: matrix.build == 'linux' || matrix.build == 'macos' || matrix.build == 'macos-intel' | |
| run: strip "target/${{ matrix.target }}/release/umi-transfer" | |
| # For now revert to the old image, since the new image does not recognise the format of the compiled binary. | |
| #- name: Strip release binary (arm) | |
| # if: matrix.build == 'linux-arm' | |
| # run: | | |
| # docker run --rm -v \ | |
| # "$PWD/target:/target:Z" \ | |
| # ghcr.io/cross-rs/arm-unknown-linux-gnueabihf:edge \ | |
| # strip /target/arm-unknown-linux-gnueabihf/release/umi-transfer | |
| - name: Strip release binary (arm) | |
| if: matrix.build == 'linux-arm' | |
| run: | | |
| docker run --rm -v \ | |
| "$PWD/target:/target:Z" \ | |
| rustembedded/cross:arm-unknown-linux-gnueabihf \ | |
| arm-linux-gnueabihf-strip \ | |
| /target/arm-unknown-linux-gnueabihf/release/umi-transfer | |
| - name: Build archive | |
| shell: bash | |
| run: | | |
| staging="umi-transfer-${{ env.SOFTWARE_VERSION }}-${{ matrix.target }}" | |
| mkdir "$staging" | |
| cp {README.md,LICENSE} "$staging/" | |
| cp -R docs "$staging/docs" | |
| if [ "${{ matrix.target }}" = "i686-pc-windows-msvc" ] || [ "${{ matrix.target }}" = "x86_64-pc-windows-gnu" ] || [ "${{ matrix.target }}" = "x86_64-pc-windows-msvc" ]; then | |
| echo "Target is Windows Based" | |
| cp "target/${{ matrix.target }}/release/umi-transfer.exe" "$staging/" | |
| 7z a "$staging.zip" "$staging" | |
| echo "ASSET=$staging.zip" >> $GITHUB_ENV | |
| else | |
| echo "Target is not Windows Based" | |
| cp "target/${{ matrix.target }}/release/umi-transfer" "$staging/" | |
| tar czf "$staging.tar.gz" "$staging" | |
| echo "ASSET=$staging.tar.gz" >> $GITHUB_ENV | |
| fi | |
| - name: Create artifact from binary | |
| if: (github.event_name == 'push' || github.event_name == 'pull-request' || github.event_name == 'workflow_dispatch' ) && github.event.ref == 'refs/heads/main' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ env.ASSET }} | |
| path: ${{ env.ASSET }} | |
| - name: Upload release archive | |
| uses: actions/upload-release-asset@v1.0.1 | |
| if: github.event_name == 'release' | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| upload_url: ${{ github.event.release.upload_url }} | |
| asset_path: ${{ env.ASSET }} | |
| asset_name: ${{ env.ASSET }} | |
| asset_content_type: application/octet-stream |