Release #19
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 | |
| actions: write # 增加 actions 写入权限以触发其他工作流 | |
| 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 and version number | |
| run: | | |
| # 获取原始 tag 名称 (e.g., v1.0.21) | |
| RELEASE_TAG=$(git describe --tags --abbrev=0) | |
| echo "RELEASE_TAG=$RELEASE_TAG" >> $GITHUB_ENV | |
| # 提取不带 v 的版本号部分 (e.g., 1.0.21),用于 Release 名称和文件名 | |
| VERSION_NUMBER=${RELEASE_TAG#v} | |
| echo "VERSION_NUMBER=$VERSION_NUMBER" >> $GITHUB_ENV | |
| - 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-${{ env.VERSION_NUMBER }}.zip . && cd .. # 使用不带 v 的版本号命名 zip 文件 | |
| - 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 }} # 使用原始 tag v1.0.21,关联 release 到它 | |
| name: Release ${{ env.VERSION_NUMBER }} # Release 名称使用不带 v 的版本号 1.0.21 | |
| body: ${{ env.RELEASE_BODY }} | |
| files: release/simple-notaion-${{ env.VERSION_NUMBER }}.zip # 关联 zip 文件,使用不带 v 的版本号命名 | |
| 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/ |