@@ -164,3 +164,75 @@ jobs:
164164 - name : Build example for iOS
165165 run : |
166166 yarn turbo run build:ios --cache-dir="${{ env.TURBO_CACHE_DIR }}"
167+
168+ publish-canary :
169+ name : Publish canary to npm (PRs to main)
170+ if : github.event_name == 'pull_request' && github.base_ref == 'main' && github.event.pull_request.head.repo.full_name == github.repository
171+ needs : [lint, test, build-library]
172+ runs-on : ubuntu-latest
173+ steps :
174+ - name : Checkout
175+ uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
176+
177+ - name : Setup
178+ uses : ./.github/actions/setup
179+
180+ - name : Build package
181+ run : yarn prepare
182+
183+ - name : Configure npm auth
184+ run : |
185+ echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
186+ env :
187+ NPM_TOKEN : ${{ secrets.NPM_TOKEN }}
188+
189+ - name : Publish canary
190+ env :
191+ GITHUB_SHA : ${{ github.sha }}
192+ run : |
193+ BASE_VERSION=$(node -p "require('./package.json').version")
194+ SHORT_SHA=${GITHUB_SHA::7}
195+ # Use run_number to avoid collisions on repeated pushes
196+ CANARY_VERSION="$BASE_VERSION-canary.${{ github.run_number }}.$SHORT_SHA"
197+ echo "Canary version: $CANARY_VERSION"
198+ npm version "$CANARY_VERSION" --no-git-tag-version
199+ npm publish --access public --tag canary
200+
201+ publish :
202+ name : Publish to npm (push to main)
203+ if : github.event_name == 'push' && github.ref == 'refs/heads/main'
204+ needs : [lint, test, build-library]
205+ runs-on : ubuntu-latest
206+ steps :
207+ - name : Checkout
208+ uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
209+
210+ - name : Setup
211+ uses : ./.github/actions/setup
212+
213+ - name : Configure npm auth
214+ run : |
215+ echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
216+ env :
217+ NPM_TOKEN : ${{ secrets.NPM_TOKEN }}
218+
219+ - name : Skip if version already published
220+ id : version-check
221+ run : |
222+ PKG=$(node -p "require('./package.json').name")
223+ VER=$(node -p "require('./package.json').version")
224+ echo "pkg=$PKG ver=$VER"
225+ PUBLISHED=$(npm view "$PKG@$VER" version || true)
226+ if [ "$PUBLISHED" = "$VER" ]; then
227+ echo "already=true" >> $GITHUB_OUTPUT
228+ else
229+ echo "already=false" >> $GITHUB_OUTPUT
230+ fi
231+
232+ - name : Build package
233+ if : steps.version-check.outputs.already == 'false'
234+ run : yarn prepare
235+
236+ - name : Publish
237+ if : steps.version-check.outputs.already == 'false'
238+ run : npm publish --access public
0 commit comments