diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..f40b59d --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,21 @@ +name: publish to npm +on: + push: + tags: + - v* + +jobs: + publish-npm: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + with: + node-version: 12 + registry-url: https://registry.npmjs.org/ + - name: Check release validity + run: sh scripts/check-release.sh + - name: Publish + run: npm publish . + env: + NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} diff --git a/scripts/check-release.sh b/scripts/check-release.sh new file mode 100644 index 0000000..646e981 --- /dev/null +++ b/scripts/check-release.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +# Checking if current tag matches the package version +current_tag=$(echo $GITHUB_REF | tr -d 'refs/tags/v') +file_tag=$(grep '"version":' package.json | cut -d ':' -f 2- | tr -d ' ' | tr -d '"' | tr -d ',') +if [ "$current_tag" != "$file_tag" ]; then + echo "Error: the current tag does not match the version in package file(s)." + echo "$current_tag vs $file_tag" + exit 1 +fi + +echo 'OK' +exit 0