Skip to content

feat: update

feat: update #38

Workflow file for this run

# 整个流程的名字
name: Release
# 触发时机,在 tag 被 push 操作触发
on:
push:
tags:
- "v*"
permissions:
id-token: write # Required for OIDC
contents: write
# 任务,定义个changelog 的任务
jobs:
changelog:
name: Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Use Node.js 18.x
uses: actions/setup-node@v6
with:
node-version: 24
registry-url: https://registry.npmjs.org
- uses: pnpm/action-setup@v5
with:
version: 8
# 安装依赖
- name: Install dependencies
run: |
pnpm install --no-frozen-lockfile
- name: Check file versions
run: |
files="dist/index.js dist/index.esm.js package.json"
version=""
inconsistent=false
for file in $files; do
if [ ! -f "$file" ]; then
echo "缺少文件: $file"
inconsistent=true
continue
fi
v=$(head -3 "$file" | grep -Eo '([0-9]+\.[0-9]+\.[0-9]+)+(-[a-z]+\.[0-9]+)?')
if [ -z "$v" ]; then
echo "文件 $file 未检测到版本号"
inconsistent=true
continue
fi
if [ -z "$version" ]; then
version="$v"
else
if [ "$version" != "$v" ]; then
echo "文件 $file 的版本号 $v 与其它文件版本号 $version 不一致"
inconsistent=true
fi
fi
done
if [ "$inconsistent" = true ]; then
echo "版本号不一致,禁止推送!"
exit 1
fi
echo "所有文件版本号一致: $version"
# 获取 tag 的版本类型(仅支持 正式版、alpha和beta版)
- name: Determine release tag
id: determine_tag
run: |
TAG=$(echo "${GITHUB_REF}" | sed 's/refs\/tags\/\(.*\)/\1/')
if [[ "$TAG" =~ -alpha ]]; then
echo "tag=alpha" >> "$GITHUB_OUTPUT"
elif [[ "$TAG" =~ -beta ]]; then
echo "tag=beta" >> "$GITHUB_OUTPUT"
elif [[ "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "tag=latest" >> "$GITHUB_OUTPUT"
else
echo "Unsupported version detected. Terminating."
exit 1
fi
# # 打包
# - name: Build Packages
# run: pnpm run build
# 发布npm 发布前执行了prepublishOnly
- name: Publish npm
run: npm publish --tag ${{ steps.determine_tag.outputs.tag }} --access public
- name: Build sha
run: echo ${{ github.sha }} > Release.txt
- name: Test
run: cat Release.txt
# 打包 dist 为自定义压缩包
- name: Create release archive
run: |
PKG_NAME=$(node -p "require('./package.json').name.replace('@ezuikit/', '')")
VERSION=$(node -p "require('./package.json').version")
ARCHIVE_NAME="${PKG_NAME}-${VERSION}"
# 创建包含 dist 和 package.json 的 zip 包
zip -r "${ARCHIVE_NAME}.zip" dist/ package.json
# 创建包含 dist 和 package.json 的 tar.gz 包
tar -czf "${ARCHIVE_NAME}.tar.gz" dist/ package.json
echo "archive_name=${ARCHIVE_NAME}" >> "$GITHUB_OUTPUT"
id: archive
# 自动创建 GitHub Release
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref_name }}
name: ${{ github.ref_name }}
generate_release_notes: true
prerelease: ${{ steps.determine_tag.outputs.tag != 'latest' }}
files: |
${{ steps.archive.outputs.archive_name }}.zip
${{ steps.archive.outputs.archive_name }}.tar.gz
Release.txt