-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6ad0969
commit 6861a64
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
name: Publish to npm | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
test-and-publish: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: '20' | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Run tests | ||
run: npm test | ||
|
||
- name: Get current version | ||
id: get_version | ||
run: echo "::set-output name=version::$(node -p -e \"require('./package.json').version\")" | ||
|
||
- name: Check if version is bumped | ||
id: version_check | ||
run: | | ||
git fetch --tags | ||
if [ "$(git tag --list "v${{ steps.get_version.outputs.version }}")" ]; then | ||
echo "Version ${{ steps.get_version.outputs.version }} is already published." | ||
exit 1 | ||
else | ||
echo "Version ${{ steps.get_version.outputs.version }} is new and will be published." | ||
fi | ||
- name: Publish to npm | ||
if: ${{ success() && steps.version_check.outputs.version != '' }} | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
run: | | ||
npm publish | ||
git tag "v${{ steps.get_version.outputs.version }}" | ||
git push origin "v${{ steps.get_version.outputs.version }}" |