From 47ec12fbe3608675c8cee7f6b6f57177c6989389 Mon Sep 17 00:00:00 2001 From: Shigure Kurosaki Date: Wed, 4 Dec 2024 17:15:25 +0800 Subject: [PATCH 1/4] feat: Support binary artifact upload --- .github/workflows/cd.yml | 90 +++++++++++++++++++++ etc/cd/before_deploy.sh | 164 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 254 insertions(+) create mode 100644 .github/workflows/cd.yml create mode 100644 etc/cd/before_deploy.sh diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 0000000..1c2815c --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,90 @@ +name: CD + +on: + push: + tags: [ 'v[0-9]+.[0-9]+.[0-9]+', 'v[0-9]+.[0-9]+.[0-9]+-canary.[0-9]+' ] + +jobs: + publish: + name: Publishing for ${{ matrix.job.os }} + runs-on: ${{ matrix.job.os }} + strategy: + matrix: + job: + - os: macos-latest + target: x86_64-apple-darwin + use-cross: false + - os: macos-latest + target: aarch64-apple-darwin + use-cross: false + - os: windows-latest + target: x86_64-pc-windows-msvc + use-cross: false + - os: ubuntu-20.04 + target: x86_64-unknown-linux-gnu + use-cross: false + - os: ubuntu-latest + target: x86_64-unknown-linux-musl + use-cross: true + - os: ubuntu-20.04 + target: i686-unknown-linux-gnu + use-cross: true + - os: ubuntu-20.04 + target: arm-unknown-linux-gnueabihf + use-cross: true + - os: ubuntu-20.04 + target: aarch64-unknown-linux-gnu + use-cross: true + + steps: + - name: Installing Rust toolchain + uses: dtolnay/rust-toolchain@stable + with: + targets: ${{ matrix.job.target }} + - name: Checkout repository + uses: actions/checkout@v3 + - name: Install cross + if: matrix.job.use-cross + uses: taiki-e/install-action@v2 + with: + tool: cross + - name: Cargo build + env: + MACOSX_DEPLOYMENT_TARGET: 10.7 + shell: bash + run: | + if [[ "${{ matrix.job.use-cross }}" == "true" ]]; then + cross build --release --target ${{ matrix.job.target }} + else + cargo build --release --target ${{ matrix.job.target }} + fi + + - name: Install required dependencies + shell: bash + run: | + if [[ ${{ matrix.job.target }} == arm-unknown-linux-gnueabihf ]]; then + sudo apt update + sudo apt-get install -y binutils-arm-linux-gnueabihf + fi + if [[ ${{ matrix.job.target }} == aarch64-unknown-linux-gnu ]]; then + sudo apt update + sudo apt-get install -y binutils-aarch64-linux-gnu + fi + + - name: Packaging final binary + shell: bash + env: + TARGET: ${{ matrix.job.target }} + PROJECT_NAME: katharsis + PACKAGE_NAME: katharsis + OS_NAME: ${{ matrix.job.os }} + run: ./etc/cd/before_deploy.sh + + - name: Releasing assets + uses: softprops/action-gh-release@v1 + with: + files: | + katharsis-*-${{ matrix.job.target }}.* + katharsis*.deb + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/etc/cd/before_deploy.sh b/etc/cd/before_deploy.sh new file mode 100644 index 0000000..ca7d01d --- /dev/null +++ b/etc/cd/before_deploy.sh @@ -0,0 +1,164 @@ +#!/usr/bin/env bash + +set -ex + +pack() { + local tempdir + local out_dir + local package_name + local gcc_prefix + + tempdir=$(mktemp -d 2>/dev/null || mktemp -d -t tmp) + out_dir=$(pwd) + package_name="$PROJECT_NAME-${GITHUB_REF/refs\/tags\//}-$TARGET" + + if [[ $TARGET == "arm-unknown-linux-gnueabihf" ]]; then + gcc_prefix="arm-linux-gnueabihf-" + elif [[ $TARGET == "aarch64-unknown-linux-gnu" ]]; then + gcc_prefix="aarch64-linux-gnu-" + else + gcc_prefix="" + fi + + mkdir "$tempdir/$package_name" + + cp "target/$TARGET/release/$PROJECT_NAME" "$tempdir/$package_name/" + if [ "$OS_NAME" != windows-latest ]; then + "${gcc_prefix}"strip "$tempdir/$package_name/$PROJECT_NAME" + fi + + cp README.md "$tempdir/$package_name" + cp LICENSE "$tempdir/$package_name" + + pushd "$tempdir" + if [ "$OS_NAME" = windows-latest ]; then + 7z a "$out_dir/$package_name.zip" "$package_name"/* + else + tar czf "$out_dir/$package_name.tar.gz" "$package_name"/* + fi + popd + rm -r "$tempdir" +} + +make_deb() { + local tempdir + local architecture + local version + local dpkgname + local conflictname + local gcc_prefix + local homepage + local maintainer + + homepage="https://github.com/kurosakishigure/katharsis" + maintainer="Shigure Kurosaki " + copyright_years="2024 - "$(date "+%Y") + + case $TARGET in + x86_64*) + architecture=amd64 + gcc_prefix="" + library_dir="" + ;; + i686*) + architecture=i386 + gcc_prefix="" + library_dir="" + ;; + aarch64*) + architecture=arm64 + gcc_prefix="aarch64-linux-gnu-" + library_dir="-l/usr/aarch64-linux-gnu/lib" + ;; + arm*hf) + architecture=armhf + gcc_prefix="arm-linux-gnueabihf-" + library_dir="-l/usr/arm-linux-gnueabihf/lib" + ;; + *) + echo "make_deb: skipping target '${TARGET}'" >&2 + return 0 + ;; + esac + version=${GITHUB_REF/refs\/tags\//} + + if [[ $TARGET = *musl* ]]; then + dpkgname=$PACKAGE_NAME-musl + conflictname=$PROJECT_NAME + else + dpkgname=$PACKAGE_NAME + conflictname=$PROJECT_NAME-musl + fi + + tempdir=$(mktemp -d 2>/dev/null || mktemp -d -t tmp) + + install -Dm755 "target/$TARGET/release/$PROJECT_NAME" "$tempdir/usr/bin/$PROJECT_NAME" + "${gcc_prefix}"strip "$tempdir/usr/bin/$PROJECT_NAME" + + mkdir "./debian" + touch "./debian/control" + depends="$(dpkg-shlibdeps $library_dir -O "$tempdir/usr/bin/$PROJECT_NAME" 2> /dev/null | sed 's/^shlibs:Depends=//')" + rm -rf "./debian" + + install -Dm644 README.md "$tempdir/usr/share/doc/$dpkgname/README.md" + cat > "$tempdir/usr/share/doc/$dpkgname/copyright" < "$tempdir/DEBIAN/control" < +Architecture: $architecture +Depends: $depends +Conflicts: $conflictname +Description: CLI tool for generating RSS feeds. +EOF + + fakeroot dpkg-deb -Zxz --build "$tempdir" "${dpkgname}_${version}_${architecture}.deb" +} + + +main() { + pack + if [[ $TARGET = *linux* ]]; then + make_deb + fi +} + +main From 4e4355c7f770fd8de73d41c4a56bb0b5fecf23fe Mon Sep 17 00:00:00 2001 From: Shigure Kurosaki Date: Wed, 4 Dec 2024 17:33:05 +0800 Subject: [PATCH 2/4] fix: Solve the issue of insufficient permissions to run the .sh file --- etc/cd/before_deploy.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 etc/cd/before_deploy.sh diff --git a/etc/cd/before_deploy.sh b/etc/cd/before_deploy.sh old mode 100644 new mode 100755 From 3141af6bd3a05b7b985097b5b148e6f08d6ecdb9 Mon Sep 17 00:00:00 2001 From: Shigure Kurosaki Date: Wed, 4 Dec 2024 17:50:43 +0800 Subject: [PATCH 3/4] fix: dpkg-deb version number does not start with digit --- .github/workflows/cd.yml | 2 +- .github/workflows/ci.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 1c2815c..849314f 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -2,7 +2,7 @@ name: CD on: push: - tags: [ 'v[0-9]+.[0-9]+.[0-9]+', 'v[0-9]+.[0-9]+.[0-9]+-canary.[0-9]+' ] + tags: [ '[0-9]+.[0-9]+.[0-9]+', '[0-9]+.[0-9]+.[0-9]+-canary.[0-9]+' ] jobs: publish: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4591897..81a25b8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,7 +2,7 @@ name: CI on: push: - tags: [ 'v[0-9]+.[0-9]+.[0-9]+', 'v[0-9]+.[0-9]+.[0-9]+-canary.[0-9]+' ] + tags: [ '[0-9]+.[0-9]+.[0-9]+', '[0-9]+.[0-9]+.[0-9]+-canary.[0-9]+' ] pull_request: branches: [ 'canary' ] From 26d925cb14a345564644b3e545e84f39303ae97b Mon Sep 17 00:00:00 2001 From: Shigure Kurosaki Date: Wed, 4 Dec 2024 18:35:09 +0800 Subject: [PATCH 4/4] fix: GitHub release failed with status: 403 --- .github/workflows/cd.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 849314f..8f742f2 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -4,6 +4,9 @@ on: push: tags: [ '[0-9]+.[0-9]+.[0-9]+', '[0-9]+.[0-9]+.[0-9]+-canary.[0-9]+' ] +permissions: + contents: write + jobs: publish: name: Publishing for ${{ matrix.job.os }}