diff --git a/publish/action.yml b/publish/action.yml index f35adcf..606061a 100644 --- a/publish/action.yml +++ b/publish/action.yml @@ -6,13 +6,9 @@ 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: "./" @@ -21,9 +17,9 @@ inputs: 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,22 +30,25 @@ runs: working-directory: ${{ inputs.directory }} run: | PREFIX="" - if [ "${{ inputs.npm-version-tag }}" != "" ]; then - PREFIX="${{ inputs.npm-version-tag }}-${{ github.event.number }}-" + if [ "${{ github.event_name }}" == "pull_request" ]; then + 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 - 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 }} - 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)))) working-directory: ${{ inputs.directory }} run: | - npm publish ${{ inputs.npm-version-tag != '' && format('--tag {0}', inputs.npm-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 }}