Skip to content

修复GitHub Pages部署配置,降级Actions版本以兼容 #12

修复GitHub Pages部署配置,降级Actions版本以兼容

修复GitHub Pages部署配置,降级Actions版本以兼容 #12

name: Build and Release
on:
push:
branches: [ main, master ]
# 在推送标签时也触发
tags:
- 'v*' # 匹配格式如 v1.0.0 的标签
# 允许手动触发工作流
workflow_dispatch:
# 添加权限配置
permissions:
contents: write
pages: write
id-token: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: 检出代码
uses: actions/checkout@v3
- name: 设置Node.js环境
uses: actions/setup-node@v3
with:
node-version: '18' # 使用Node.js 18
cache: 'npm'
- name: 修复npm依赖问题
run: |
rm -rf package-lock.json node_modules
npm install
- name: 设置私钥
run: node scripts/setup-private-key.js
env:
EXTENSION_PRIVATE_KEY: ${{ secrets.EXTENSION_PRIVATE_KEY }}
- name: 构建扩展
run: npm run build:extension
- name: 创建ZIP包
run: npm run build:zip
- name: 创建CRX包
run: npm run build:crx
- name: 创建发布文件
run: npm run build:release
- name: 上传构建产物
uses: actions/upload-artifact@v4
with:
name: built-extension
path: |
dist/release/
dist/zip/
dist/crx/
retention-days: 5
# 构建和部署GitHub Pages
deploy-pages:
needs: build
runs-on: ubuntu-latest
# 确保在主分支推送或手动触发时运行,但不在标签推送时运行
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') || github.event_name == 'workflow_dispatch'
# 使用GitHub Pages环境
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: 检出代码
uses: actions/checkout@v3
with:
fetch-depth: 0 # 获取完整的历史记录以支持提交
- name: 下载构建产物
uses: actions/download-artifact@v4
with:
name: built-extension
path: temp-artifacts
- name: 更新演示站点内容
run: |
# 确保目录存在
mkdir -p docs/website/assets/images
mkdir -p docs/website/assets/videos
# 复制最新的扩展文件到演示站点
cp -r temp-artifacts/release/* docs/website/
# 创建重定向到最新版本文件的链接
VERSION=$(cat temp-artifacts/release/version-info.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[", ]//g')
cp temp-artifacts/release/pro-color-v${VERSION}.zip docs/website/pro-color-latest.zip
cp temp-artifacts/release/pro-color-v${VERSION}.crx docs/website/pro-color-latest.crx
# 复制版本信息
cp temp-artifacts/release/version-info.json docs/website/version.json
# 配置GitHub Pages
- name: 设置Pages
id: pages
uses: actions/configure-pages@v3
# 打包页面内容
- name: 打包页面内容
uses: actions/upload-pages-artifact@v2
with:
path: docs/website
# 部署到GitHub Pages
- name: 部署到GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
with:
token: ${{ github.token }}
# 只在标签推送时进行发布
release:
needs: build
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- name: 检出代码
uses: actions/checkout@v3
with:
fetch-depth: 0 # 获取完整的Git历史记录,用于生成更新日志
- name: 下载构建产物
uses: actions/download-artifact@v4
with:
name: built-extension
path: dist
- name: 获取版本号
id: get_version
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
- name: 创建更新日志
id: changelog
run: |
VERSION=${{ steps.get_version.outputs.VERSION }}
echo "## Pro Color 浏览器扩展 v${VERSION}" > CHANGELOG.md
echo "" >> CHANGELOG.md
echo "发布日期: $(date +'%Y-%m-%d')" >> CHANGELOG.md
echo "" >> CHANGELOG.md
echo "### 更新内容" >> CHANGELOG.md
echo "" >> CHANGELOG.md
# 如果有上一个标签,显示自上一个标签以来的提交
PREV_TAG=$(git tag --sort=-v:refname | grep -A 1 "v${VERSION}" | tail -n 1)
if [ ! -z "$PREV_TAG" ] && [ "$PREV_TAG" != "v${VERSION}" ]; then
echo "自 ${PREV_TAG} 以来的更新:" >> CHANGELOG.md
git log ${PREV_TAG}..HEAD --pretty=format:"- %s" --reverse >> CHANGELOG.md
else
echo "- 首次发布" >> CHANGELOG.md
fi
# 将更新日志内容设置为步骤输出
CHANGELOG=$(cat CHANGELOG.md)
echo "CHANGELOG<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGELOG" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: 创建GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ github.ref }}
name: Pro Color v${{ steps.get_version.outputs.VERSION }}
body: ${{ steps.changelog.outputs.CHANGELOG }}
draft: false
prerelease: false
files: |
./dist/release/pro-color-v${{ steps.get_version.outputs.VERSION }}.zip
./dist/release/pro-color-v${{ steps.get_version.outputs.VERSION }}.crx
./dist/release/version-info.json