prescottprue/react-google-button

View on GitHub
.github/workflows/publish.yml

Summary

Maintainability
Test Coverage
name: NPM Package Publish

on:
  push:
    branches:
      - master
      - next

jobs:
  build:
    name: Build
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Code
        uses: actions/checkout@v2

      - name: Setup Node 12
        uses: actions/setup-node@v1
        with:
          node-version: 12
          registry-url: https://registry.npmjs.org/

      - name: Get Cache Settings
        id: yarn-cache
        run: echo "::set-output name=dir::$(yarn cache dir)"

      - name: Cache Dependencies
        uses: actions/cache@v1
        with:
          path: ${{ steps.yarn-cache.outputs.dir }}
          key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}

      - name: Install Dependencies
        env:
          CI: true
        run: |
          yarn install --frozen-lockfile

      - name: Run Unit Tests + Coverage
        run: yarn test:cov

      - name: Build
        run: yarn build

      - name: Publish To NPM
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
          GITHUB_REF: ${{ github.ref }}
        run: npm publish $(if [ "$GITHUB_REF" != 'refs/heads/master' ]; then echo '--tag next';fi;)

      - name: Get package version
        id: package-info
        env:
          SHA: ${{ github.sha }}
        run: |
          echo "::set-output name=version::$(yarn info react-google-button version)"
          echo "::set-output name=body::$(git --no-pager log --format=%B -n 1 $SHA)"

      - name: Create Release
        id: create_release
        uses: actions/create-release@v1
        env:
          GITHUB_TOKEN: ${{ github.token }}
        with:
          tag_name: v${{ steps.package-info.outputs.version }}
          release_name: v${{ steps.package-info.outputs.version }}
          draft: false
          body: ${{ steps.package-info.outputs.body }}
          prerelease: ${{ github.ref }} == 'refs/heads/next'

      - name: Upload Coverage
        if: success()
        env:
          CI: true
          CODE_COV: ${{ secrets.CODE_COV }}
        run: |
          # Upload to Code Cover. Curl used in place of codecov/codecov-action
          # due to long build time. See https://github.com/codecov/codecov-action/issues/21
          curl -s https://codecov.io/bash | bash -s -- -t $CODE_COV