From 0feb8099e610f67cea0653e7d29a48438b838806 Mon Sep 17 00:00:00 2001 From: Liam Bigelow <40188355+bglw@users.noreply.github.com> Date: Thu, 16 Feb 2023 14:17:36 +1300 Subject: [PATCH] Support publishing npm versions with prerelease tags --- .backstage/get_tag.cjs | 22 ++++++++++++++++++++++ .github/workflows/release.yml | 21 ++++++++++++--------- 2 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 .backstage/get_tag.cjs diff --git a/.backstage/get_tag.cjs b/.backstage/get_tag.cjs new file mode 100644 index 00000000..35981c0f --- /dev/null +++ b/.backstage/get_tag.cjs @@ -0,0 +1,22 @@ +const version = process.env.GIT_VERSION; + +if (!version) { + console.error("Script expected a GIT_VERSION environment variable"); + process.exit(1); +} + +// Only allow latest tag if we are releasing a major/minor/patch +if (/^\d+\.\d+\.\d+$/.test(version)) { + console.log("latest"); + process.exit(0); +} + +// Use the suffix as the tag. i.e. `0.11.0-rc5` -> `rc` +const suffix = version.match(/^\d+\.\d+\.\d+-([a-z]+)/i)?.[1]; +if (suffix) { + console.log(suffix.toLowerCase()); + process.exit(0); +} + +// Fall back to an unknown tag for safety +console.log("unknown"); \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index da95e825..3809550f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -95,42 +95,45 @@ jobs: name: release-checksums path: wrappers/node/checksums + - name: Get Version + run: echo GIT_VERSION="$(git describe --tags | sed 's/^v\(.*\)$/\1/')" >> $GITHUB_ENV + + - name: Get Tag + run: echo GIT_TAG="$(node ./.backstage/get_tag.cjs)" >> $GITHUB_ENV + - name: Prepare wrapper package working-directory: ./wrappers/node run: | - RELEASE_VERSION=${GITHUB_REF#refs/tags/} - npm version $(echo $RELEASE_VERSION | cut -c1-) + npm version $GIT_VERSION - name: Publish wrapper package working-directory: ./wrappers/node - run: npm publish + run: npm publish --tag $GIT_TAG env: NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - name: Prepare default ui package working-directory: ./pagefind_ui/default run: | - RELEASE_VERSION=${GITHUB_REF#refs/tags/} - npm version $(echo $RELEASE_VERSION | cut -c1-) + npm version $GIT_VERSION - name: Publish default ui package working-directory: ./pagefind_ui/default run: | npm i npm run build - npm publish + npm publish --tag $GIT_TAG env: NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - name: Prepare modular ui package working-directory: ./pagefind_ui/modular run: | - RELEASE_VERSION=${GITHUB_REF#refs/tags/} - npm version $(echo $RELEASE_VERSION | cut -c1-) + npm version $GIT_VERSION - name: Publish modular ui package working-directory: ./pagefind_ui/modular run: | npm i npm run build - npm publish + npm publish --tag $GIT_TAG env: NPM_TOKEN: ${{ secrets.NPM_TOKEN }}