Skip to content

Commit

Permalink
chore(release): update release workflow to manage pre-release version…
Browse files Browse the repository at this point in the history
…s and check for Git tags

- Modified cache key to include package.json and yarn.lock for better dependency management.
- Added steps to enter and exit Changeset pre-release mode based on branch names.
- Implemented a check for Git tags before publishing GitHub Releases, ensuring releases only occur when a tag exists.
  • Loading branch information
cycleccc committed Jan 4, 2025
1 parent c3ab3cc commit e3c58b0
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
**/node_modules
**/.turbo
/home/runner/.cache/Cypress
key: ${{ runner.os }}-node-${{ matrix.node-version }}-${{ hashFiles('**/package-lock.json') }}
key: ${{ runner.os }}-node-${{ matrix.node-version }}-${{ hashFiles('**/package.json', '**/yarn.lock') }}

# 安装依赖
- name: Install dependencies
Expand All @@ -78,27 +78,47 @@ jobs:
start: yarn run example
wait-on: 'http://localhost:8881/examples/default-mode.html'

# 创建 Release PR 或发布稳定版本到 npm
- name: Create Release PR or publish stable version to npm
# 创建测试版本或稳定版本的 Release PR
- name: Manage Changeset Pre-release Mode
if: startsWith(github.ref_name, 'dev') || github.ref_name == 'develop'
run: yarn changeset pre enter alpha || true

- name: Exit Changeset Pre-release Mode
if: github.ref_name == 'master'
run: yarn changeset pre exit || true

- name: Create Release PR or publish version to npm
id: changesets
uses: changesets/action@v1
with:
createGithubReleases: false
publish: yarn changeset publish --access=public
title: ${{ github.ref_name == 'master' && 'Publish a new stable version' || 'Publish a new pre-release version' }}
title: >-
${{ github.ref_name == 'master' && 'Publish a new stable version' || 'Publish a new pre-release version' }}
commit: >-
${{ github.ref_name == 'master' && 'chore(release): publish a new release version' || 'chore(release): publish a new pre-release version' }}
${{ github.ref_name == 'master' && 'chore(release): publish a new release version' || 'chore(release): publish a new pre-release version' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

# 发布 GitHub Release 仅针对 editor 包
# 检查是否有 Git 标签
- name: Check for Git tag
id: check_tag
run: |
if [ -z "$(git tag --points-at HEAD)" ]; then
echo "tag_exists=false" >> $GITHUB_OUTPUT
else
echo "tag_exists=true" >> $GITHUB_OUTPUT
fi
# 发布 GitHub Release,仅针对 editor 包
- name: Publish GitHub Release for editor
if: ${{ github.ref_name == 'master' }} # 仅在 master 分支发布
if: steps.check_tag.outputs.tag_exists == 'true' # 仅在存在标签时发布
uses: softprops/action-gh-release@v1
with:
generate_release_notes: true
files: |
packages/editor/dist/** # 仅附加 editor 包的构建产物
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit e3c58b0

Please sign in to comment.