Skip to content

Commit

Permalink
Support publishing npm versions with prerelease tags
Browse files Browse the repository at this point in the history
  • Loading branch information
bglw committed Feb 16, 2023
1 parent 060c4c2 commit 0feb809
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
22 changes: 22 additions & 0 deletions .backstage/get_tag.cjs
Original file line number Diff line number Diff line change
@@ -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");
21 changes: 12 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand Down

0 comments on commit 0feb809

Please sign in to comment.