feat(workflows): 增强发布工作流触发逻辑 #16
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release | |
| permissions: | |
| contents: write | |
| on: | |
| workflow_dispatch: # 允许手动触发工作流 | |
| push: | |
| tags: | |
| - 'v*' # 匹配所有以 v 开头的 tag,如 v1.0.0 | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| fetch-tags: true | |
| - name: List tags | |
| run: git tag | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' # 可根据需要修改 Node.js 版本 | |
| - name: Install dependencies | |
| run: yarn install --frozen-lockfile | |
| - name: Build project | |
| run: yarn build | |
| - name: Set release tag | |
| run: | | |
| if [[ "${GITHUB_REF}" == refs/tags/* ]]; then | |
| echo "RELEASE_TAG=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV | |
| else | |
| TAG=$(git describe --tags --abbrev=0) | |
| TAG=${TAG#v} | |
| echo "RELEASE_TAG=$TAG" >> $GITHUB_ENV | |
| fi | |
| - name: Generate release notes | |
| id: release_notes | |
| run: | | |
| if [[ "${GITHUB_REF}" == refs/tags/* ]]; then | |
| # 获取上一个 tag | |
| PREV_TAG=$(git tag --sort=-creatordate | grep -A1 "${GITHUB_REF_NAME}" | tail -n1) | |
| if [ -z "$PREV_TAG" ]; then | |
| # 没有上一个 tag,取所有历史 | |
| LOG=$(git log --pretty=format:"%s") | |
| else | |
| LOG=$(git log --pretty=format:"%s" "${PREV_TAG}".."${GITHUB_REF_NAME}") | |
| fi | |
| else | |
| # 手动触发时,取最新 tag 和上一个 tag | |
| CUR_TAG=$(git describe --tags --abbrev=0) | |
| PREV_TAG=$(git tag --sort=-creatordate | grep -A1 "${CUR_TAG}" | tail -n1) | |
| if [ -z "$PREV_TAG" ]; then | |
| LOG=$(git log --pretty=format:"%s") | |
| else | |
| LOG=$(git log --pretty=format:"%s" "${PREV_TAG}".."${CUR_TAG}") | |
| fi | |
| fi | |
| echo "RELEASE_BODY<<EOF" >> $GITHUB_ENV | |
| echo "Changes in this Release:" >> $GITHUB_ENV | |
| echo "$LOG" >> $GITHUB_ENV | |
| echo "EOF" >> $GITHUB_ENV | |
| - name: Check dist directory | |
| run: ls -la dist/ | |
| - name: Archive dist folder | |
| run: | | |
| mkdir -p release | |
| cd dist && zip -r ../release/simple-notaion-${RELEASE_TAG}.zip . && cd .. | |
| - name: Upload artifact to GitHub Release | |
| uses: softprops/action-gh-release@v1 | |
| if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' | |
| with: | |
| tag_name: ${{ env.RELEASE_TAG }} | |
| name: Release ${{ env.RELEASE_TAG }} | |
| body: ${{ env.RELEASE_BODY }} | |
| files: release/simple-notaion-${{ env.RELEASE_TAG }}.zip | |
| draft: false | |
| prerelease: false | |
| - name: Explicitly trigger publish workflow | |
| if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' # Only trigger if release was created/published | |
| run: | | |
| gh workflow run publish.yml | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| - name: Clean up zip file | |
| run: rm -rf release/ |