Release Binaries #42
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 Binaries | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| as-pre-release: | |
| description: 'Release as a pre-release' | |
| required: false | |
| type: boolean | |
| default: false | |
| as-draft: | |
| description: 'Release as a draft' | |
| required: false | |
| type: boolean | |
| default: false | |
| env: | |
| CLI_NAME: git-versioner | |
| jobs: | |
| determine-version: | |
| name: Determine Version | |
| runs-on: ubuntu-latest | |
| outputs: | |
| sem-ver: ${{ steps.determine-version.outputs.GitVersion_SemVer }} | |
| pre-release-label: ${{ steps.determine-version.outputs.GitVersion_PreReleaseLabel }} | |
| version-source-sha: ${{ steps.determine-version.outputs.GitVersion_VersionSourceSha }} | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| lfs: false | |
| - name: Install git-versioner | |
| run: | | |
| curl -L -o git-versioner https://github.com/Crown0815/git-versioner/releases/download/v0.8.0/git-versioner-x86_64-unknown-linux-gnu | |
| chmod +x git-versioner | |
| - name: Determine Version | |
| id: determine-version | |
| run: ./git-versioner ${{ github.event.inputs.as-pre-release && '' || '--as-release' }} | |
| determine-changelog: | |
| name: Determine Changelog | |
| runs-on: ubuntu-latest | |
| outputs: | |
| changelog: ${{ steps.determine-changelog.outputs.changelog }} | |
| needs: | |
| determine-version | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Generate Changelog | |
| id: determine-changelog | |
| run: |- | |
| export PATH="$PATH:/root/.dotnet/tools" | |
| dotnet tool install --global ConventionalChangelog --version 0.11.0 | |
| CHANGELOG=$(changelog --skip-title --show-hash --reference-commit ${{ needs.determine-version.outputs.version-source-sha }} "${{ github.workspace }}") | |
| echo "changelog<<EOF_STEFFIMAXMAGDALENA" >> "$GITHUB_OUTPUT" | |
| echo "$CHANGELOG" >> "$GITHUB_OUTPUT" | |
| echo "EOF_STEFFIMAXMAGDALENA" >> "$GITHUB_OUTPUT" | |
| - name: Print Changelog | |
| run: echo "${{ steps.determine-changelog.outputs.changelog }}" | |
| build: | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| build: | |
| - { | |
| name: linux-x64-glibc, | |
| os: ubuntu-22.04, | |
| toolchain: stable, | |
| target: x86_64-unknown-linux-gnu, | |
| } | |
| - { | |
| name: linux-x64-musl, | |
| os: ubuntu-22.04, | |
| toolchain: stable, | |
| target: x86_64-unknown-linux-musl, | |
| } | |
| - { | |
| name: linux-x86-glibc, | |
| os: ubuntu-22.04, | |
| toolchain: stable, | |
| target: i686-unknown-linux-gnu, | |
| } | |
| - { | |
| name: linux-x86-musl, | |
| os: ubuntu-22.04, | |
| toolchain: stable, | |
| target: i686-unknown-linux-musl, | |
| } | |
| - { | |
| name: linux-arm64-glibc, | |
| os: ubuntu-22.04, | |
| toolchain: stable, | |
| target: aarch64-unknown-linux-gnu, | |
| } | |
| - { | |
| name: linux-arm64-musl, | |
| os: ubuntu-22.04, | |
| toolchain: stable, | |
| target: aarch64-unknown-linux-musl, | |
| } | |
| - { | |
| name: win32-x64-mingw, | |
| os: windows-2022, | |
| toolchain: stable, | |
| target: x86_64-pc-windows-gnu, | |
| } | |
| - { | |
| name: win32-x64-msvc, | |
| os: windows-2022, | |
| toolchain: stable, | |
| target: x86_64-pc-windows-msvc, | |
| } | |
| - { | |
| name: win32-x86-msvc, | |
| os: windows-2022, | |
| toolchain: stable, | |
| target: i686-pc-windows-msvc, | |
| } | |
| - { | |
| name: win32-arm64-msvc, | |
| os: windows-2022, | |
| toolchain: stable, | |
| target: aarch64-pc-windows-msvc, | |
| } | |
| - { | |
| name: darwin-x64, | |
| os: macos-15-intel, | |
| toolchain: stable, | |
| target: x86_64-apple-darwin, | |
| } | |
| - { | |
| name: darwin-arm64, | |
| os: macos-15, | |
| toolchain: stable, | |
| target: aarch64-apple-darwin, | |
| } | |
| runs-on: ${{ matrix.build.os }} | |
| needs: determine-version | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Install MUSL-libc dependencies (Linux) | |
| if: endsWith(matrix.build.target, 'musl') | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -o DPkg::Lock::Timeout=60 -y --no-install-recommends musl-tools | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| toolchain: ${{ matrix.build.toolchain }} | |
| targets: ${{ matrix.build.target }} | |
| components: rustfmt, clippy | |
| - name: Check format | |
| run: cargo fmt -- --check | |
| - name: Run clippy | |
| run: cargo clippy -- -D warnings | |
| - name: Set version in Cargo.toml | |
| run: | | |
| cargo install cargo-edit -f --no-default-features --features "set-version" | |
| cargo set-version ${{ needs.determine-version.outputs.sem-ver }} | |
| - name: Create Cross.toml (Linux) | |
| if: runner.os == 'Linux' | |
| run: | | |
| cat << EOF > Cross.toml | |
| [target.x86_64-unknown-linux-gnu] | |
| pre-build = ["apt-get update -qq -y", "apt-get install -y --no-install-recommends libssl-dev libssh2-1-dev pkg-config"] | |
| [target.i686-unknown-linux-gnu] | |
| pre-build = ["dpkg --add-architecture i386", "apt-get update -qq -y", "apt-get install -y --no-install-recommends libssl-dev:i386 libssh2-1-dev:i386 pkg-config"] | |
| [target.aarch64-unknown-linux-gnu] | |
| pre-build = ["dpkg --add-architecture arm64", "apt-get update -qq -y", "apt-get install -y --no-install-recommends libssl-dev:arm64 libssh2-1-dev:arm64 pkg-config"] | |
| [target.x86_64-unknown-linux-musl] | |
| pre-build = ["apt-get update -qq -y", "DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends cmake make git"] | |
| [target.i686-unknown-linux-musl] | |
| pre-build = ["apt-get update -qq -y", "DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends cmake make git"] | |
| [target.aarch64-unknown-linux-musl] | |
| pre-build = ["apt-get update -qq -y", "DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends cmake make git"] | |
| EOF | |
| - name: Install cross (Linux) | |
| if: runner.os == 'Linux' | |
| run: cargo install cross | |
| - name: Set PKG_CONFIG env (Linux) | |
| if: runner.os == 'Linux' | |
| run: | | |
| echo "PKG_CONFIG_ALLOW_CROSS=1" >> $GITHUB_ENV | |
| if [ "${{ matrix.build.target }}" == "x86_64-unknown-linux-gnu" ]; then | |
| echo "PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig" >> $GITHUB_ENV | |
| elif [ "${{ matrix.build.target }}" == "i686-unknown-linux-gnu" ]; then | |
| echo "PKG_CONFIG_PATH=/usr/lib/i386-linux-gnu/pkgconfig" >> $GITHUB_ENV | |
| elif [ "${{ matrix.build.target }}" == "aarch64-unknown-linux-gnu" ]; then | |
| echo "PKG_CONFIG_PATH=/usr/lib/aarch64-linux-gnu/pkgconfig" >> $GITHUB_ENV | |
| fi | |
| - name: Build binary (Linux) | |
| if: runner.os == 'Linux' | |
| run: cross build --release --locked --target ${{ matrix.build.target }} | |
| env: | |
| CARGO_TARGET_DIR: target | |
| - name: Build binary (Windows/macOS) | |
| if: runner.os != 'Linux' | |
| run: cargo build --release --locked --target ${{ matrix.build.target }} | |
| env: | |
| CARGO_TARGET_DIR: target | |
| - name: Strip binary (Linux/macOS) | |
| if: runner.os != 'Windows' | |
| run: | | |
| if [[ "${{ matrix.build.target }}" == aarch64* && "${{ runner.os }}" == Linux ]]; then | |
| sudo apt-get update | |
| sudo apt-get install -y binutils-aarch64-linux-gnu | |
| aarch64-linux-gnu-strip target/${{ matrix.build.target }}/release/${{ env.CLI_NAME }} | |
| else | |
| strip target/${{ matrix.build.target }}/release/${{ env.CLI_NAME }} | |
| fi | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: binary-${{ matrix.build.target }} | |
| path: target/${{ matrix.build.target }}/release/${{ env.CLI_NAME }}${{ runner.os == 'Windows' && '.exe' || '' }} | |
| if-no-files-found: error | |
| release: | |
| needs: [build, determine-version, determine-changelog] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Download artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: artifacts | |
| - name: Rename artifacts for uniqueness | |
| run: | | |
| mkdir -p release-artifacts | |
| for dir in artifacts/*; do | |
| if [ -d "$dir" ]; then | |
| target=$(basename "$dir" | sed 's/^binary-//') | |
| for file in "$dir"/*; do | |
| if [ -f "$file" ]; then | |
| filename=$(basename "$file") | |
| ext="${filename##*.}" | |
| if [ "$ext" = "$filename" ]; then | |
| mv "$file" "release-artifacts/${{ env.CLI_NAME }}-${target}" | |
| else | |
| mv "$file" "release-artifacts/${{ env.CLI_NAME }}-${target}.${ext}" | |
| fi | |
| fi | |
| done | |
| fi | |
| done | |
| - name: List release artifacts | |
| run: ls -l release-artifacts | |
| - name: Create Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| files: release-artifacts/* | |
| tag_name: "v${{ needs.determine-version.outputs.sem-ver }}" | |
| draft: ${{ github.event.inputs.as-draft }} | |
| prerelease: ${{ steps.determine-version.outputs.pre-release-label != '' }} | |
| body: | | |
| ${{ needs.determine-changelog.outputs.changelog }} | |
| fail_on_unmatched_files: true |