domjtalbot/nx-mesh

View on GitHub
.github/workflows/__generators.yml

Summary

Maintainability
Test Coverage
name: 'Generators'

on:
  workflow_call:
    inputs:
      affected:
        description: >
          Run for affected projects.
        required: false
        default: true
        type: boolean
      examples:
        description: >
          The Nx version to test against
        required: false
        type: string
        default: '["country-info", "fake-api", "rfam", "stackexchange", "star-wars", "trippin"]'
      node_version:
        description: >
          Optionally define the version of Node to install.
        required: false
        default: 'lts/*'
        type: string
      nx_version:
        description: >
          The Nx version to test against
        required: false
        type: string
        default: '["15.7.1", "15.7", "15.8", "latest"]'
      save_cache:
        description: >
          Should the cache be saved upon completion?
        required: false
        default: false
        type: boolean
    secrets:
      NX_CLOUD_ACCESS_TOKEN:
        description: 'The NX Cloud API token'
        required: true
      NX__TRIPPIN__API_KEY:
        description: 'The Trippin API Key'
        required: true

concurrency:
  group: generators--${{ github.workflow }}--${{ github.ref }}

env:
  NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
  NX__TRIPPIN__API_KEY: ${{ secrets.NX__TRIPPIN__API_KEY }}

jobs:
  generator:
    name: Generator - nx-${{ matrix.nx_version }}/${{ matrix.example }}/${{ matrix.type }}
    runs-on: ubuntu-latest
    timeout-minutes: 10
    strategy:
      fail-fast: false
      matrix:
        type: [application, sdk, preset]
        example: ${{fromJson(inputs.examples)}}
        nx_version: ${{fromJson(inputs.nx_version)}}
    steps:
      - name: Check out repository
        uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3
        with:
          fetch-depth: 0

      - name: Setup Job
        uses: ./.github/actions/setup-job
        id: setup
        with:
          node_version: ${{ inputs.node_version }}
          skip_node_cache: 'true'

      - name: Restore PNPM cache
        uses: actions/cache/restore@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3
        id: pnpm-cache
        with:
          path: |
            ${{ steps.setup.outputs.pnpm_directory }}
          key: |
            generators--pnpm--nx-${{ matrix.nx_version }}--type-${{ matrix.type }}--example-${{ matrix.example }}

      - name: Download Nx Mesh
        uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3
        with:
          name: nx-mesh

      - name: Test Generator - (node-${{ inputs.node_version }}/nx-${{ matrix.nx_version }}/${{ matrix.type }}-${{ matrix.example }})
        shell: bash
        run: |
          cd ../
          pnpm dlx create-nx-workspace@${{ matrix.nx_version }} \
            --name=generator \
            --appName=${{ matrix.example }} \
            --preset=apps \
            --interactive=false \
            --nxCloud=false \
            --style=css \
            --skipGit
          cd generator
          pnpm nx report
          npm pkg set "pnpm.overrides.@nrwl/cypress"="${{ matrix.nx_version }}"
          npm pkg set "pnpm.overrides.@nrwl/jest"="${{ matrix.nx_version }}"
          npm pkg set "pnpm.overrides.@nrwl/js"="${{ matrix.nx_version }}"
          npm pkg set "pnpm.overrides.@nrwl/node"="${{ matrix.nx_version }}"
          npm pkg set "pnpm.overrides.@nrwl/webpack"="${{ matrix.nx_version }}"
          pnpm add ../nx-mesh/nx-mesh.tar.gz
          pnpm nx report
          pnpm exec nx generate nx-mesh:${{ matrix.type }} \
            ${{ matrix.example }} \
            --example=${{ matrix.example }} \
            --no-interactive
          pnpm nx run ${{ matrix.example }}:build

      - name: Save PNPM cache
        uses: actions/cache/save@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3
        with:
          path: |
            ${{ steps.setup.outputs.pnpm_directory }}
          key: |
            generators--pnpm--nx-${{ matrix.nx_version }}--type-${{ matrix.type }}--example-${{ matrix.example }}