Skip to content

init for github actions release and publish #1

init for github actions release and publish

init for github actions release and publish #1

Workflow file for this run

name: Release and publish
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
- run: npm ci
- run: npm test
publish-npm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-node@v3
with:
node-version: 16
registry-url: 'https://registry.npmjs.org'
- run: npm ci
- name: Check if version has been incremented
id: check-version
run: |
VERSION=$(node -p "require('./package.json').version")
PREVIOUS_VERSION=$(git show HEAD~1:package.json | node -p "require('./package.json').version")
if [ "$VERSION" != "$PREVIOUS_VERSION" ]; then
echo "::set-output name=version_changed::true"
echo "::set-output name=new_version::$VERSION"
fi
- name: Create GitHub release
if: steps.check-version.outputs.version_changed == 'true'
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.check-version.outputs.new_version }}
release_name: Release ${{ steps.check-version.outputs.new_version }}
draft: false
prerelease: false
- name: Publish to npm
if: steps.check-version.outputs.version_changed == 'true'
run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}