feedsbrain/pssh-tools

View on GitHub
.github/workflows/npm-publish.yml

Summary

Maintainability
Test Coverage
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages

name: NPM Publish

on:
  release:
    types: [created]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v2
        with:
          node-version: 14
      - run: npm ci && npm test

  publish:
    needs: build
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v2
        with:
          node-version: 14
          registry-url: 'https://npm.pkg.github.com'
          scope: '@feedsbrain'

      - name: Get Package Version
        run: |
          # Strip git ref prefix from version
          VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')

          # Strip "v" prefix from tag name
          [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')

          # Save Image version info to GitHub environment variable
          echo "PACKAGE_VERSION=$VERSION" >> $GITHUB_ENV

      - name: NPM Version
        uses: reedyuk/npm-version@1.1.1
        with:
          version: ${{ env.PACKAGE_VERSION }}

      - name: Authenticate to GitHub Package Registry
        run: echo "//npm.pkg.github.com:_authToken=${{ secrets.GITHUB_TOKEN }}" > ~/.npmrc

      - name: Publishing to GitHub Package
        run: npm ci && npm publish
        env:
            NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}