From e24e01a87208901e6ef659d600ea5e5317934948 Mon Sep 17 00:00:00 2001 From: Charlotte Vermandel Date: Fri, 28 May 2021 18:39:29 +0200 Subject: [PATCH] Add publish CI --- .github/workflows/publish.yml | 21 +++++++++++++++++++++ scripts/check-release.sh | 13 +++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 .github/workflows/publish.yml create mode 100644 scripts/check-release.sh 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