cln-nip47/.github/workflows/release.yml
2026-04-03 10:16:59 +02:00

169 lines
7 KiB
YAML

name: Build and release
on:
push:
tags:
- 'v*'
jobs:
build-linux:
name: Build Linux binaries (glibc)
runs-on: ubuntu-22.04
outputs:
glibc-version: ${{ steps.versions.outputs.glibc-version }}
rust-version: ${{ steps.versions.outputs.rust-version }}
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: x86_64-unknown-linux-gnu, aarch64-unknown-linux-gnu, armv7-unknown-linux-gnueabihf
- name: Install cross-compilation dependencies
run: |
sudo apt update
sudo apt install -y gcc-aarch64-linux-gnu gcc-arm-linux-gnueabihf
- name: Install Protoc
uses: arduino/setup-protoc@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
version: "21.12"
- name: Build Linux binaries (release)
run: |
cargo build --profile optimized --locked --target x86_64-unknown-linux-gnu
cargo build --profile optimized --locked --target aarch64-unknown-linux-gnu
cargo build --profile optimized --locked --target armv7-unknown-linux-gnueabihf
tar -czf "${{ github.event.repository.name }}-${{github.ref_name}}-aarch64-linux-gnu.tar.gz" --transform 's|.*/||' "target/aarch64-unknown-linux-gnu/optimized/${{ github.event.repository.name }}"
tar -czf "${{ github.event.repository.name }}-${{github.ref_name}}-armv7-linux-gnueabihf.tar.gz" --transform 's|.*/||' "target/armv7-unknown-linux-gnueabihf/optimized/${{ github.event.repository.name }}"
tar -czf "${{ github.event.repository.name }}-${{github.ref_name}}-x86_64-linux-gnu.tar.gz" --transform 's|.*/||' "target/x86_64-unknown-linux-gnu/optimized/${{ github.event.repository.name }}"
ls -alh *.tar.gz
- name: Get versions
id: versions
run: |
echo "rust-version=$(rustc --version | awk '{print $2}')" >> "$GITHUB_OUTPUT"
GLIBC_VER=$(ldd --version | awk '/ldd/{print $NF}')
echo "glibc-version=$GLIBC_VER" >> "$GITHUB_OUTPUT"
- name: Upload Linux artifacts
uses: actions/upload-artifact@v7
with:
name: linux-binaries
path: |
${{ github.event.repository.name }}-${{ github.ref_name }}-*.tar.gz
build-macos:
name: Build macOS universal binary
runs-on: macos-latest
outputs:
macos-deployment-target: ${{ steps.build.outputs.macos-deployment-target }}
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: x86_64-apple-darwin, aarch64-apple-darwin
- name: Install Protoc
uses: arduino/setup-protoc@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
version: "21.12"
- name: Build macOS universal (release)
id: build
env:
MACOSX_DEPLOYMENT_TARGET: "11.0"
run: |
cargo build --profile optimized --locked --target x86_64-apple-darwin
cargo build --profile optimized --locked --target aarch64-apple-darwin
BINARY_NAME="${{ github.event.repository.name }}"
TAG="${{ github.ref_name }}"
lipo -create -output "${BINARY_NAME}" \
target/x86_64-apple-darwin/optimized/"${BINARY_NAME}" \
target/aarch64-apple-darwin/optimized/"${BINARY_NAME}"
zip "${BINARY_NAME}-${TAG}-universal-apple-darwin.zip" "${BINARY_NAME}"
echo "macos-deployment-target=$MACOSX_DEPLOYMENT_TARGET" >> "$GITHUB_OUTPUT"
ls -alh *.zip
- name: Verify macOS deployment target
env:
EXPECTED_TARGET: ${{ steps.build.outputs.macos-deployment-target }}
run: |
BINARY="${{ github.event.repository.name }}"
echo "Verifying deployment target for universal binary: $BINARY"
echo "Expected minimum macOS version: $EXPECTED_TARGET"
echo
# Check x86_64 slice
X86_MINOS=$(otool -l -arch x86_64 "$BINARY" | awk '
/LC_BUILD_VERSION/ || /LC_VERSION_MIN_MACOSX/ {getline; getline; getline; if ($1 == "minos") print $2}
')
echo "x86_64 slice minos: $X86_MINOS"
# Check arm64 slice
ARM64_MINOS=$(otool -l -arch arm64 "$BINARY" | awk '
/LC_BUILD_VERSION/ || /LC_VERSION_MIN_MACOSX/ {getline; getline; getline; if ($1 == "minos") print $2}
')
echo "arm64 slice minos: $ARM64_MINOS"
# Fail if either doesn't match
if [ "$X86_MINOS" != "$EXPECTED_TARGET" ] || [ "$ARM64_MINOS" != "$EXPECTED_TARGET" ]; then
echo "ERROR: Deployment target mismatch!"
echo "Expected: $EXPECTED_TARGET"
echo "Got: x86_64=$X86_MINOS, arm64=$ARM64_MINOS"
exit 1
fi
echo "Success: Both architectures have deployment target $EXPECTED_TARGET"
- name: Upload macOS artifacts
uses: actions/upload-artifact@v7
with:
name: macos-binaries
path: |
${{ github.event.repository.name }}-${{ github.ref_name }}-universal-apple-darwin.zip
release:
name: Github Release
needs: [build-linux, build-macos]
runs-on: "ubuntu-latest"
permissions:
contents: write
steps:
- name: Get semver version from tag
id: tag_name
run: echo "current_version=${GITHUB_REF#refs/tags/v}" >> "$GITHUB_OUTPUT"
- name: Checkout code
uses: actions/checkout@v6
- name: Get Changelog Entry
id: changelog_reader
uses: mindsers/changelog-reader-action@v2
with:
validation_level: warn
version: ${{ steps.tag_name.outputs.current_version }}
path: ./CHANGELOG.md
- name: Download Artifacts
uses: actions/download-artifact@v8
with:
merge-multiple: true
- name: Release
uses: ncipollo/release-action@v1
with:
allowUpdates: false
artifactErrorsFailBuild: true
body: "${{ steps.changelog_reader.outputs.changes }} \n\n### Release binaries info\n\n- Release binaries were built using rust ${{ needs.build-linux.outputs.rust-version }}\n- Linux release binaries require glibc>=${{ needs.build-linux.outputs.glibc-version }} (check yours with ``ldd --version``)\n- macOS universal binary (x86_64 + aarch64), requires macOS >= ${{ needs.build-macos.outputs.macos-deployment-target }} (deployment target)"
artifacts: "${{ github.event.repository.name }}-${{github.ref_name}}-*.tar.gz,${{ github.event.repository.name }}-${{github.ref_name}}-*.zip"
immutableCreate: true