release: use cargo-zigbuild for Linux musl cross-compilation #9
Workflow file for this run
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: Release | |
| on: | |
| push: | |
| tags: ["v*"] | |
| permissions: | |
| contents: write | |
| env: | |
| CARGO_TERM_COLOR: always | |
| jobs: | |
| build: | |
| strategy: | |
| matrix: | |
| include: | |
| - target: x86_64-unknown-linux-musl | |
| os: ubuntu-latest | |
| arch: x86_64 | |
| platform: linux | |
| - target: aarch64-unknown-linux-musl | |
| os: ubuntu-latest | |
| arch: aarch64 | |
| platform: linux | |
| - target: aarch64-apple-darwin | |
| os: macos-latest | |
| arch: aarch64 | |
| platform: darwin | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: ${{ matrix.target }} | |
| - uses: Swatinem/rust-cache@v2 | |
| with: | |
| key: ${{ matrix.target }} | |
| - name: Install cargo-zigbuild and Zig | |
| if: matrix.platform == 'linux' | |
| run: | | |
| pip3 install ziglang | |
| cargo install cargo-zigbuild | |
| - name: Set version from tag | |
| run: echo "VERSION=${GITHUB_REF_NAME#v}" >> "$GITHUB_ENV" | |
| - name: Build (zigbuild, Linux musl) | |
| if: matrix.platform == 'linux' | |
| run: cargo zigbuild --release --target ${{ matrix.target }} | |
| - name: Build (native, macOS) | |
| if: matrix.platform == 'darwin' | |
| run: cargo build --release --target ${{ matrix.target }} | |
| - name: Compress binary (zstd) | |
| run: zstd -19 target/${{ matrix.target }}/release/batdoc -o batdoc-${{ matrix.platform }}-${{ matrix.arch }}.zst | |
| - name: Create tar.gz archive | |
| if: matrix.platform == 'linux' | |
| run: | | |
| mkdir -p batdoc_${{ env.VERSION }}_${{ matrix.arch }} | |
| cp target/${{ matrix.target }}/release/batdoc batdoc_${{ env.VERSION }}_${{ matrix.arch }}/ | |
| cp LICENSE README.md batdoc_${{ env.VERSION }}_${{ matrix.arch }}/ | |
| tar czf batdoc_${{ env.VERSION }}_${{ matrix.arch }}.tar.gz batdoc_${{ env.VERSION }}_${{ matrix.arch }}/ | |
| - name: Upload zstd artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: batdoc-${{ matrix.platform }}-${{ matrix.arch }}.zst | |
| path: batdoc-${{ matrix.platform }}-${{ matrix.arch }}.zst | |
| - name: Upload tar.gz artifact | |
| if: matrix.platform == 'linux' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: batdoc_${{ env.VERSION }}_${{ matrix.arch }}.tar.gz | |
| path: batdoc_${{ env.VERSION }}_${{ matrix.arch }}.tar.gz | |
| packages: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set version from tag | |
| run: echo "VERSION=${GITHUB_REF_NAME#v}" >> "$GITHUB_ENV" | |
| - name: Build distro packages | |
| run: docker build --build-arg VERSION=${{ env.VERSION }} -o pkg/out . | |
| - name: List packages | |
| run: ls -lh pkg/out/ | |
| - name: Remove debug packages | |
| run: rm -f pkg/out/*-debug* pkg/out/*-debuginfo* pkg/out/*-debugsource* | |
| - name: Upload packages | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: distro-packages | |
| path: pkg/out/ | |
| release: | |
| needs: [build, packages] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| merge-multiple: true | |
| - name: List release assets | |
| run: ls -lh | |
| - name: Create release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| generate_release_notes: true | |
| files: | | |
| batdoc-linux-x86_64.zst | |
| batdoc-linux-aarch64.zst | |
| batdoc-darwin-aarch64.zst | |
| batdoc_*_x86_64.tar.gz | |
| batdoc_*_aarch64.tar.gz | |
| *.deb | |
| *.rpm | |
| *.apk | |
| *.pkg.tar.zst |