nazhua/.github/workflows/release.yml

151 lines
5.2 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

name: Build and Release
on:
push:
tags:
- 'v*.*.*'
workflow_dispatch:
inputs:
version:
description: 'Version to release'
required: false
jobs:
build-and-release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 2 # 获取最近的两次提交
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '20' # 根据项目需求调整版本
- name: Install dependencies
run: npm install
- name: Get version from package.json
id: get_version
run: echo "::set-output name=version::$(node -p "require('./package.json').version")"
- name: Determine version
id: determine_version
run: |
if [ "${{ github.event.inputs.version }}" ]; then
echo "::set-output name=version::${{ github.event.inputs.version }}"
else
echo "::set-output name=version::${{ steps.get_version.outputs.version }}"
fi
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.determine_version.outputs.version }}
release_name: Release v${{ steps.determine_version.outputs.version }}
draft: false
prerelease: false
- name: 构建v0版本 - 完整引用版本
run: npm run build
- name: 打包v0-${{ steps.determine_version.outputs.version }}-all.zip
run: zip -r v0-${{ steps.determine_version.outputs.version }}-all.zip dist
- name: 构建v0版本 - JSDeliver引用版本
env:
VITE_SARASA_TERM_SC_USE_CDN: '1'
VITE_USE_CDN: '1'
VITE_CDN_LIB_TYPE: 'jsdelivr'
run: npm run build
- name: 打包v0-${{ steps.determine_version.outputs.version }}-cdn-jsdelivr.zip
run: zip -r v0-${{ steps.determine_version.outputs.version }}-cdn-jsdelivr.zip dist
- name: 构建v0版本 - loli(CDNJS)引用版本
env:
VITE_SARASA_TERM_SC_USE_CDN: '1'
VITE_USE_CDN: '1'
VITE_CDN_LIB_TYPE: 'loli'
run: npm run build
- name: 打包v0-${{ steps.determine_version.outputs.version }}-cdn-loli.zip
run: zip -r v0-${{ steps.determine_version.outputs.version }}-cdn-loli.zip dist
- name: 构建哪吒v1内置版本
env:
VITE_NEZHA_VERSION: 'v1'
VITE_SARASA_TERM_SC_USE_CDN: '1'
VITE_USE_CDN: '1'
VITE_CDN_LIB_TYPE: 'jsdelivr'
run: npm run build
- name: 打包dist.zip
run: zip -r dist.zip dist
- name: Upload v0-${{ steps.determine_version.outputs.version }}-all.zip
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./v0-${{ steps.determine_version.outputs.version }}-all.zip
asset_name: v0-${{ steps.determine_version.outputs.version }}-all.zip
asset_content_type: application/zip
- name: Upload v0-${{ steps.determine_version.outputs.version }}-cdn-jsdelivr.zip
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./v0-${{ steps.determine_version.outputs.version }}-cdn-jsdelivr.zip
asset_name: v0-${{ steps.determine_version.outputs.version }}-cdn-jsdelivr.zip
asset_content_type: application/zip
- name: Upload v0-${{ steps.determine_version.outputs.version }}-cdn-loli.zip
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./v0-${{ steps.determine_version.outputs.version }}-cdn-loli.zip
asset_name: v0-${{ steps.determine_version.outputs.version }}-cdn-loli.zip
asset_content_type: application/zip
- name: Upload dist.zip
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./dist.zip
asset_name: dist.zip
asset_content_type: application/zip
- name: Add release notes
run: |
# 获取最近一次提交的变更内容
git log -1 > changes.txt
# 获取现有的发布说明
gh release view v${{ steps.determine_version.outputs.version }} --json body -q .body > body.txt
# 将变更内容添加到发布说明中
echo -e "### 本次发布\n" >> body.txt
cat changes.txt >> body.txt
# 添加其他发布说明
echo -e "\n哪吒V1请下载dist.zip\n哪吒V0请下载v0-${{ steps.determine_version.outputs.version }}-(all|cdn-jsdelivr|cdn-loli).zip\n`all`是全量包,`cdn-jsdelivr`是jsdelivr引用版`cdn-loli`是cdnjs引用版\nv0版本构建物通过修改`./config.js`指定`nezhaVersion`版本为`v1`可以匹配哪吒v1接口" >> body.txt
# 更新发布说明
gh release edit v${{ steps.determine_version.outputs.version }} --notes-file body.txt
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}