Bumps the github-actions group with 3 updates: [dependabot/fetch-metadata](https://github.com/dependabot/fetch-metadata), [actions/github-script](https://github.com/actions/github-script) and [softprops/action-gh-release](https://github.com/softprops/action-gh-release). Updates `dependabot/fetch-metadata` from 2 to 3 - [Release notes](https://github.com/dependabot/fetch-metadata/releases) - [Commits](https://github.com/dependabot/fetch-metadata/compare/v2...v3) Updates `actions/github-script` from 8 to 9 - [Release notes](https://github.com/actions/github-script/releases) - [Commits](https://github.com/actions/github-script/compare/v8...v9) Updates `softprops/action-gh-release` from 2 to 3 - [Release notes](https://github.com/softprops/action-gh-release/releases) - [Changelog](https://github.com/softprops/action-gh-release/blob/master/CHANGELOG.md) - [Commits](https://github.com/softprops/action-gh-release/compare/v2...v3) --- updated-dependencies: - dependency-name: dependabot/fetch-metadata dependency-version: '3' dependency-type: direct:production update-type: version-update:semver-major dependency-group: github-actions - dependency-name: actions/github-script dependency-version: '9' dependency-type: direct:production update-type: version-update:semver-major dependency-group: github-actions - dependency-name: softprops/action-gh-release dependency-version: '3' dependency-type: direct:production update-type: version-update:semver-major dependency-group: github-actions ... Signed-off-by: dependabot[bot] <support@github.com>
269 lines
11 KiB
YAML
269 lines
11 KiB
YAML
name: 发布扩展到多个应用商店
|
|
|
|
# 工作流触发条件:手动触发,允许指定版本号
|
|
on:
|
|
workflow_dispatch:
|
|
inputs:
|
|
version:
|
|
description: "版本号 (例如: 1.0.0)"
|
|
required: true
|
|
type: string
|
|
|
|
# 工作流权限设置
|
|
permissions:
|
|
contents: write # 创建 GitHub Release 需要
|
|
packages: write # 发布包需要
|
|
|
|
jobs:
|
|
build-and-publish:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
# 第一步:检出源代码
|
|
- name: 检出代码
|
|
uses: actions/checkout@v6
|
|
|
|
# 第二步:设置 Python 环境用于构建脚本
|
|
- name: 设置 Python
|
|
uses: actions/setup-python@v6
|
|
with:
|
|
python-version: "3.11"
|
|
|
|
# 第三步:设置 Node.js 环境用于 JSON 验证
|
|
- name: 设置 Node.js
|
|
uses: actions/setup-node@v6
|
|
with:
|
|
node-version: "18"
|
|
|
|
- name: 安装 Node.js 依赖
|
|
run: npm ci
|
|
|
|
# 第四步:验证 manifest 文件格式
|
|
- name: 验证 manifest 文件
|
|
run: |
|
|
# 验证 Chrome manifest.json 是否为有效的 JSON
|
|
node -e "JSON.parse(require('fs').readFileSync('manifest.json', 'utf8'))"
|
|
echo "[OK] Chrome manifest.json 格式有效"
|
|
|
|
# 验证 Firefox manifest 是否为有效的 JSON
|
|
node -e "JSON.parse(require('fs').readFileSync('manifest-firefox.json', 'utf8'))"
|
|
echo "[OK] Firefox manifest.json 格式有效"
|
|
|
|
# 第五步:设置版本号
|
|
- name: 从输入设置版本
|
|
id: version
|
|
run: |
|
|
# 从工作流输入获取版本号
|
|
VERSION="${{ inputs.version }}"
|
|
if ! printf '%s' "$VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$'; then
|
|
echo "版本号格式非法: $VERSION"
|
|
exit 1
|
|
fi
|
|
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
|
echo "手动设置版本: $VERSION"
|
|
|
|
# 第六步:更新所有配置文件中的版本号
|
|
- name: 更新 manifest 版本
|
|
env:
|
|
VERSION: ${{ steps.version.outputs.version }}
|
|
run: |
|
|
# 更新 Chrome manifest.json 中的版本
|
|
node -e "
|
|
const fs = require('fs');
|
|
const manifest = JSON.parse(fs.readFileSync('manifest.json', 'utf8'));
|
|
manifest.version = process.env.VERSION;
|
|
fs.writeFileSync('manifest.json', JSON.stringify(manifest, null, 2));
|
|
console.log('已更新 Chrome manifest.json 版本为:', manifest.version);
|
|
"
|
|
|
|
# 更新 Firefox manifest.json 中的版本
|
|
node -e "
|
|
const fs = require('fs');
|
|
const manifest = JSON.parse(fs.readFileSync('manifest-firefox.json', 'utf8'));
|
|
manifest.version = process.env.VERSION;
|
|
fs.writeFileSync('manifest-firefox.json', JSON.stringify(manifest, null, 2));
|
|
console.log('已更新 Firefox manifest.json 版本为:', manifest.version);
|
|
"
|
|
|
|
# 第七步:同步更新 package.json 版本
|
|
- name: 更新 package.json 版本
|
|
env:
|
|
VERSION: ${{ steps.version.outputs.version }}
|
|
run: |
|
|
npm version "$VERSION" --no-git-tag-version
|
|
echo "已同步 package.json 和 package-lock.json 版本为: $VERSION"
|
|
|
|
# 第八步:提交版本更改并创建 Git 标签
|
|
- name: 提交并推送版本更新
|
|
run: |
|
|
# 配置 Git 用户信息用于自动提交
|
|
git config --local user.email "action@github.com"
|
|
git config --local user.name "GitHub Action"
|
|
|
|
# 添加更新的文件
|
|
git add manifest.json manifest-firefox.json package.json package-lock.json
|
|
|
|
# 检查是否有需要提交的更改
|
|
if git diff --staged --quiet; then
|
|
echo "没有版本更改需要提交"
|
|
else
|
|
# 提交版本更新
|
|
git commit -m "chore: 更新版本到 ${{ steps.version.outputs.version }} [skip ci]"
|
|
|
|
# 为此版本创建并推送新标签
|
|
git tag "v${{ steps.version.outputs.version }}"
|
|
|
|
# 推送到主分支并包含标签
|
|
git push origin HEAD:main
|
|
git push origin "v${{ steps.version.outputs.version }}"
|
|
|
|
echo "[OK] 版本更新已提交并推送到主分支,包含标签"
|
|
fi
|
|
|
|
- name: 构建扩展包
|
|
run: |
|
|
echo "开始构建扩展包..."
|
|
|
|
# 运行构建脚本构建所有平台
|
|
python build.py --platform all --package
|
|
|
|
echo "扩展包构建完成"
|
|
ls -la packages/ || echo "packages 目录不存在"
|
|
|
|
- name: 运行测试
|
|
run: |
|
|
echo "运行基础测试..."
|
|
python dev.py test
|
|
npm run test:unit
|
|
|
|
echo "运行代码检查..."
|
|
python dev.py lint
|
|
|
|
- name: 发布到 Chrome 应用商店
|
|
continue-on-error: true
|
|
id: chrome-publish
|
|
uses: mnao305/chrome-extension-upload@v6.0.0
|
|
with:
|
|
file-path: packages/Xget-Now_${{ steps.version.outputs.version }}.chromium.zip
|
|
extension-id: ${{ secrets.CHROME_EXTENSION_ID }}
|
|
client-id: ${{ secrets.CHROME_CLIENT_ID }}
|
|
client-secret: ${{ secrets.CHROME_CLIENT_SECRET }}
|
|
refresh-token: ${{ secrets.CHROME_REFRESH_TOKEN }}
|
|
publish: true
|
|
|
|
- name: 发布到 Edge 加载项
|
|
continue-on-error: true
|
|
id: edge-publish
|
|
uses: wdzeng/edge-addon@v2
|
|
with:
|
|
product-id: ${{ secrets.EDGE_PRODUCT_ID }}
|
|
zip-path: packages/Xget-Now_${{ steps.version.outputs.version }}.chromium.zip
|
|
api-key: ${{ secrets.EDGE_API_KEY }}
|
|
client-id: ${{ secrets.EDGE_CLIENT_ID }}
|
|
notes-for-certification: "自动发布 v${{ steps.version.outputs.version }} - ${{ github.sha }}"
|
|
|
|
- name: 发布到 Firefox 附加组件
|
|
continue-on-error: true
|
|
id: firefox-publish
|
|
uses: browser-actions/release-firefox-addon@latest
|
|
with:
|
|
addon-id: ${{ secrets.FIREFOX_ADDON_ID }}
|
|
addon-path: packages/Xget-Now_${{ steps.version.outputs.version }}.firefox.xpi
|
|
auth-api-issuer: ${{ secrets.FIREFOX_AUTH_API_ISSUER }}
|
|
auth-api-secret: ${{ secrets.FIREFOX_AUTH_API_SECRET }}
|
|
approval-note: |
|
|
这是一个下载加速器扩展,支持多个平台的文件下载加速。
|
|
源代码位于 GitHub: https://github.com/xixu-me/Xget-Now
|
|
构建说明:直接从源代码打包,无需编译或转译。
|
|
|
|
- name: 创建 GitHub 发布
|
|
uses: softprops/action-gh-release@v3
|
|
with:
|
|
tag_name: v${{ steps.version.outputs.version }}
|
|
name: Xget Now ${{ steps.version.outputs.version }}
|
|
files: |
|
|
packages/Xget-Now_${{ steps.version.outputs.version }}.chromium.zip
|
|
packages/Xget-Now_${{ steps.version.outputs.version }}.firefox.xpi
|
|
packages/Xget-Now_${{ steps.version.outputs.version }}.userscript.user.js
|
|
generate_release_notes: true
|
|
body: |
|
|
## 扩展包下载
|
|
|
|
### Chromium
|
|
- **文件**: `Xget-Now_${{ steps.version.outputs.version }}.chromium.zip`
|
|
- **支持**: Chrome、Edge 等基于 Chromium 的浏览器
|
|
- **Manifest**: v3
|
|
|
|
### Firefox
|
|
- **文件**: `Xget-Now_${{ steps.version.outputs.version }}.firefox.xpi`
|
|
- **支持**: Firefox 或其他基于 Firefox 的浏览器
|
|
- **Manifest**: v2
|
|
|
|
### Userscript
|
|
- **文件**: `Xget-Now_${{ steps.version.outputs.version }}.userscript.user.js`
|
|
- **支持**: 用户脚本管理器
|
|
- **能力**: GitHub、GitLab、Gitea、Codeberg、Hugging Face、PyPI、npm、SourceForge 下载加速
|
|
|
|
## 安装方法
|
|
|
|
详细的安装说明请参考:[手动安装指南](https://github.com/xixu-me/Xget-Now?tab=readme-ov-file#%E6%89%8B%E5%8A%A8%E5%AE%89%E8%A3%85)
|
|
|
|
## 更新日志
|
|
|
|
详细的更改内容请查看下方的自动生成的发布说明。
|
|
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: 检查发布结果
|
|
run: |
|
|
echo "发布结果摘要:"
|
|
echo "================================"
|
|
echo "版本: ${{ steps.version.outputs.version }}"
|
|
echo ""
|
|
|
|
if [ "${{ steps.chrome-publish.outcome }}" = "success" ]; then
|
|
echo "[OK] Chrome 应用商店: 发布成功"
|
|
elif [ "${{ steps.chrome-publish.outcome }}" = "failure" ]; then
|
|
echo "[FAIL] Chrome 应用商店: 发布失败"
|
|
else
|
|
echo "[WARN] Chrome 应用商店: 已跳过(缺少密钥或其他原因)"
|
|
fi
|
|
|
|
if [ "${{ steps.edge-publish.outcome }}" = "success" ]; then
|
|
echo "[OK] Edge 加载项: 发布成功"
|
|
elif [ "${{ steps.edge-publish.outcome }}" = "failure" ]; then
|
|
echo "[FAIL] Edge 加载项: 发布失败"
|
|
else
|
|
echo "[WARN] Edge 加载项: 已跳过(缺少密钥或其他原因)"
|
|
fi
|
|
|
|
if [ "${{ steps.firefox-publish.outcome }}" = "success" ]; then
|
|
echo "[OK] Firefox 附加组件: 发布成功"
|
|
elif [ "${{ steps.firefox-publish.outcome }}" = "failure" ]; then
|
|
echo "[FAIL] Firefox 附加组件: 发布失败"
|
|
else
|
|
echo "[WARN] Firefox 附加组件: 已跳过(缺少密钥或其他原因)"
|
|
fi
|
|
|
|
echo ""
|
|
echo "[OK] GitHub 发布: 已创建包含所有扩展文件"
|
|
echo "================================"
|
|
|
|
- name: 通知成功
|
|
run: |
|
|
echo ""
|
|
echo "成功发布 Xget Now ${{ steps.version.outputs.version }}"
|
|
echo "================================"
|
|
echo "Chrome 应用商店: https://chrome.google.com/webstore/detail/${{ secrets.CHROME_EXTENSION_ID }}"
|
|
echo "Edge 加载项: 查看发布页面获取最新信息"
|
|
echo "Firefox 附加组件: 查看 Mozilla Add-ons 获取最新信息"
|
|
echo "GitHub 发布: https://github.com/${{ github.repository }}/releases/tag/v${{ steps.version.outputs.version }}"
|
|
echo "安装指南: https://github.com/${{ github.repository }}#installation"
|
|
echo ""
|
|
echo "发布的文件:"
|
|
echo " - Xget-Now_${{ steps.version.outputs.version }}.chromium.zip (Chromium)"
|
|
echo " - Xget-Now_${{ steps.version.outputs.version }}.firefox.xpi (Firefox)"
|
|
echo " - Xget-Now_${{ steps.version.outputs.version }}.userscript.user.js (Userscript)"
|
|
echo "================================"
|