diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index a54aa325..b16c80d4 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -8,12 +8,14 @@ jobs: uses: actions/checkout@v3 with: ref: ${{ github.head_ref }} + - name: 🤝 Set Node version from .nvmrc + run: echo NVMRC=`cat .nvmrc` >> $GITHUB_ENV - name: ⎔ Setup node # sets up the .npmrc file to publish to npm uses: actions/setup-node@v3 with: - node-version: "16" + node-version: ${{ env.NVMRC }} registry-url: "https://registry.npmjs.org" - name: 📥 Download deps diff --git a/publish.sh b/publish.sh index 2d72c02d..045c556c 100755 --- a/publish.sh +++ b/publish.sh @@ -1,5 +1,9 @@ #!/bin/sh +# This script will determine the type of release based on the git branch. When the default branch is used, it will be a `patch` that's published to npm under the `latest` dist-tag. Any other branch will be a `prelease` that's published to npm under the `alpha` dist-tag. +bump='patch' +tag='latest' + set -e; if ! git diff-files --quiet; then @@ -15,10 +19,20 @@ fi; rm -rf node_modules npm install -npm test; +current_branch=$(git rev-parse --abbrev-ref HEAD) +default_branch=$(git remote show origin | sed -n '/HEAD branch/s/.*: //p') -npm version ${1-patch} +if [ "$current_branch" != "$default_branch" ]; then + bump='prerelease' + tag='alpha' + npm --no-git-tag-version version $bump --preid=$tag + git push + npm publish --tag $tag +else + npm test; + npm version ${1-bump} -git push; -git push --tags; -npm publish; + git push; + git push --tags; + npm publish; +fi