Merge remote-tracking branch 'refs/remotes/origin/master'核心稳定性改进 #66
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: Rust Auto-Release (macOS + Linux) | |
| on: | |
| push: | |
| branches: [ master ] # 自动 → Pre-release | |
| paths-ignore: | |
| - '**/Buildtag.md' | |
| - '**/README.md' | |
| pull_request: | |
| branches: [ master ] | |
| workflow_dispatch: # 手动可升正式 | |
| inputs: | |
| official: | |
| description: "Set true to publish **official Release**" | |
| required: false | |
| default: "false" | |
| permissions: | |
| contents: write | |
| env: { CARGO_TERM_COLOR: always } | |
| jobs: | |
| release: | |
| runs-on: macos-14 | |
| permissions: { contents: write } | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # 获取完整历史,避免shallow clone问题 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| # 1) 读取版本号 | |
| - name: Get version | |
| id: ver | |
| run: | | |
| V=$(grep -m1 '^version' Cargo.toml | sed -E 's/.*"([^"]+)".*/\1/') | |
| echo "version=$V" >>"$GITHUB_OUTPUT" | |
| # 2) 生成发布信息 & 类型 | |
| - name: Prepare release meta | |
| id: meta | |
| run: | | |
| IS_PRE=true | |
| BODY_FILE="PRE.md" | |
| if [[ "${{ github.event_name }}" == "workflow_dispatch" && "${{ inputs.official }}" == "true" ]]; then | |
| IS_PRE=false | |
| BODY_FILE="RELEASE.md" | |
| fi | |
| echo "pre=$IS_PRE" >>"$GITHUB_OUTPUT" | |
| echo "body=$BODY_FILE" >>"$GITHUB_OUTPUT" | |
| # 写入内容 | |
| if $IS_PRE; then | |
| echo "⚠️ 自动生成的 *预发布* 包,我没有义务为其提供技术支持" > PRE.md | |
| else | |
| echo "### 变更日志\n\n- TODO: 手动填写改动" > RELEASE.md | |
| fi | |
| # 3) 若 tag 不存在则创建 | |
| - name: Ensure tag | |
| run: | | |
| TAG="v${{ steps.ver.outputs.version }}" | |
| git fetch --tags | |
| git tag -f -a "$TAG" -m "Release $TAG" | |
| git push -f origin "$TAG" | |
| # 4) 安装依赖 | |
| - name: Install toolchains & musl/upx | |
| run: | | |
| brew install FiloSottile/musl-cross/musl-cross upx | |
| - uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: | | |
| x86_64-apple-darwin | |
| aarch64-apple-darwin | |
| x86_64-unknown-linux-musl | |
| aarch64-unknown-linux-musl | |
| # 5) 构建 | |
| - name: Build artifacts | |
| run: bash allrelease.sh | |
| # 6) 推送Buildtag.md - 修复版本 | |
| - name: Update buildtag | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| # 更简单直接的方法 | |
| if [[ -f "Buildtag.md" ]]; then | |
| # 直接提交当前更改 | |
| git add Buildtag.md | |
| # 检查是否有更改需要提交 | |
| if ! git diff --cached --quiet; then | |
| git commit -m "Update buildtag from GitHub Action [skip ci]" | |
| # 尝试推送,如果失败则先拉取再推送 | |
| if ! git push origin master; then | |
| echo "Push failed, pulling and retrying..." | |
| git pull --rebase origin master | |
| git push origin master | |
| fi | |
| else | |
| echo "No changes to commit" | |
| fi | |
| else | |
| echo "Buildtag.md not found" | |
| fi | |
| # 7) 发布 | |
| - name: Publish release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: v${{ steps.ver.outputs.version }} | |
| name: v${{ steps.ver.outputs.version }} | |
| prerelease: ${{ steps.meta.outputs.pre == 'true' }} | |
| body_path: ${{ steps.meta.outputs.body }} | |
| files: target/dist/* |