Publish NPM (Manual) #6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Publish NPM (Manual) | |
on: | |
workflow_dispatch: | |
inputs: | |
release-tag: | |
type: string | |
required: true | |
description: Release Tag to Publish | |
jobs: | |
validate_tag: | |
runs-on: ubuntu-latest | |
outputs: | |
is-prerelease: ${{ steps.validate-release.outputs.is-prerelease }} | |
steps: | |
- uses: actions/github-script@v7 | |
id: validate-release | |
with: | |
script: | | |
/** the "core" module does not have access to workflow_dispatch inputs */ | |
const tag = '${{ inputs.release-tag }}'; | |
/** Releases don't have a guaranteed order, so we'll have to paginate */ | |
let exhausted = false; | |
let page = 1; | |
while (!exhausted) { | |
const releases = await github.rest.repos.listReleases({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
page, | |
per_page: 100, | |
}).then(r => r.data); | |
const matchingRelease = releases.find(r => r.tag_name === tag); | |
if (matchingRelease) { | |
core.setOutput('has-release', 'true'); | |
core.setOutput('is-prerelease', matchingRelease.prerelease.toString()); | |
return; | |
} | |
if (releases.length < 100) { | |
exhausted = true; | |
} else if (page >= 10) { | |
throw new Error("We iterated over 10 pages. Does the script work?"); | |
} else { | |
page++ | |
} | |
} | |
core.setOutput('has-release', 'false'); | |
core.setOutput('is-prerelease', 'false'); | |
- name: Abort | |
if: steps.validate-release.outputs.has-release != 'true' | |
run: | | |
{ | |
echo "Tag ${{ github.event.inputs.release-tag }} not found." | |
exit 1 | |
} | |
publish_npm: | |
needs: validate_tag | |
uses: ./.github/workflows/publish.reusable.yml | |
permissions: | |
contents: write | |
id-token: write | |
with: | |
release-tag: ${{ github.event.inputs.release-tag }} | |
is-prerelease: ${{ needs.validate_tag.outputs.is-prerelease }} | |
secrets: inherit |