kalidea/kaligraphi

View on GitHub
.github/workflows/build.yml

Summary

Maintainability
Test Coverage

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  CI:
    runs-on: ubuntu-latest
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - name: Checkout
        uses: actions/checkout@v2

      - name: Set node version
        uses: actions/setup-node@master
        with:
          node-version: '10.x'

      - name: Install
        run: npm i

      - name: Test
        run: npm run test:ci

      - name: Build Lib & Playground
        run: |
          npm run build
          npm run build:playground -- --base-href /kaligraphi/

      - name: Upload to Github Pages
        uses: JamesIves/github-pages-deploy-action@3.5.9
        with:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          BRANCH: gh-pages # The branch the action should deploy to.
          FOLDER: dist/playground # The folder the action should deploy.

      - name: Upload artifact
        uses: actions/upload-artifact@v2
        with:
          name: dist
          path: dist/


  DEPLOY:
    needs: CI
    if: (github.event_name == 'push' && (contains(github.ref, '/heads/master') || contains(github.ref, '/tags/v')))
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Grab last artifact
        uses: actions/download-artifact@v2
        with:
          name: dist
          path: dist/

      - name: Copy Files & create asset
        id: create-asset
        run: |
          cp README.md dist/kalidea/kaligraphi/
          cd dist/kalidea/kaligraphi
          npm pack
          echo "::set-output name=filename::`ls *.tgz`"

      - name: Create Release
        id: create-release
        uses: actions/create-release@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          tag_name: ${{ github.ref }}
          release_name: Release ${{ github.ref }}
          draft: false
          prerelease: false

      - name: Upload Release Asset
        id: upload-release-asset
        uses: actions/upload-release-asset@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          upload_url: ${{ steps.create-release.outputs.upload_url }}
          asset_path: ./${{ steps.create-asset.outputs.filename }}
          asset_name: ${{ steps.create-asset.outputs.filename }}
          asset_content_type: application/gzip

      - name: Deploy to NPMJS
        uses: actions/setup-node@v1
        with:
          node-version: '10.x'
          registry-url: 'https://registry.npmjs.org'
      # Publish to npm
      - run: npm publish --access public
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPMJS_TOKEN }}
      # Setup .npmrc file to publish to GitHub Packages
      - name: Deploy to github package
        uses: actions/setup-node@v1
        with:
          registry-url: 'https://npm.pkg.github.com'
          # Defaults to the user or organization that owns the workflow file
          scope: '@kalidea'
      # Publish to GitHub Packages
      - run: npm publish
        env:
          NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}