chore: release v0.9.3 #155
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: Build Packages | |
| on: | |
| push: | |
| branches: [ master ] | |
| tags: [ '*' ] | |
| pull_request: | |
| branches: [ master ] | |
| permissions: | |
| contents: write | |
| actions: write | |
| pages: write | |
| id-token: write | |
| env: | |
| GITHUB_PAGES_URL: https://zccrs.github.io/git-commit-helper | |
| jobs: | |
| build-arch: | |
| runs-on: ubuntu-latest | |
| container: | |
| image: archlinux:base-devel | |
| options: --privileged | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install dependencies | |
| run: | | |
| pacman -Syu --noconfirm | |
| pacman -S --noconfirm rust cargo git | |
| - name: Build package | |
| run: | | |
| useradd builder -m | |
| chown -R builder:builder . | |
| sudo -u builder makepkg -s --noconfirm | |
| - name: Upload Arch Package | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: arch-package | |
| path: ./*.pkg.tar.zst | |
| build-deb: | |
| runs-on: ubuntu-latest | |
| container: | |
| image: debian:sid | |
| options: --privileged | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install dependencies | |
| run: | | |
| apt-get update | |
| apt-get install -y curl build-essential git debhelper pkg-config libssl-dev cargo rustc dpkg-dev | |
| - name: Build package | |
| run: | | |
| dpkg-buildpackage -us -uc | |
| - name: Setup Debian Repository | |
| run: | | |
| mkdir -p deb-repo/pool | |
| mv ../*.deb deb-repo/pool/ | |
| cd deb-repo | |
| dpkg-scanpackages pool /dev/null > Packages | |
| gzip -k Packages | |
| echo "Origin: git-commit-helper" > Release | |
| echo "Label: git-commit-helper" >> Release | |
| echo "Suite: stable" >> Release | |
| echo "Codename: stable" >> Release | |
| echo "Components: main" >> Release | |
| echo "Architectures: amd64" >> Release | |
| echo "Description: Git Commit Helper Repository" >> Release | |
| - name: Upload Debian Package | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: debian-package | |
| path: | | |
| deb-repo/pool/*.deb | |
| deb-repo/Packages* | |
| deb-repo/Release | |
| build-rpm: | |
| runs-on: ubuntu-latest | |
| container: | |
| image: fedora:latest | |
| options: --privileged | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install dependencies | |
| run: | | |
| dnf install -y rust cargo git rpm-build rpmdevtools openssl-devel pkg-config | |
| - name: Build package | |
| run: | | |
| mkdir -p ~/rpmbuild/{SOURCES,SPECS} | |
| cp git-commit-helper.spec ~/rpmbuild/SPECS/ | |
| VERSION=$(grep '^Version:' git-commit-helper.spec | awk '{print $2}') | |
| tar --transform "s,^,git-commit-helper-$VERSION/," -czf ~/rpmbuild/SOURCES/git-commit-helper-$VERSION.tar.gz * | |
| rpmbuild -ba ~/rpmbuild/SPECS/git-commit-helper.spec | |
| - name: Upload RPM Package | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: rpm-package | |
| path: ~/rpmbuild/RPMS/x86_64/*.rpm | |
| build-binary: | |
| strategy: | |
| matrix: | |
| include: | |
| - os: ubuntu-latest | |
| target: x86_64-unknown-linux-gnu | |
| suffix: "" | |
| os_name: "linux" | |
| - os: windows-latest | |
| target: x86_64-pc-windows-msvc | |
| suffix: ".exe" | |
| os_name: "windows" | |
| - os: macos-latest | |
| target: x86_64-apple-darwin | |
| suffix: "" | |
| os_name: "macos" | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: ${{ matrix.target }} | |
| - name: Build Binary | |
| shell: bash | |
| run: | | |
| cargo build --release --target ${{ matrix.target }} | |
| cd target/${{ matrix.target }}/release | |
| mv git-commit-helper${{ matrix.suffix }} git-commit-helper-${{ matrix.os_name }}-${{ matrix.target }}${{ matrix.suffix }} | |
| - name: Upload Binary | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: git-commit-helper-${{ matrix.os_name }}-${{ matrix.target }} | |
| path: target/${{ matrix.target }}/release/git-commit-helper-${{ matrix.os_name }}-${{ matrix.target }}${{ matrix.suffix }} | |
| pre-release: | |
| name: "Pre Release" | |
| needs: [build-arch, build-deb, build-rpm, build-binary] | |
| runs-on: "ubuntu-latest" | |
| if: github.ref_type != 'tag' && github.event_name == 'push' | |
| steps: | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| - name: Create Pre Release | |
| uses: "softprops/action-gh-release@v2" | |
| with: | |
| token: "${{ secrets.GITHUB_TOKEN }}" | |
| prerelease: true | |
| name: "${{ github.ref_name }}" | |
| tag_name: "pre-release-${{ github.run_id }}" | |
| files: | | |
| arch-package/*.pkg.tar.zst | |
| debian-package/pool/*.deb | |
| rpm-package/*.rpm | |
| git-commit-helper-*/* | |
| create-release: | |
| needs: [build-arch, build-deb, build-rpm, build-binary] | |
| runs-on: ubuntu-latest | |
| if: github.ref_type == 'tag' | |
| steps: | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| - name: Create Release | |
| uses: "softprops/action-gh-release@v2" | |
| with: | |
| token: "${{ secrets.GITHUB_TOKEN }}" | |
| prerelease: false | |
| generate_release_notes: true | |
| files: | | |
| arch-package/*.pkg.tar.zst | |
| debian-package/pool/*.deb | |
| rpm-package/*.rpm | |
| git-commit-helper-*/* | |
| deploy-deb-repo: | |
| needs: [create-release] | |
| runs-on: ubuntu-latest | |
| if: github.ref_type == 'tag' | |
| steps: | |
| - name: Download debian repository | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: debian-package | |
| path: deb-repo | |
| - name: Setup Pages | |
| uses: actions/configure-pages@v4 | |
| - name: Upload Debian Repository | |
| uses: actions/upload-pages-artifact@v3 | |
| with: | |
| path: deb-repo | |
| - name: Deploy to GitHub Pages | |
| uses: actions/deploy-pages@v4 | |
| publish_aur: | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'push' | |
| steps: | |
| - uses: actions/checkout@v2 | |
| with: | |
| fetch-depth: 0 # 获取完整的git历史和标签 | |
| - name: Patch PKGBUILD for AUR | |
| run: | | |
| commit_hash="$GITHUB_SHA" | |
| url="https://github.com/zccrs/git-commit-helper/archive/${commit_hash}.tar.gz" | |
| curl -L -o "git-commit-helper-${commit_hash}.tar.gz" "$url" | |
| sha256=$(sha256sum "git-commit-helper-${commit_hash}.tar.gz" | awk '{print $1}') | |
| # 计算版本号:获取最新版本tag(v开头)和从tag到当前commit的距离 | |
| latest_tag=$(git tag --list 'v*' --sort=-version:refname | head -1 || echo "v0.0.0") | |
| tag_version=$(echo "$latest_tag" | sed 's/^v//') | |
| commits_since_tag=$(git rev-list --count ${latest_tag}..HEAD 2>/dev/null || echo "0") | |
| if [ "$commits_since_tag" -gt 0 ]; then | |
| # 如果有新提交,版本号格式为 tag_version.r{commit_count}.{short_hash} | |
| short_hash=$(echo "$commit_hash" | cut -c1-7) | |
| aur_version="${tag_version}.r${commits_since_tag}.${short_hash}" | |
| else | |
| # 如果没有新提交,直接使用tag版本号 | |
| aur_version="$tag_version" | |
| fi | |
| # 输出调试信息并设置环境变量 | |
| echo "=== DEBUG: AUR Version Calculation ===" | |
| echo "Latest tag: $latest_tag" | |
| echo "Tag version: $tag_version" | |
| echo "Commits since tag: $commits_since_tag" | |
| echo "Commit hash: $commit_hash" | |
| echo "AUR version: $aur_version" | |
| echo "Download URL: $url" | |
| echo "SHA256: $sha256" | |
| echo "==================================" | |
| # 设置环境变量供后续步骤使用 | |
| echo "AUR_VERSION=$aur_version" >> $GITHUB_ENV | |
| sed -i "/^source=/c\source=(\"\$pkgname-\$pkgver.tar.gz::$url\")" PKGBUILD | |
| sed -i "/^sha256sums=/c\sha256sums=('$sha256')" PKGBUILD | |
| sed -i "s|cd \"\\\$startdir\"|cd \"\\\$srcdir/\\\$pkgname-${commit_hash}\"|g" PKGBUILD | |
| # 修改 pkgver 并完全删除 pkgver() 函数 | |
| sed -i "/^pkgver=/c\pkgver=$aur_version" PKGBUILD | |
| # 删除整个 pkgver() 函数,避免在非git环境中执行 | |
| sed -i '/^pkgver() {/,/^}/d' PKGBUILD | |
| # 输出修改后的 PKGBUILD 内容以便调试 | |
| echo "" | |
| echo "=== DEBUG: Modified PKGBUILD Content ===" | |
| cat PKGBUILD | |
| echo "========================================" | |
| - name: Publish AUR package (backup method) | |
| uses: KSXGitHub/github-actions-deploy-aur@v4.1.1 | |
| with: | |
| pkgname: git-commit-helper | |
| pkgbuild: ./PKGBUILD | |
| commit_username: zccrs | |
| commit_email: zccrs@live.com | |
| ssh_private_key: ${{ secrets.AUR_SSH_PRIVATE_KEY }} | |
| commit_message: "Update git-commit-helper to ${{ env.AUR_VERSION }} - Auto-published from GitHub Actions" | |
| ssh_keyscan_types: rsa,ecdsa,ed25519 | |
| updpkgsums: false | |
| allow_empty_commits: false | |
| force_push: true |