From f9a399dd364a612d065c0535db03bd805aa52707 Mon Sep 17 00:00:00 2001 From: Yinglao Liu Date: Wed, 22 Dec 2021 11:48:15 -0800 Subject: [PATCH] npm publish to @latest only when release type is released Summary: The following case won't work -- npm publish is not triggered when a draft is saved and then published This diff fix the case and introduce the following behavior: 1. when a new release is issued and not marked as pre-release, the npm package with the latest tag will be updated. 2. if the new release is marked as pre-release, the npm packages with the next tag will be updated. 3. The above behavior doesn't change whether or not a draft is saved before the released. p.s. updating the "prerelease" to "released" won't trigger the workflow, and its not desired. To make a release based on prerelease, please redo whatever steps are needed. Reviewed By: raedle Differential Revision: D33248441 fbshipit-source-id: f54e5fb0c2834429ed27f7c16655f6628f50944b --- .github/workflows/npm-publish.yml | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index 20ca07e1c..58bcc3a1f 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -2,7 +2,7 @@ name: NPM Publish on: release: - types: [created] + types: [published] jobs: publish-npm-cli: @@ -24,10 +24,16 @@ jobs: run: yarn run build - name: Unit Test run: yarn run test - - name: Publish To NPM + - name: Publish To NPM latest + if: github.event.release.prerelease == false run: npm publish env: NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} + - name: Publish To NPM next + if: github.event.release.prerelease == true + run: npm publish --tag next + env: + NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} publish-npm-core: runs-on: ubuntu-latest @@ -44,10 +50,16 @@ jobs: run: npm version $GITHUB_REF_NAME - name: Install Dependencies run: yarn install --frozen-lockfile - - name: Publish To NPM + - name: Publish To NPM latest + if: github.event.release.prerelease == false run: npm publish env: NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} + - name: Publish To NPM next + if: github.event.release.prerelease == true + run: npm publish --tag next + env: + NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} publish-npm-template: runs-on: ubuntu-latest @@ -75,7 +87,13 @@ jobs: working-directory: ./react-native-template-pytorch-live/template - name: Update package.json version to $GITHUB_REF_NAME run: npm version $GITHUB_REF_NAME - - name: Publish To NPM + - name: Publish To NPM latest + if: github.event.release.prerelease == false run: npm publish env: NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} + - name: Publish To NPM next + if: github.event.release.prerelease == true + run: npm publish --tag next + env: + NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}