Skip to content

Commit

Permalink
Refactor release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
quietvoid committed Sep 14, 2024
1 parent 57114be commit 2aad3bb
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 58 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/actions/setup-release-env/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Setup release env
runs:
using: "composite"
steps:
- name: Install Rust
uses: dtolnay/rust-toolchain@stable

- name: Get the package versions
shell: bash
run: |
RELEASE_PKG_VERSION=$(cargo metadata --format-version 1 --no-deps | jq -r '.packages[].version')
echo "RELEASE_PKG_VERSION=${RELEASE_PKG_VERSION}" >> $GITHUB_ENV
echo "ARCHIVE_PREFIX=${{ env.RELEASE_BIN }}-${RELEASE_PKG_VERSION}" >> $GITHUB_ENV
- name: Create artifacts directory
shell: bash
run: |
mkdir ${{ env.RELEASE_DIR }}
144 changes: 86 additions & 58 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,96 +7,124 @@ env:
RELEASE_BIN: hdr10plus_tool
RELEASE_DIR: artifacts
WINDOWS_TARGET: x86_64-pc-windows-msvc
WINDOWS_ARM_TARGET: aarch64-pc-windows-msvc
MACOS_X86_TARGET: x86_64-apple-darwin
MACOS_ARM_TARGET: aarch64-apple-darwin
LINUX_TARGET: x86_64-unknown-linux-musl
LINUX_ARM_TARGET: aarch64-unknown-linux-musl

jobs:
build:
name: Build artifacts
runs-on: ${{ matrix.os }}
strategy:
matrix:
build: [Linux, macOS, Windows]
include:
- build: Linux
os: ubuntu-latest
- build: macOS
os: macos-latest
- build: Windows
os: windows-latest

linux-binary:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Install Rust
uses: dtolnay/rust-toolchain@stable

- name: Get the version
shell: bash
run: |
echo "RELEASE_PKG_VERSION=$(cargo pkgid | cut -d# -f2 | cut -d: -f2)" >> $GITHUB_ENV
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-release-env

