2.0.0-alpha.0: fix global install, modernize toolchain, and ship ESM generator #5
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: CI | |
| on: | |
| pull_request: | |
| types: [opened, synchronize, reopened, edited, closed] | |
| branches: | |
| - master | |
| concurrency: | |
| group: ci-${{ github.event.pull_request.number }} | |
| cancel-in-progress: true | |
| permissions: | |
| contents: read | |
| jobs: | |
| build-and-test: | |
| name: Build and test | |
| if: github.event.action != 'closed' || github.event.pull_request.merged == true | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version-file: package.json | |
| cache: npm | |
| - run: npm ci | |
| - run: npm run build | |
| name: Build | |
| - run: npm run build:test | |
| name: Build tests | |
| - run: npm run typecheck | |
| name: Typecheck | |
| - run: npm run lint | |
| name: Lint | |
| - run: npm run format | |
| name: Check formatting | |
| - run: npm test | |
| name: Test | |
| check-version: | |
| name: Check version bump | |
| needs: build-and-test | |
| if: github.event.pull_request.merged == false && github.event.action != 'closed' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Compare versions | |
| env: | |
| BASE_REF: ${{ github.base_ref }} | |
| run: | | |
| set -euo pipefail | |
| git fetch origin "${BASE_REF}" | |
| TARGET_VERSION=$(git show "origin/${BASE_REF}:package.json" | jq -r '.version') | |
| TARGET_LOCK_VERSION=$(git show "origin/${BASE_REF}:package-lock.json" | jq -r '.version') | |
| SOURCE_VERSION=$(jq -r '.version' package.json) | |
| SOURCE_LOCK_VERSION=$(jq -r '.version' package-lock.json) | |
| echo "Base (${BASE_REF}): package.json=${TARGET_VERSION}, package-lock.json=${TARGET_LOCK_VERSION}" | |
| echo "PR head: package.json=${SOURCE_VERSION}, package-lock.json=${SOURCE_LOCK_VERSION}" | |
| VERSION_FAILURE=0 | |
| version_is_greater() { | |
| test "$(printf '%s\n%s' "$1" "$2" | sort -V | head -n 1)" != "$1" | |
| } | |
| if version_is_greater "${SOURCE_VERSION}" "${TARGET_VERSION}"; then | |
| echo "package.json version bumped: ${TARGET_VERSION} -> ${SOURCE_VERSION}" | |
| else | |
| echo "::warning file=package.json,line=1,title=Bump Version::Bump package.json version before publishing" | |
| VERSION_FAILURE=1 | |
| fi | |
| if version_is_greater "${SOURCE_LOCK_VERSION}" "${TARGET_LOCK_VERSION}"; then | |
| echo "package-lock.json version bumped: ${TARGET_LOCK_VERSION} -> ${SOURCE_LOCK_VERSION}" | |
| else | |
| echo "::warning file=package-lock.json,line=1,title=Bump Version::Bump package-lock.json version before publishing" | |
| VERSION_FAILURE=1 | |
| fi | |
| echo "VERSION_FAILURE=${VERSION_FAILURE}" >> "${GITHUB_ENV}" | |
| - name: Comment on pull request | |
| if: env.VERSION_FAILURE == '1' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| github.rest.issues.createComment({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: ":rotating_light: Don't forget to bump the versions in package.json and package-lock.json! :rotating_light:" | |
| }) | |
| - name: Fail if version was not bumped | |
| if: env.VERSION_FAILURE == '1' | |
| run: exit 1 | |
| publish-package: | |
| name: Publish to npm | |
| needs: build-and-test | |
| if: github.event.pull_request.merged == true && github.event.action == 'closed' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| id-token: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version-file: package.json | |
| cache: npm | |
| registry-url: https://registry.npmjs.org | |
| - run: npm ci | |
| - run: npm run build | |
| - name: Publish | |
| # Do not run lifecycle scripts — protects against malicious package scripts at publish time. | |
| run: npm publish --ignore-scripts --provenance --access public | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |