Skip to content

Commit

Permalink
Add publish CI
Browse files Browse the repository at this point in the history
  • Loading branch information
bidoubiwa committed May 28, 2021
1 parent d925398 commit e24e01a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -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}}
13 changes: 13 additions & 0 deletions scripts/check-release.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e24e01a

Please sign in to comment.