graycoreio/daffodil

View on GitHub
.github/workflows/build.yml

Summary

Maintainability
Test Coverage
name: Daffodil Build

env:
  NX_REJECT_UNKNOWN_LOCAL_CACHE: 0

on:
  push:
    branches:
      - develop
    tags: ["v*"]
  pull_request:
    branches:
      - develop

jobs:
  build:
    name: Build
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node: [18.19.x]
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0

      - uses: nrwl/nx-set-shas@v3
        name: Derive appropriate SHAs for base and head for `nx affected` commands
        with:
          main-branch-name: 'develop'

      - uses: actions/cache@v3
        name: Cache `.nx_cache`
        id: build_cache
        with:
          path: .nx_cache
          key: build-${{ matrix.node }}-${{ github.sha }}
          restore-keys:
            build-${{ matrix.node }}

      - uses: graycoreio/github-actions/clear-old-nx-cache@main
        with:
          size-in-mb: 500

      - uses: graycoreio/github-actions/setup-node@main
        with:
          node-version: ${{ matrix.node }}
          use-stamp-cache: true

      - run: npx lerna run build --concurrency=1

      - run: cd dist/apps/daffio && zip -r ../daffio.zip .

      - uses: actions/upload-artifact@v3
        with:
          name: daffio-${{ matrix.node }}
          path: dist/apps/daffio.zip
          if-no-files-found: error

  compute_packages:
    name: Compute Packages to Test
    outputs:
      packages: ${{ steps.compute.outputs.packages }}
    runs-on: ubuntu-latest
    needs: [ ]
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - uses: graycoreio/github-actions/setup-node@main
        with:
          node-version: '18.19.x'
          use-stamp-cache: true
      - uses: nrwl/nx-set-shas@v3
        name: Derive appropriate SHAs for base and head for `nx affected` commands
        with:
          main-branch-name: 'develop'
      - name: packages
        id: compute
        shell: bash
        run: |
          packages=$(npx lerna ls --since=$NX_BASE --all --json | jq '[.[] | .name]' -c)
          echo "packages=$packages" >> ${GITHUB_OUTPUT}
  test:
    name: Test
    runs-on: ubuntu-latest
    if: ${{ needs.compute_packages.outputs.packages != '[]' && needs.compute_packages.outputs.packages != '' }}
    strategy:
      fail-fast: false
      matrix:
        package: ${{ fromJSON(needs.compute_packages.outputs.packages) }}
        node: [18.19.x]
    needs:
      - compute_packages
      - build
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0

      - uses: nrwl/nx-set-shas@v3
        name: Derive appropriate SHAs for base and head for `nx affected` commands
        with:
          main-branch-name: 'develop'

      - uses: actions/cache@v3
        name: Cache `.nx_cache`
        id: build_cache
        with:
          fail-on-cache-miss: true
          path: .nx_cache
          key: build-${{ matrix.node }}-${{ github.sha }}

      - uses: graycoreio/github-actions/setup-node@main
        with:
          node-version: ${{ matrix.node }}
          use-stamp-cache: true

      - run: npx lerna run test --scope="${{ matrix.package }}" --concurrency=1
        name: Test ${{ matrix.package }}

  deploy_daffio:
    name: Deploy Daff.io
    needs:
      - build
    uses: ./.github/workflows/deploy.yml
    secrets:
      VERCEL_NEXT_PROJECT_ID: ${{ secrets.VERCEL_DAFFIO_NEXT_PROJECT_ID }}
      VERCEL_PROJECT_ID: ${{ secrets.VERCEL_DAFFIO_PROJECT_ID }}
      VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
      VERCEL_ORG: ${{ secrets.VERCEL_ORG }}
    with:
      artifact: daffio-18.19.x
      artifact-zip-name: daffio.zip

  publish:
    name: Publish
    runs-on: ubuntu-latest
    if: startsWith(github.ref, 'refs/tags/v')
    needs:
      - build
    steps:
    - uses: actions/checkout@v3
      with:
        fetch-depth: 1

    - uses: actions/cache@v3
      name: Cache `.nx_cache`
      id: build_cache
      with:
        fail-on-cache-miss: true
        path: .nx_cache
        key: build-18.19.x-${{ github.sha }}

    - uses: graycoreio/github-actions/setup-node@main
      with:
        node-version: 18.19.x
        use-stamp-cache: true
        registry-url: 'https://registry.npmjs.org'

    - run: npx lerna run build

    - uses: graycoreio/github-actions/set-versions-from-root@main

    - run: npx lerna run publish
      env:
        NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}