NPM publish #257
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: NPM publish | |
| on: | |
| schedule: | |
| - cron: '01 00 * * *' # Every day at 00:01 UTC | |
| workflow_dispatch: | |
| inputs: | |
| release-type: | |
| description: 'Which npm dist-tag to publish under' | |
| required: true | |
| type: choice | |
| options: | |
| - nightly # executorch-nightly, version suffixed with commit + date | |
| - latest # current stable release | |
| - legacy # maintenance release of an older line | |
| default: nightly | |
| dist-tag: | |
| description: 'Publish under this exact dist-tag instead, e.g. v0.8 for a maintenance line (leave empty to use release-type)' | |
| required: false | |
| type: string | |
| default: '' | |
| permissions: | |
| id-token: write | |
| contents: read | |
| concurrency: | |
| group: 'npm-executorch-package-build' | |
| cancel-in-progress: false | |
| jobs: | |
| build: | |
| if: github.repository == 'software-mansion/react-native-executorch' | |
| runs-on: ubuntu-latest | |
| environment: deployment | |
| permissions: | |
| contents: read | |
| id-token: write | |
| env: | |
| EXECUTORCH_DIR: packages/react-native-executorch | |
| EXECUTORCH_VERSION: PLACEHOLDER | |
| PACKAGE_NAME: PLACEHOLDER | |
| TAG: PLACEHOLDER | |
| # `inputs` is empty on the scheduled run, which is always a nightly. | |
| RELEASE_TYPE: ${{ inputs.release-type || 'nightly' }} | |
| DIST_TAG_OVERRIDE: ${{ inputs.dist-tag || '' }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| - name: Setup Node | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: 24 | |
| cache: 'yarn' | |
| registry-url: https://registry.npmjs.org/ | |
| - name: Determine version | |
| working-directory: ${{ env.EXECUTORCH_DIR }} | |
| run: | | |
| VERSION=$(jq -r .version package.json) | |
| echo "EXECUTORCH_VERSION=$VERSION" >> $GITHUB_ENV | |
| - name: Assert EXECUTORCH_VERSION | |
| if: ${{ env.EXECUTORCH_VERSION == 'PLACEHOLDER' }} | |
| run: exit 1 # this should never happen | |
| - name: Install monorepo dependencies | |
| run: yarn install --immutable | |
| - name: Set tag | |
| run: | | |
| if [[ -n "$DIST_TAG_OVERRIDE" ]]; then | |
| # The override only moves the dist-tag; the version still comes from | |
| # release-type. Pairing it with nightly would publish a throwaway | |
| # `x.y.z-nightly-<sha>-<date>` under a tag meant to be stable, which | |
| # is never what you want - fail instead of guessing. | |
| if [[ "$RELEASE_TYPE" == "nightly" ]]; then | |
| echo "dist-tag override needs a stable build: set release-type to latest or legacy." >&2 | |
| exit 1 | |
| fi | |
| # npm rejects a dist-tag that parses as a semver range, so require a | |
| # leading letter. That also rules out bare versions like `0.8`. | |
| if [[ ! "$DIST_TAG_OVERRIDE" =~ ^[a-zA-Z][a-zA-Z0-9._-]*$ ]]; then | |
| echo "Invalid dist-tag: '$DIST_TAG_OVERRIDE' (expected e.g. v0.8)" >&2 | |
| exit 1 | |
| fi | |
| echo "TAG=$DIST_TAG_OVERRIDE" >> $GITHUB_ENV | |
| else | |
| case "$RELEASE_TYPE" in | |
| nightly) echo "TAG=executorch-nightly" >> $GITHUB_ENV ;; | |
| latest) echo "TAG=latest" >> $GITHUB_ENV ;; | |
| legacy) echo "TAG=legacy" >> $GITHUB_ENV ;; | |
| *) echo "Unknown release type: $RELEASE_TYPE" >&2; exit 1 ;; | |
| esac | |
| fi | |
| - name: Assert tag | |
| if: ${{ env.TAG == 'PLACEHOLDER' }} | |
| run: exit 1 # this should never happen | |
| - name: Build package | |
| id: build | |
| working-directory: ${{ env.EXECUTORCH_DIR }} | |
| run: | | |
| if [[ "$RELEASE_TYPE" == "nightly" ]]; then | |
| ./scripts/create-package.sh generate_nightly_version | |
| else | |
| ./scripts/create-package.sh | |
| fi | |
| - name: Check if any node_modules were packed | |
| id: check_node_modules | |
| working-directory: ${{ env.EXECUTORCH_DIR }} | |
| run: >- | |
| ! grep --silent -E "node_modules/.+" build.log | |
| - name: Show build log | |
| working-directory: ${{ env.EXECUTORCH_DIR }} | |
| if: failure() && steps.build.outcome == 'failure' | |
| run: cat build.log | |
| - name: Show packed node_modules | |
| working-directory: ${{ env.EXECUTORCH_DIR }} | |
| if: failure() && steps.node_modules.outcome == 'failure' | |
| run: >- | |
| ! grep -E "node_modules/.+" build.log | |
| - name: Add package name to env | |
| working-directory: ${{ env.EXECUTORCH_DIR }} | |
| run: echo "PACKAGE_NAME=$(ls -l | egrep -o "react-native-executorch-(.*)(=?\.tgz)")" >> $GITHUB_ENV | |
| - name: Assert package name | |
| if: ${{ env.PACKAGE_NAME == 'PLACEHOLDER' }} | |
| run: exit 1 # this should never happen | |
| - name: Upload package to GitHub | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ env.PACKAGE_NAME }} | |
| path: ${{ env.EXECUTORCH_DIR }}/${{ env.PACKAGE_NAME }} | |
| - name: Move package to monorepo root | |
| run: mv ${{ env.EXECUTORCH_DIR }}/${{ env.PACKAGE_NAME }} . | |
| - name: Publish package to npm | |
| run: npm publish $PACKAGE_NAME --tag ${{ env.TAG }} --provenance |