fix: fix bug of release #184
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 CI | |
| on: | |
| push: | |
| branches: | |
| - 'release/[0-9]+\.[0-9]+\.[0-9]+' | |
| - 'hotfix/[0-9]+\.[0-9]+\.[0-9]+' | |
| - 'pre-release/[0-9]+\.[0-9]+\.[0-9]+-alpha\.[0-9]+' | |
| - 'pre-release/[0-9]+\.[0-9]+\.[0-9]+-beta\.[0-9]+' | |
| - 'pre-release/[0-9]+\.[0-9]+\.[0-9]+-rc\.[0-9]+' | |
| - 'pre-release/[0-9]+\.[0-9]+\.[0-9]+-hotfix\.[0-9]+' | |
| jobs: | |
| release: | |
| runs-on: macos-latest | |
| permissions: | |
| id-token: write | |
| contents: write | |
| pull-requests: write | |
| strategy: | |
| matrix: | |
| node-version: [20.x] | |
| concurrency: | |
| group: vgrammar-release-${{ github.ref_name }} | |
| cancel-in-progress: false | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Configure Git identity | |
| run: | | |
| git config user.name ${{ github.actor }} | |
| git config user.email ${{ github.actor }}@users.noreply.github.com | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ matrix.node-version }} | |
| registry-url: 'https://registry.npmjs.org' | |
| cache: 'npm' | |
| cache-dependency-path: './common/config/rush/pnpm-lock.yaml' | |
| - name: Install latest pnpm | |
| run: npm install -g pnpm@10.7.0 | |
| - name: Install Python distutils (macOS) | |
| if: runner.os == 'macOS' | |
| run: | | |
| python3 -m pip install setuptools --break-system-packages | |
| - name: Install Python distutils (Linux) | |
| if: runner.os == 'Linux' | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y python3-distutils | |
| python3 -m pip install setuptools --break-system-packages | |
| - name: Install native deps for node-canvas (macOS) | |
| if: runner.os == 'macOS' | |
| run: | | |
| brew update | |
| brew install pkg-config cairo pango libpng jpeg giflib librsvg | |
| - name: Install native deps for node-canvas (Linux) | |
| if: runner.os == 'Linux' | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev pkg-config | |
| - name: Install rush | |
| run: node common/scripts/install-run-rush.js install --bypass-policy | |
| - name: Parse semver (release) | |
| if: startsWith(github.ref_name, 'release/') | |
| id: semver_release | |
| uses: xile611/read-package-version-action@main | |
| with: | |
| path: packages/vgrammar | |
| semver_string: ${{ github.ref_name }} | |
| semver_pattern: '^release/(.*)$' | |
| - name: update nextBump (release) | |
| if: startsWith(github.ref_name, 'release/') | |
| uses: xile611/set-next-bump-of-rush@main | |
| with: | |
| release_version: ${{ steps.semver_release.outputs.full }} | |
| write_next_bump: true | |
| - name: Generate rush version (release) | |
| if: startsWith(github.ref_name, 'release/') | |
| run: node common/scripts/install-run-rush.js version --bump | |
| - name: Update version (release) | |
| if: startsWith(github.ref_name, 'release/') | |
| run: node common/scripts/apply-release-version.js 'none' ${{ steps.semver_release.outputs.main }} | |
| - name: Parse semver (hotfix) | |
| if: startsWith(github.ref_name, 'hotfix/') | |
| id: semver_hotfix | |
| uses: xile611/read-package-version-action@main | |
| with: | |
| path: packages/vgrammar | |
| semver_string: ${{ github.ref_name }} | |
| semver_pattern: '^hotfix/(.*)$' | |
| - name: update nextBump (hotfix) | |
| if: startsWith(github.ref_name, 'hotfix/') | |
| uses: xile611/set-next-bump-of-rush@main | |
| with: | |
| release_version: ${{ steps.semver_hotfix.outputs.full }} | |
| write_next_bump: true | |
| - name: Generate rush version (hotfix) | |
| if: startsWith(github.ref_name, 'hotfix/') | |
| run: node common/scripts/install-run-rush.js version --bump | |
| - name: Update version (hotfix) | |
| if: startsWith(github.ref_name, 'hotfix/') | |
| run: node common/scripts/apply-release-version.js 'none' ${{ steps.semver_hotfix.outputs.main }} | |
| - name: Parse semver (pre-release) | |
| if: startsWith(github.ref_name, 'pre-release/') | |
| id: semver_prerelease | |
| uses: xile611/read-package-version-action@main | |
| with: | |
| path: packages/vgrammar | |
| semver_string: ${{ github.ref_name }} | |
| semver_pattern: '^pre-release/(.*)$' | |
| - name: Apply prereleaseName (pre-release) | |
| if: startsWith(github.ref_name, 'pre-release/') | |
| run: node common/scripts/apply-release-version.js ${{ steps.semver_prerelease.outputs.pre_release_name }} ${{ steps.semver_prerelease.outputs.main }} | |
| - name: Build packages | |
| env: | |
| NODE_OPTIONS: '--max_old_space_size=4096' | |
| run: node common/scripts/install-run-rush.js build --only tag:package | |
| - name: Setup Node.js for npm publish | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22.x | |
| registry-url: 'https://registry.npmjs.org' | |
| cache: 'npm' | |
| cache-dependency-path: './common/config/rush/pnpm-lock.yaml' | |
| # Workaround for Node 22.22.2 regression: | |
| # `npm install -g npm@latest` breaks npm's own dependency tree. | |
| # See: https://github.com/nodejs/node/issues/62425 | |
| # Fix: use corepack or npx to bootstrap, then install npm@latest. | |
| - name: Update npm (workaround for Node 22.22.2 bug) | |
| run: | | |
| echo "Current npm version: $(npm --version)" | |
| npx npm@latest install -g npm@latest | |
| echo "Updated npm version: $(npm --version)" | |
| - name: Verify OIDC requirements | |
| run: | | |
| echo "Node version: $(node --version)" | |
| echo "npm version: $(npm --version)" | |
| NODE_MAJOR=$(node -e "console.log(process.version.split('.')[0].slice(1))") | |
| NPM_MAJOR=$(npm --version | cut -d. -f1) | |
| NPM_MINOR=$(npm --version | cut -d. -f2) | |
| if [ "$NODE_MAJOR" -lt 22 ]; then | |
| echo "❌ Node >= 22.14.0 required for OIDC trusted publishing" | |
| exit 1 | |
| fi | |
| if [ "$NPM_MAJOR" -lt 11 ] || { [ "$NPM_MAJOR" -eq 11 ] && [ "$NPM_MINOR" -lt 5 ]; }; then | |
| echo "❌ npm >= 11.5.1 required for OIDC trusted publishing" | |
| exit 1 | |
| fi | |
| echo "✅ Node and npm versions meet OIDC requirements" | |
| - name: Publish to npm (release) | |
| if: startsWith(github.ref_name, 'release/') | |
| env: | |
| RUSH_ALLOW_UNSUPPORTED_NODEJS: 1 | |
| run: node common/scripts/install-run-rush.js publish --publish --include-all --tag latest | |
| - name: Publish to npm (hotfix) | |
| if: startsWith(github.ref_name, 'hotfix/') | |
| env: | |
| RUSH_ALLOW_UNSUPPORTED_NODEJS: 1 | |
| run: node common/scripts/install-run-rush.js publish --publish --include-all --tag hotfix | |
| - name: Publish to npm (pre-release) | |
| if: startsWith(github.ref_name, 'pre-release/') | |
| env: | |
| RUSH_ALLOW_UNSUPPORTED_NODEJS: 1 | |
| run: node common/scripts/install-run-rush.js publish --publish --include-all --tag ${{ steps.semver_prerelease.outputs.pre_release_type }} | |
| - name: Update shrinkwrap | |
| env: | |
| RUSH_ALLOW_UNSUPPORTED_NODEJS: 1 | |
| run: node common/scripts/install-run-rush.js update | |
| - name: Get npm version (release) | |
| if: startsWith(github.ref_name, 'release/') | |
| id: package_version_release | |
| uses: xile611/read-package-version-action@main | |
| with: | |
| path: packages/vgrammar | |
| - name: Commit & Push changes (release) | |
| if: startsWith(github.ref_name, 'release/') | |
| run: | | |
| set -euo pipefail | |
| if git diff --quiet; then | |
| echo 'No changes to commit for release branch.' | |
| else | |
| git add . | |
| git commit -m "build: release version ${{ steps.package_version_release.outputs.current_version }} [skip ci]" -n | |
| git push --no-verify origin ${{ github.ref_name }} | |
| fi | |
| - name: Create Pull Request to main (release) | |
| if: startsWith(github.ref_name, 'release/') | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| set -euo pipefail | |
| BRANCH="${GITHUB_REF_NAME}" | |
| echo "Source branch: $BRANCH" | |
| if gh pr list --base main --head "$BRANCH" --state open --json number --limit 1 | grep -q '"number"'; then | |
| echo "PR from $BRANCH to main already exists, skip creating." | |
| exit 0 | |
| fi | |
| TITLE="[Auto release] release ${{ steps.package_version_release.outputs.current_version }}" | |
| BODY="This PR merges release branch $BRANCH into main." | |
| gh pr create --base main --head "$BRANCH" --title "$TITLE" --body "$BODY" | |
| - name: Get npm version (hotfix) | |
| if: startsWith(github.ref_name, 'hotfix/') | |
| id: package_version_hotfix | |
| uses: xile611/read-package-version-action@main | |
| with: | |
| path: packages/vgrammar | |
| - name: Commit & Push changes (hotfix) | |
| if: startsWith(github.ref_name, 'hotfix/') | |
| run: | | |
| set -euo pipefail | |
| if git diff --quiet; then | |
| echo 'No changes to commit for hotfix branch.' | |
| else | |
| git add . | |
| git commit -m "build: hotfix version ${{ steps.package_version_hotfix.outputs.current_version }} [skip ci]" -n | |
| git push --no-verify origin ${{ github.ref_name }} | |
| fi | |
| - name: Get npm version (pre-release) | |
| if: startsWith(github.ref_name, 'pre-release/') | |
| id: package_version_prerelease | |
| uses: xile611/read-package-version-action@main | |
| with: | |
| path: packages/vgrammar | |
| - name: Commit & Push changes (pre-release) | |
| if: startsWith(github.ref_name, 'pre-release/') | |
| run: | | |
| set -euo pipefail | |
| if git diff --quiet; then | |
| echo 'No changes to commit for pre-release branch.' | |
| else | |
| git add . | |
| git commit -m "build: prerelease version ${{ steps.package_version_prerelease.outputs.current_version }} [skip ci]" -n | |
| git push --no-verify origin ${{ github.ref_name }} | |
| fi |