Skip to content

Commit 2558259

Browse files
authored
ci: make npm publish dist-tag an explicit choice (#1348)
## Description Previously publish without `latest` checked published as nightly. But sometimes we want to publish new legacy version. This PR adds this possibility. ### Introduces a breaking change? - [ ] Yes - [x] No ### Type of change - [x] Bug fix (change which fixes an issue) - [ ] New feature (change which adds functionality) - [ ] Documentation update (improves or adds clarity to existing documentation) - [ ] Other (chores, tests, code style improvements etc.) ### Tested on - [ ] iOS - [ ] Android ### Testing instructions Actions → NPM publish → Run workflow. The form now shows a `release-type` dropdown with `nightly` / `latest` / `legacy` instead of a checkbox. ### Screenshots ### Related issues ### Checklist - [x] I have performed a self-review of my code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have updated the documentation accordingly - [x] My changes generate no new warnings ### Additional notes Same change is backported to `release/0.8` in a companion PR so `0.8.5` can be published under `legacy`.
1 parent cb21d6d commit 2558259

1 file changed

Lines changed: 39 additions & 7 deletions

File tree

.github/workflows/npm-publish.yml

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,20 @@ on:
55
- cron: '01 00 * * *' # Every day at 00:01 UTC
66
workflow_dispatch:
77
inputs:
8-
latest-build:
9-
description: 'Whether to publish as a latest build'
8+
release-type:
9+
description: 'Which npm dist-tag to publish under'
1010
required: true
11-
type: boolean
11+
type: choice
12+
options:
13+
- nightly # executorch-nightly, version suffixed with commit + date
14+
- latest # current stable release
15+
- legacy # maintenance release of an older line
16+
default: nightly
17+
dist-tag:
18+
description: 'Publish under this exact dist-tag instead, e.g. v0.8 for a maintenance line (leave empty to use release-type)'
19+
required: false
20+
type: string
21+
default: ''
1222

1323
permissions:
1424
id-token: write
@@ -31,6 +41,9 @@ jobs:
3141
EXECUTORCH_VERSION: PLACEHOLDER
3242
PACKAGE_NAME: PLACEHOLDER
3343
TAG: PLACEHOLDER
44+
# `inputs` is empty on the scheduled run, which is always a nightly.
45+
RELEASE_TYPE: ${{ inputs.release-type || 'nightly' }}
46+
DIST_TAG_OVERRIDE: ${{ inputs.dist-tag || '' }}
3447
steps:
3548
- name: Checkout
3649
uses: actions/checkout@v6
@@ -57,10 +70,29 @@ jobs:
5770

5871
- name: Set tag
5972
run: |
60-
if [[ "${{ inputs.latest-build }}" != "true" ]]; then
61-
echo "TAG=executorch-nightly" >> $GITHUB_ENV
73+
if [[ -n "$DIST_TAG_OVERRIDE" ]]; then
74+
# The override only moves the dist-tag; the version still comes from
75+
# release-type. Pairing it with nightly would publish a throwaway
76+
# `x.y.z-nightly-<sha>-<date>` under a tag meant to be stable, which
77+
# is never what you want - fail instead of guessing.
78+
if [[ "$RELEASE_TYPE" == "nightly" ]]; then
79+
echo "dist-tag override needs a stable build: set release-type to latest or legacy." >&2
80+
exit 1
81+
fi
82+
# npm rejects a dist-tag that parses as a semver range, so require a
83+
# leading letter. That also rules out bare versions like `0.8`.
84+
if [[ ! "$DIST_TAG_OVERRIDE" =~ ^[a-zA-Z][a-zA-Z0-9._-]*$ ]]; then
85+
echo "Invalid dist-tag: '$DIST_TAG_OVERRIDE' (expected e.g. v0.8)" >&2
86+
exit 1
87+
fi
88+
echo "TAG=$DIST_TAG_OVERRIDE" >> $GITHUB_ENV
6289
else
63-
echo "TAG=latest" >> $GITHUB_ENV
90+
case "$RELEASE_TYPE" in
91+
nightly) echo "TAG=executorch-nightly" >> $GITHUB_ENV ;;
92+
latest) echo "TAG=latest" >> $GITHUB_ENV ;;
93+
legacy) echo "TAG=legacy" >> $GITHUB_ENV ;;
94+
*) echo "Unknown release type: $RELEASE_TYPE" >&2; exit 1 ;;
95+
esac
6496
fi
6597
6698
- name: Assert tag
@@ -71,7 +103,7 @@ jobs:
71103
id: build
72104
working-directory: ${{ env.EXECUTORCH_DIR }}
73105
run: |
74-
if [[ "${{ inputs.latest-build }}" != "true" ]]; then
106+
if [[ "$RELEASE_TYPE" == "nightly" ]]; then
75107
./scripts/create-package.sh generate_nightly_version
76108
else
77109
./scripts/create-package.sh

0 commit comments

Comments
 (0)