fix(ci): remove hardcoded pnpm version 9 from rn-release and deploy-t… #329
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: publish | |
| on: | |
| # When Release Pull Request is merged | |
| push: | |
| branches: | |
| - 'chore/**' | |
| - 'feat/**' | |
| - next | |
| pull_request: | |
| branches: | |
| - next | |
| types: [closed] | |
| workflow_dispatch: | |
| env: | |
| CI: true | |
| NODE_OPTIONS: --openssl-legacy-provider | |
| permissions: {} | |
| jobs: | |
| publish: | |
| # 仅 release 提交(chore(release):)触发;job 级 if 不允许引用 env 上下文, | |
| # 必须从 github.event 读取 commit message。workflow_dispatch 用于手动补发。 | |
| if: | | |
| github.event_name == 'workflow_dispatch' || | |
| startsWith(github.event.head_commit.message, 'chore(release):') || | |
| (github.event_name == 'pull_request' && github.event.pull_request.merged == true && startsWith(github.event.pull_request.title, 'chore(release):')) | |
| permissions: | |
| contents: write # to create tags and refs | |
| actions: write # to cancel running workflow (andymckay/cancel-action) | |
| issues: write # to create comment | |
| pull-requests: write # to create comment and so on | |
| name: publish | |
| runs-on: ubuntu-latest | |
| steps: | |
| # Setup | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Node ${{ matrix.node_version }} | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 18 | |
| registry-url: 'https://registry.npmjs.org' | |
| - name: Git Identity | |
| run: | | |
| git config --global user.name 'github-actions[bot]' | |
| git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
| git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/$GITHUB_REPOSITORY | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| # Log meta | |
| - name: GITHUB CONTEXT | |
| env: | |
| GITHUB_CONTEXT: ${{ toJson(github) }} | |
| run: echo "$GITHUB_CONTEXT" | |
| # Get commit message | |
| - name: Get commit message | |
| run: | | |
| COMMIT_MESSAGE=$(git log --format=%s -n 1) | |
| echo "COMMIT_MESSAGE=${COMMIT_MESSAGE}" >> $GITHUB_ENV | |
| - name: Show commit message | |
| run: echo "$COMMIT_MESSAGE" | |
| # Get & check npm publish | |
| - name: Get publish params | |
| if: github.event_name == 'push' | |
| run: | | |
| PUBLISH_PARAMS=`echo $COMMIT_MESSAGE | grep -oE "^chore\(release\): publish \S*\s(.*)" | cut -d " " -f 4-` | |
| echo "PUBLISH_PARAMS=${PUBLISH_PARAMS}" >> $GITHUB_ENV | |
| - name: Show publish params | |
| if: github.event_name == 'push' | |
| run: echo "Publish pushing provide parameter [$PUBLISH_PARAMS]." | |
| # Define ${CURRENT_VERSION} | |
| - name: Set Current Version | |
| if: startsWith( env.COMMIT_MESSAGE , 'chore(release):' ) | |
| shell: bash -ex {0} | |
| run: | | |
| CURRENT_VERSION=$(node -p 'require("./packages/taro-ui/package.json").version') | |
| echo "CURRENT_VERSION=${CURRENT_VERSION}" >> $GITHUB_ENV | |
| # Check git tag | |
| - name: Tag Check | |
| if: startsWith( env.COMMIT_MESSAGE , 'chore(release):' ) | |
| id: tag_check | |
| shell: bash -ex {0} | |
| run: | | |
| GET_API_URL="https://api.github.com/repos/${GITHUB_REPOSITORY}/git/ref/tags/v${CURRENT_VERSION}" | |
| http_status_code=$(curl -LI $GET_API_URL -o /dev/null -w '%{http_code}\n' -s \ | |
| -H "Authorization: token ${GITHUB_TOKEN}") | |
| if [ "$http_status_code" -ne "404" ] ; then | |
| echo "exists_tag=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "exists_tag=false" >> $GITHUB_OUTPUT | |
| fi | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| # Bootstrap project | |
| - name: Cache pnpm modules | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.pnpm-store | |
| key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }} | |
| restore-keys: | | |
| ${{ runner.os }}- | |
| - name: install | |
| uses: pnpm/action-setup@v4 | |
| with: | |
| run_install: | | |
| - recursive: true | |
| args: [--frozen-lockfile] | |
| - name: build | |
| run: | | |
| pnpm build | |
| # Git stash | |
| - name: Drop current changes | |
| if: startsWith( env.COMMIT_MESSAGE , 'chore(release):' ) && steps.tag_check.outputs.exists_tag == 'false' | |
| run: | | |
| git add . | |
| git stash | |
| # Create git tag | |
| - name: Create Git Tag | |
| if: startsWith( env.COMMIT_MESSAGE , 'chore(release):' ) && steps.tag_check.outputs.exists_tag == 'false' | |
| uses: azu/action-package-version-to-git-tag@v1 | |
| with: | |
| version: ${{ env.CURRENT_VERSION }} | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| github_repo: ${{ github.repository }} | |
| git_commit_sha: ${{ github.sha }} | |
| git_tag_prefix: 'v' | |
| # Publish | |
| - name: Publish | |
| run: | | |
| if [ '${{ github.event_name }}' == 'pull_request' ] ; then | |
| pnpm publish --filter=taro-ui --registry=https://registry.npmjs.org/ --publish-branch=next | |
| elif [ '${{ github.event_name }}' == 'push' ] || [ '${{ github.event_name }}' == 'workflow_dispatch' ] ; then | |
| pnpm publish --filter=taro-ui --registry=https://registry.npmjs.org/ --publish-branch=${{ github.ref_name }} ${{ env.PUBLISH_PARAMS }} | |
| fi | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| # Create relase when event is PR | |
| - name: Create Release | |
| id: create_release | |
| if: startsWith( env.COMMIT_MESSAGE , 'chore(release):' ) && steps.tag_check.outputs.exists_tag == 'false' && github.event.pull_request.merged == true | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: v${{ env.CURRENT_VERSION }} | |
| name: ${{ github.event.pull_request.title }} | |
| body: | | |
| ${{ github.event.pull_request.body }} | |
| draft: false | |
| prerelease: false | |
| # Create PR page comment when event is PR | |
| - uses: actions/github-script@v6 | |
| if: github.event.pull_request.merged == true | |
| with: | |
| github-token: ${{secrets.GITHUB_TOKEN}} | |
| script: | | |
| github.rest.issues.createComment({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: 'https://github.com/${{ github.repository }}/releases/tag/v${{ env.CURRENT_VERSION }} is released 🎉' | |
| }) |