nazhua/.github/workflows/release.yml

142 lines
4.9 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: '指定版本号: v(*.*.*)'
required: false
jobs:
build-and-release:
runs-on: ubuntu-latest
steps:
- name: 选择Node版本
uses: actions/setup-node@v3
with:
node-version: '20' # 根据项目需求调整版本
- name: 从package.json读取版本号
id: get_version
run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
- name: 读取或指定版本号
id: determine_version
run: |
if [ "${{ github.event.inputs.version }}" ]; then
echo "version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
else
echo "version=${{ steps.get_version.outputs.version }}" >> $GITHUB_OUTPUT
fi
- name: 初始化构建环境
run: npm install
- name: 创建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: 上传v0全量包
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: 上传v0的cdn-jsdelivr包
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: 上传v0的cdn-loli包
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: 上传v1的发行包
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: |
# 获取现有的发布说明
gh release view v${{ steps.determine_version.outputs.version }} --json body -q .body > body.txt
# 获取最近一次提交的变更内容
git log $(git describe --tags --abbrev=0)..HEAD --pretty=format:"%s%n%b" >> body.txt
# 添加其他发布说明
echo -e "\n哪吒V1请下载dist.zip\n哪吒V0请下载v0-${{ steps.determine_version.outputs.version }}-cdn-jsdelivr.zip\n -all是全量包-cdn-jsdelivr是jsdelivr引用版-cdn-loli是cdnjs的loli.net引用版\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 }}