From cfda03bda13a668b5bd8a4afc13ad8941e692437 Mon Sep 17 00:00:00 2001 From: Seimizu Joukan Date: Fri, 19 Dec 2025 19:21:46 +0900 Subject: [PATCH 1/3] Add workflow to create tag and release. --- .github/workflows/release.yml | 176 ++++++++++++++++++++++++++++++++++ Cargo.toml | 16 ++++ 2 files changed, 192 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..da67723 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,176 @@ +name: Release + +on: + push: + branches: [ main ] + paths: + - 'Cargo.toml' + +env: + CARGO_TERM_COLOR: always + +jobs: + check-version: + name: Check Version Change + runs-on: ubuntu-latest + outputs: + version_changed: ${{ steps.check.outputs.changed }} + new_version: ${{ steps.check.outputs.version }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 2 + + - name: Check if version changed + id: check + run: | + # Get current version from Cargo.toml + CURRENT_VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/') + echo "Current version: $CURRENT_VERSION" + + # Get previous version from the previous commit + git checkout HEAD~1 -- Cargo.toml 2>/dev/null || true + PREVIOUS_VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/' || echo "") + git checkout HEAD -- Cargo.toml + echo "Previous version: $PREVIOUS_VERSION" + + # Check if version changed + if [ "$CURRENT_VERSION" != "$PREVIOUS_VERSION" ] && [ -n "$CURRENT_VERSION" ]; then + echo "changed=true" >> $GITHUB_OUTPUT + echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT + echo "Version changed from $PREVIOUS_VERSION to $CURRENT_VERSION" + else + echo "changed=false" >> $GITHUB_OUTPUT + echo "Version unchanged" + fi + + build: + name: Build Release Packages + needs: check-version + if: needs.check-version.outputs.version_changed == 'true' + runs-on: ubuntu-latest + strategy: + matrix: + target: + - arch: x86_64 + rust_target: x86_64-unknown-linux-gnu + - arch: aarch64 + rust_target: aarch64-unknown-linux-gnu + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + target: ${{ matrix.target.rust_target }} + override: true + + - name: Install cargo-deb + run: cargo install cargo-deb + + - name: Install cross-compilation tools + if: matrix.target.arch == 'aarch64' + run: | + sudo apt-get update + sudo apt-get install -y gcc-aarch64-linux-gnu + + - name: Build binary + run: | + if [ "${{ matrix.target.arch }}" = "aarch64" ]; then + export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc + fi + cargo build --release --target ${{ matrix.target.rust_target }} + + - name: Create Debian package + run: | + cargo deb --target ${{ matrix.target.rust_target }} --no-build + + - name: Rename package + run: | + VERSION="${{ needs.check-version.outputs.new_version }}" + PKG_NAME="ghr_${VERSION}_${{ matrix.target.arch }}.deb" + mv target/${{ matrix.target.rust_target }}/debian/*.deb "$PKG_NAME" + echo "PKG_PATH=$PKG_NAME" >> $GITHUB_ENV + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: deb-${{ matrix.target.arch }} + path: ${{ env.PKG_PATH }} + + create-release: + name: Create GitHub Release + needs: [check-version, build] + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Download all artifacts + uses: actions/download-artifact@v4 + with: + path: artifacts + + - name: Generate changelog + id: changelog + run: | + VERSION="${{ needs.check-version.outputs.new_version }}" + + # Get the previous tag + PREVIOUS_TAG=$(git tag --sort=-version:refname | grep -E '^v[0-9]' | head -1 || echo "") + + if [ -n "$PREVIOUS_TAG" ]; then + echo "Generating changelog from $PREVIOUS_TAG to HEAD" + CHANGELOG=$(git log ${PREVIOUS_TAG}..HEAD --pretty=format:"- %s (%h)" --no-merges) + else + echo "No previous tag found, generating changelog from beginning" + CHANGELOG=$(git log --pretty=format:"- %s (%h)" --no-merges) + fi + + # Create changelog file + cat > CHANGELOG.txt << EOF + Release v${VERSION} + + ## Changes + + ${CHANGELOG} + EOF + + echo "Changelog created" + cat CHANGELOG.txt + + - name: Create Git Tag + run: | + VERSION="${{ needs.check-version.outputs.new_version }}" + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git tag -a "v${VERSION}" -m "Release v${VERSION}" + git push origin "v${VERSION}" + + - name: Create source tarball + run: | + VERSION="${{ needs.check-version.outputs.new_version }}" + git archive --format=tar.gz --prefix=ghr-${VERSION}/ HEAD > ghr-${VERSION}.tar.gz + + - name: Create GitHub Release + uses: softprops/action-gh-release@v1 + with: + tag_name: v${{ needs.check-version.outputs.new_version }} + name: v${{ needs.check-version.outputs.new_version }} + body_path: CHANGELOG.txt + draft: false + prerelease: false + files: | + ghr-${{ needs.check-version.outputs.new_version }}.tar.gz + artifacts/deb-x86_64/*.deb + artifacts/deb-aarch64/*.deb + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/Cargo.toml b/Cargo.toml index 38891b0..536e4a9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,3 +26,19 @@ futures = "0.3" indicatif = "0.17" urlencoding = "2.1" +[package.metadata.deb] +maintainer = "Seimizu Joukan " +copyright = "2025, Seimizu Joukan " +license-file = ["LICENSE", "4"] +extended-description = """\ +A fast, simple command-line tool for fetching and downloading GitHub release assets. +Features include pattern matching for assets, concurrent downloads, interactive selection, +and repository search with private repository support.""" +depends = "$auto" +section = "utility" +priority = "optional" +assets = [ + ["target/release/ghr", "usr/bin/", "755"], + ["README.md", "usr/share/doc/ghr/", "644"], +] + From 00468ba2594cb280bc5bb78dbf5fde9e6475f725 Mon Sep 17 00:00:00 2001 From: Seimizu Joukan Date: Fri, 19 Dec 2025 19:28:21 +0900 Subject: [PATCH 2/3] Update pr-check to verify on arm64. --- .github/workflows/pr-check.yml | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index a2e841e..6f48809 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -27,8 +27,15 @@ jobs: run: cargo fmt --check test: - name: Unit Tests - runs-on: ubuntu-latest + name: Unit Tests (${{ matrix.arch }}) + runs-on: ${{ matrix.runner }} + strategy: + matrix: + include: + - arch: x86_64 + runner: ubuntu-latest + - arch: arm64 + runner: ubuntu-24.04-arm steps: - name: Checkout code uses: actions/checkout@v4 @@ -44,25 +51,25 @@ jobs: uses: actions/cache@v4 with: path: ~/.cargo/registry - key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} + key: ${{ runner.os }}-${{ matrix.arch }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} restore-keys: | - ${{ runner.os }}-cargo-registry- + ${{ runner.os }}-${{ matrix.arch }}-cargo-registry- - name: Cache cargo index uses: actions/cache@v4 with: path: ~/.cargo/git - key: ${{ runner.os }}-cargo-git-${{ hashFiles('**/Cargo.lock') }} + key: ${{ runner.os }}-${{ matrix.arch }}-cargo-git-${{ hashFiles('**/Cargo.lock') }} restore-keys: | - ${{ runner.os }}-cargo-git- + ${{ runner.os }}-${{ matrix.arch }}-cargo-git- - name: Cache cargo build uses: actions/cache@v4 with: path: target - key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }} + key: ${{ runner.os }}-${{ matrix.arch }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }} restore-keys: | - ${{ runner.os }}-cargo-build-target- + ${{ runner.os }}-${{ matrix.arch }}-cargo-build-target- - name: Run tests run: cargo test --verbose From 78b090cc7e20e774c5496f98bf3a4febd57cd793 Mon Sep 17 00:00:00 2001 From: Seimizu Joukan Date: Fri, 19 Dec 2025 19:56:01 +0900 Subject: [PATCH 3/3] Switch to use arm64 runner to create package for arm64. --- .github/workflows/release.yml | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index da67723..e65d572 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -49,14 +49,16 @@ jobs: name: Build Release Packages needs: check-version if: needs.check-version.outputs.version_changed == 'true' - runs-on: ubuntu-latest + runs-on: ${{ matrix.target.runner }} strategy: matrix: target: - arch: x86_64 rust_target: x86_64-unknown-linux-gnu - - arch: aarch64 + runner: ubuntu-latest + - arch: arm64 rust_target: aarch64-unknown-linux-gnu + runner: ubuntu-24.04-arm steps: - name: Checkout code uses: actions/checkout@v4 @@ -72,17 +74,11 @@ jobs: - name: Install cargo-deb run: cargo install cargo-deb - - name: Install cross-compilation tools - if: matrix.target.arch == 'aarch64' - run: | - sudo apt-get update - sudo apt-get install -y gcc-aarch64-linux-gnu + - name: Install OpenSSL + run: sudo apt-get update && sudo apt-get install -y libssl-dev - name: Build binary run: | - if [ "${{ matrix.target.arch }}" = "aarch64" ]; then - export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc - fi cargo build --release --target ${{ matrix.target.rust_target }} - name: Create Debian package @@ -171,6 +167,6 @@ jobs: files: | ghr-${{ needs.check-version.outputs.new_version }}.tar.gz artifacts/deb-x86_64/*.deb - artifacts/deb-aarch64/*.deb + artifacts/deb-arm64/*.deb env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}