[2.11.4] - 2026-02-25
[2.11.4] - 2026-02-25
【免费下载链接】upload-release-actionUpload files to a GitHub release项目地址: https://gitcode.com/gh_mirrors/up/upload-release-action
- Bump npm versions
[2.11.3] - 2025-11-20
- Post-fix releases created as draft when they shouldn't have - [#99]
## 🔄 自动集成流程:从 CHANGELOG 到 Release 的完整实现 ### 1️⃣ 准备工作:创建基本的工作流文件 首先,我们需要在项目的 `.github/workflows` 目录下创建一个工作流文件,例如 `release.yml`。这个文件将定义触发条件、运行环境和具体步骤。 ### 2️⃣ 读取 CHANGELOG.md 内容:提取当前版本信息 在工作流中,我们需要添加一个步骤来读取 CHANGELOG.md 文件,并提取当前版本的变更内容。可以使用以下代码片段: ```yaml - name: Read CHANGELOG.md and extract release notes id: read_changelog shell: bash run: | # 提取最新版本的变更内容 awk '/^## \[/{if (c) exit; c=1} c' CHANGELOG.md > release_notes.md # 处理特殊字符 r=$(cat release_notes.md) r="${r//'%'/'%25'}" r="${r//$'\n'/'%0A'}" r="${r//$'\r'/'%0D'}" echo "RELEASE_NOTES=$r" >> $GITHUB_OUTPUT3️⃣ 配置 upload-release-action:实现文件上传与发布
接下来,我们需要配置 upload-release-action 步骤,将构建产物和 CHANGELOG 内容上传到 Release:
- name: Upload release assets and notes uses: svenstaro/upload-release-action@v2 with: repo_token: ${{ secrets.GITHUB_TOKEN }} file: target/release/* file_glob: true tag: ${{ github.ref }} overwrite: true body: ${{ steps.read_changelog.outputs.RELEASE_NOTES }} make_latest: true这个配置将:
- 使用 GitHub 提供的令牌进行身份验证
- 上传
target/release/目录下的所有文件 - 覆盖已存在的同名资产
- 将从 CHANGELOG.md 提取的内容作为 Release 描述
- 将当前版本标记为最新版本
💡 高级技巧:优化你的 Release 流程
使用矩阵构建:支持多平台发布
upload-release-action 支持在不同操作系统上运行,结合 GitHub Actions 的矩阵功能,可以轻松实现多平台构建和发布:
strategy: matrix: include: - os: ubuntu-latest artifact_path: target/release/myapp-linux - os: windows-latest artifact_path: target/release/myapp-windows.exe - os: macos-latest artifact_path: target/release/myapp-macos处理预发布和草稿
通过设置prerelease和draft参数,可以灵活控制发布状态:
with: prerelease: true # 标记为预发布 draft: false # 不设为草稿跨仓库发布
如果需要将资产发布到其他仓库,可以使用repo_name参数:
with: repo_name: owner/another-repo repo_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}🚨 常见问题与解决方案
权限问题
如果遇到 "resource not accessible by integration" 错误,需要添加适当的权限:
permissions: contents: write文件路径问题
确保文件路径正确,对于 glob 模式,需要设置file_glob: true:
with: file: dist/*.zip file_glob: true【免费下载链接】upload-release-actionUpload files to a GitHub release项目地址: https://gitcode.com/gh_mirrors/up/upload-release-action
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