- name: Install musl-tools (Linux)
if: matrix.build == 'Linux'
- name: Install musl-tools
run: |
sudo apt-get update -y
sudo apt-get install musl-tools -y
sudo apt-get install musl-tools gcc-aarch64-linux-gnu -y
- name: Build (Linux)
if: matrix.build == 'Linux'
- name: Build
run: |
rustup target add ${{ env.LINUX_TARGET }}
rustup target add ${{ env.LINUX_ARM_TARGET }}
cargo build --release --target ${{ env.LINUX_TARGET }} --no-default-features --features internal-font
cargo build --config "target.${{ env.LINUX_ARM_TARGET }}.linker = 'aarch64-linux-gnu-gcc'" \
--release --target ${{ env.LINUX_ARM_TARGET }} --no-default-features --features internal-font
- name: Build (macOS)
if: matrix.build == 'macOS'
- name: Create tarball and checksum
run: |
rustup target add ${{ env.MACOS_ARM_TARGET }}
X86_64_ARCHIVE_FILE=${{ env.RELEASE_DIR }}/${{ env.ARCHIVE_PREFIX }}-${{ env.LINUX_TARGET }}.tar.gz
AARCH64_ARCHIVE_FILE=${{ env.RELEASE_DIR }}/${{ env.ARCHIVE_PREFIX }}-${{ env.LINUX_ARM_TARGET }}.tar.gz
cargo build --release
cargo build --release --target ${{ env.MACOS_ARM_TARGET }}
strip ./target/${{ env.LINUX_TARGET }}/release/${{ env.RELEASE_BIN }}
aarch64-linux-gnu-strip ./target/${{ env.LINUX_ARM_TARGET }}/release/${{ env.RELEASE_BIN }}
- name: Build (Windows)
if: matrix.build == 'Windows'
run: cargo build --release
mv ./target/${{ env.LINUX_TARGET }}/release/${{ env.RELEASE_BIN }} ./${{ env.RELEASE_BIN }}
tar -cvzf ./${X86_64_ARCHIVE_FILE} ./${{ env.RELEASE_BIN }}
- name: Create artifact directory
run: |
mkdir ${{ env.RELEASE_DIR }}
mv ./target/${{ env.LINUX_ARM_TARGET }}/release/${{ env.RELEASE_BIN }} ./${{ env.RELEASE_BIN }}
tar -cvzf ./${AARCH64_ARCHIVE_FILE} ./${{ env.RELEASE_BIN }}
python -c "import hashlib; import pathlib; print(hashlib.sha256(pathlib.Path('${X86_64_ARCHIVE_FILE}').read_bytes()).hexdigest())" > ${X86_64_ARCHIVE_FILE}.sha256
python -c "import hashlib; import pathlib; print(hashlib.sha256(pathlib.Path('${AARCH64_ARCHIVE_FILE}').read_bytes()).hexdigest())" > ${AARCH64_ARCHIVE_FILE}.sha256
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: Linux artifacts
path: ./${{ env.RELEASE_DIR }}/*

- name: Create tarball (Linux)
if: matrix.build == 'Linux'
windows-binary:
runs-on: windows-latest

steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-release-env

- name: Build
run: |
strip ./target/${{ env.LINUX_TARGET }}/release/${{ env.RELEASE_BIN }}
mv ./target/${{ env.LINUX_TARGET }}/release/${{ env.RELEASE_BIN }} ./${{ env.RELEASE_BIN }}
tar -cvzf ./${{ env.RELEASE_DIR }}/${{ env.RELEASE_BIN }}-${{ env.RELEASE_PKG_VERSION }}-${{ env.LINUX_TARGET }}.tar.gz ./${{ env.RELEASE_BIN }}
rustup target add ${{ env.WINDOWS_ARM_TARGET }}
cargo build --release
cargo build --release --target ${{ env.WINDOWS_ARM_TARGET }}
- name: Create zipfile (Windows)
if: matrix.build == 'Windows'
- name: Create zipfile
shell: bash
run: |
X86_64_ARCHIVE_FILE=${{ env.RELEASE_DIR }}/${{ env.ARCHIVE_PREFIX }}-${{ env.WINDOWS_TARGET }}.zip
AARCH64_ARCHIVE_FILE=${{ env.RELEASE_DIR }}/${{ env.ARCHIVE_PREFIX }}-${{ env.WINDOWS_ARM_TARGET }}.zip
mv ./target/release/${{ env.RELEASE_BIN }}.exe ./${{ env.RELEASE_BIN }}.exe
7z a ./${{ env.RELEASE_DIR }}/${{ env.RELEASE_BIN }}-${{ env.RELEASE_PKG_VERSION }}-${{ env.WINDOWS_TARGET }}.zip ./${{ env.RELEASE_BIN }}.exe
7z a ./${X86_64_ARCHIVE_FILE} ./${{ env.RELEASE_BIN }}.exe
mv ./target/${{ env.WINDOWS_ARM_TARGET }}/release/${{ env.RELEASE_BIN }}.exe ./${{ env.RELEASE_BIN }}.exe
7z a ./${AARCH64_ARCHIVE_FILE} ./${{ env.RELEASE_BIN }}.exe
python -c "import hashlib; import pathlib; print(hashlib.sha256(pathlib.Path('${X86_64_ARCHIVE_FILE}').read_bytes()).hexdigest())" > ${X86_64_ARCHIVE_FILE}.sha256
python -c "import hashlib; import pathlib; print(hashlib.sha256(pathlib.Path('${AARCH64_ARCHIVE_FILE}').read_bytes()).hexdigest())" > ${AARCH64_ARCHIVE_FILE}.sha256
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: Windows artifacts
path: ./${{ env.RELEASE_DIR }}/*

macos-binary:
runs-on: macos-latest

steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-release-env

- name: Build
run: |
rustup target add ${{ env.MACOS_X86_TARGET }}
cargo build --release
cargo build --release --target ${{ env.MACOS_X86_TARGET }}
- name: Create universal macOS binary
if: matrix.build == 'macOS'
run: |
strip ./target/release/${{ env.RELEASE_BIN }}
strip ./target/aarch64-apple-darwin/release/${{ env.RELEASE_BIN }}
strip ./target/${{ env.MACOS_X86_TARGET }}/release/${{ env.RELEASE_BIN }}
lipo -create \
./target/aarch64-apple-darwin/release/${{ env.RELEASE_BIN }} \
./target/release/${{ env.RELEASE_BIN }} \
./target/${{ env.MACOS_X86_TARGET }}/release/${{ env.RELEASE_BIN }} \
-output ./${{ env.RELEASE_BIN }}
- name: Create zipfile (macOS)
if: matrix.build == 'macOS'
- name: Create zipfile
run: |
zip -9 ./${{ env.RELEASE_DIR }}/${{ env.RELEASE_BIN }}-${{ env.RELEASE_PKG_VERSION }}-universal-macOS.zip ./${{ env.RELEASE_BIN }}
ARCHIVE_FILE=${{ env.RELEASE_DIR }}/${{ env.ARCHIVE_PREFIX }}-universal-macOS.zip
zip -9 ./${ARCHIVE_FILE} ./${{ env.RELEASE_BIN }}
python -c "import hashlib; import pathlib; print(hashlib.sha256(pathlib.Path('${ARCHIVE_FILE}').read_bytes()).hexdigest())" > ${ARCHIVE_FILE}.sha256
- name: Upload Zip
uses: actions/upload-artifact@v1
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.build }}
path: ./${{ env.RELEASE_DIR }}
name: macOS artifacts
path: ./${{ env.RELEASE_DIR }}/*

0 comments on commit 2aad3bb

Please sign in to comment.