name: PR release to npm (Reusable) on: workflow_call: inputs: custom_version: description: 'Optional: exact semver prerelease version to publish, overriding the auto-computed snapshot version.' required: false type: string default: '' dist_tag: description: 'Optional: npm dist-tag override. Required when custom_version is set. Cannot be "latest".' required: false type: string default: '' permissions: id-token: write contents: write jobs: release: runs-on: ubuntu-latest name: Release to npm steps: - name: Validate custom-version inputs if: inputs.custom_version != '' env: CUSTOM_VERSION: ${{ inputs.custom_version }} DIST_TAG: ${{ inputs.dist_tag }} run: | if [ -z "$DIST_TAG" ]; then echo "::error::dist_tag is required when custom_version is set" exit 1 fi if [ "$DIST_TAG" = "latest" ]; then echo "::error::dist_tag cannot be 'latest'" exit 1 fi - uses: actions/checkout@v6 with: fetch-depth: 0 - uses: pnpm/action-setup@v6 - uses: actions/setup-node@v6 with: node-version: '24' cache: 'pnpm' registry-url: "https://registry.npmjs.org" - name: Install packages run: pnpm install --frozen-lockfile - name: Set up project run: pnpm run bootstrap - name: Release to NPM env: CUSTOM_VERSION: ${{ inputs.custom_version }} DIST_TAG: ${{ inputs.dist_tag }} run: | if [ -n "$CUSTOM_VERSION" ]; then pnpm run release --prRelease --customVersion="$CUSTOM_VERSION" --distTag="$DIST_TAG" else pnpm run release --prRelease fi - name: Get commit message run: | # puts the first line of the last commit message to the commmit_message env var echo "commmit_message=$(git log --format=%B -n 1 ${{ github.event.after }} | head -n 1)" >> $GITHUB_ENV - name: Set up git identity if: "startsWith(env.commmit_message, 'chore(release)')" run: git config --global user.name "instructure-ui-ci" && git config --global user.email "instructure-ui-ci@instructure.com" # -a -m is needed to make the tag "annotated". Lerna needs annotated tags to work correctly with versions - name: Add tag if: "startsWith(env.commmit_message, 'chore(release)')" run: git tag -a v$(./.github/workflows/calculateVersion.sh) -m v$(./.github/workflows/calculateVersion.sh) - name: Push tags if: "startsWith(env.commmit_message, 'chore(release)')" run: git push origin v$(./.github/workflows/calculateVersion.sh)