From ee39377871142cf1632159e20c4bf4967660d8c8 Mon Sep 17 00:00:00 2001 From: Rinat Arsaev <11846445+A77AY@users.noreply.github.com> Date: Thu, 27 Mar 2025 17:13:01 +0700 Subject: [PATCH 1/4] add inputs.pr --- publish/action.yml | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/publish/action.yml b/publish/action.yml index f35adcf..ae439b4 100644 --- a/publish/action.yml +++ b/publish/action.yml @@ -6,24 +6,24 @@ inputs: description: The NPM access token to use when publishing required: true npm-skip-version-up: - description: Version not up + description: Skip version up default: "false" required: false - npm-version-tag: - description: Version tag - default: "" - required: false directory: description: Directory default: "./" required: false + pr: + description: If this is a PR + default: "false" + required: false pr-label: description: PR label for publish (publish {label}) default: "" required: false - pr-only-labeled: - description: Only publish if the PR is labeled - default: "false" + pr-version-tag: + description: Version tag for PR + default: "pr" required: false runs: @@ -34,10 +34,12 @@ runs: working-directory: ${{ inputs.directory }} run: | PREFIX="" - if [ "${{ inputs.npm-version-tag }}" != "" ]; then - PREFIX="${{ inputs.npm-version-tag }}-${{ github.event.number }}-" + if [ "${{ inputs.pr }}" == "true" ]; then + PREFIX="${{ inputs.pr-version-tag }}-${{ github.event.number }}-$(echo "${{ github.event.pull_request.head.sha }}" | cut -c1-7)" + else + PREFIX="${GITHUB_SHA::7}" fi - npm version prerelease --preid "${PREFIX}${GITHUB_SHA::7}" --no-git-tag-version + npm version prerelease --preid "${PREFIX}" --no-git-tag-version shell: bash env: NODE_AUTH_TOKEN: ${{ inputs.npm-token }} @@ -49,7 +51,7 @@ runs: && contains(github.event.pull_request.labels.*.name, format('publish {0}', inputs.pr-label)))) working-directory: ${{ inputs.directory }} run: | - npm publish ${{ inputs.npm-version-tag != '' && format('--tag {0}', inputs.npm-version-tag) || '' }} + npm publish ${{ inputs.pr == 'true' && format('--tag {0}', inputs.pr-version-tag) || '' }} shell: bash env: NODE_AUTH_TOKEN: ${{ inputs.npm-token }} From 3eef7f1cb7e82b8ae70d1ee8ef792dc3618b76fe Mon Sep 17 00:00:00 2001 From: Rinat Arsaev <11846445+A77AY@users.noreply.github.com> Date: Thu, 27 Mar 2025 17:16:33 +0700 Subject: [PATCH 2/4] fix --- publish/action.yml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/publish/action.yml b/publish/action.yml index ae439b4..cf69096 100644 --- a/publish/action.yml +++ b/publish/action.yml @@ -13,10 +13,6 @@ inputs: description: Directory default: "./" required: false - pr: - description: If this is a PR - default: "false" - required: false pr-label: description: PR label for publish (publish {label}) default: "" @@ -34,7 +30,7 @@ runs: working-directory: ${{ inputs.directory }} run: | PREFIX="" - if [ "${{ inputs.pr }}" == "true" ]; then + if [ "${{ github.event_name }}" == "pull_request" ]; then PREFIX="${{ inputs.pr-version-tag }}-${{ github.event.number }}-$(echo "${{ github.event.pull_request.head.sha }}" | cut -c1-7)" else PREFIX="${GITHUB_SHA::7}" @@ -51,7 +47,7 @@ runs: && contains(github.event.pull_request.labels.*.name, format('publish {0}', inputs.pr-label)))) working-directory: ${{ inputs.directory }} run: | - npm publish ${{ inputs.pr == 'true' && format('--tag {0}', inputs.pr-version-tag) || '' }} + npm publish ${{ github.event_name == 'pull_request' && format('--tag {0}', inputs.pr-version-tag) || '' }} shell: bash env: NODE_AUTH_TOKEN: ${{ inputs.npm-token }} From 131128dc51c5a67b0fb0a8db8d88a5eceed8f107 Mon Sep 17 00:00:00 2001 From: Rinat Arsaev <11846445+A77AY@users.noreply.github.com> Date: Thu, 27 Mar 2025 17:20:48 +0700 Subject: [PATCH 3/4] fix --- publish/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/publish/action.yml b/publish/action.yml index cf69096..b21da6c 100644 --- a/publish/action.yml +++ b/publish/action.yml @@ -41,7 +41,7 @@ runs: NODE_AUTH_TOKEN: ${{ inputs.npm-token }} - name: Publish if: > - inputs.pr-only-labeled == 'false' + github.event_name != 'pull_request' || (contains(github.event.pull_request.labels.*.name, 'publish') || (inputs.pr-label != '' && contains(github.event.pull_request.labels.*.name, format('publish {0}', inputs.pr-label)))) From 6f5f597c7908154e4846061840bfefcd9b9dcd0e Mon Sep 17 00:00:00 2001 From: Rinat Arsaev <11846445+A77AY@users.noreply.github.com> Date: Thu, 27 Mar 2025 17:24:35 +0700 Subject: [PATCH 4/4] 120 --- publish/action.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/publish/action.yml b/publish/action.yml index b21da6c..606061a 100644 --- a/publish/action.yml +++ b/publish/action.yml @@ -31,7 +31,8 @@ runs: run: | PREFIX="" if [ "${{ github.event_name }}" == "pull_request" ]; then - PREFIX="${{ inputs.pr-version-tag }}-${{ github.event.number }}-$(echo "${{ github.event.pull_request.head.sha }}" | cut -c1-7)" + PR_SHA_SHORT=$(echo "${{ github.event.pull_request.head.sha }}" | cut -c1-7) + PREFIX="${{ inputs.pr-version-tag }}-${{ github.event.number }}-$PR_SHA_SHORT" else PREFIX="${GITHUB_SHA::7}" fi