|
| 1 | +name: Continuous Integration |
| 2 | +concurrency: ${{ github.ref }} |
| 3 | + |
| 4 | +on: |
| 5 | + workflow_dispatch: |
| 6 | + inputs: |
| 7 | + nx-base: |
| 8 | + type: string |
| 9 | + description: Commit SHA, branch or tag name used by Nx in the affected jobs. |
| 10 | + required: true |
| 11 | + default: next |
| 12 | + nx-skip-cache: |
| 13 | + type: boolean |
| 14 | + description: Rerun the tasks even when the results are available in the cache. |
| 15 | + default: false |
| 16 | + nx-force-all: |
| 17 | + type: boolean |
| 18 | + description: Forces Nx to consider all projects (apps and libs) as affected. |
| 19 | + default: false |
| 20 | + pull_request: |
| 21 | + types: [opened, reopened, synchronize] |
| 22 | + push: |
| 23 | + branches: |
| 24 | + - main |
| 25 | + - next |
| 26 | + |
| 27 | +env: |
| 28 | + NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }} |
| 29 | + NX_BRANCH: ${{ github.head_ref || github.ref_name }} |
| 30 | + NX_FORCE_ALL: ${{ fromJSON('["", "--all"]')[ inputs.nx-force-all ] }} # This relies on type coercion, an implicit cast from boolean true to 1 or false to 0, which is then used as array index. |
| 31 | + NX_AFFECTED_OR_ALL: ${{ fromJSON('["affected", "run-many --all"]')[ inputs.nx-force-all ] }} |
| 32 | + NX_SKIP_NX_CACHE: ${{ inputs.nx-skip-cache || false }} |
| 33 | + BASE: ${{ github.base_ref || inputs.nx-base || github.event.repository.default_branch }} |
| 34 | + |
| 35 | +jobs: |
| 36 | + ci: |
| 37 | + name: Continuous Integration |
| 38 | + if: github.event_name == 'push' || ( github.event_name == 'pull_request' && github.head_ref != 'next' ) || github.event_name == 'workflow_dispatch' |
| 39 | + runs-on: ubuntu-20.04 |
| 40 | + steps: |
| 41 | + - uses: actions/checkout@v4 |
| 42 | + with: |
| 43 | + fetch-depth: 0 |
| 44 | + |
| 45 | + - uses: nrwl/nx-set-shas@v4 |
| 46 | + with: |
| 47 | + main-branch-name: ${{ env.BASE }} |
| 48 | + |
| 49 | + - uses: actions/setup-node@v4 |
| 50 | + with: |
| 51 | + node-version-file: "package.json" |
| 52 | + cache: "npm" |
| 53 | + cache-dependency-path: "**/package-lock.json" |
| 54 | + |
| 55 | + - name: Cache global node modules |
| 56 | + id: cache-node-modules |
| 57 | + uses: actions/cache@v4 |
| 58 | + env: |
| 59 | + cache-name: cache-node-modules |
| 60 | + with: |
| 61 | + path: node_modules |
| 62 | + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('package-lock.json') }} |
| 63 | + |
| 64 | + - name: Install Dependencies |
| 65 | + if: ${{ steps.cache-node-modules.outputs.cache-hit != 'true' }} |
| 66 | + run: npm ci |
| 67 | + |
| 68 | + - name: Nx Format Check |
| 69 | + run: npx nx format:check $NX_FORCE_ALL |
| 70 | + |
| 71 | + - name: Lint |
| 72 | + run: npx nx $NX_AFFECTED_OR_ALL --target=lint --parallel=3 |
| 73 | + |
| 74 | + - name: Build |
| 75 | + run: | |
| 76 | + npx nx $NX_AFFECTED_OR_ALL --target=build --parallel=3 |
| 77 | + npx nx $NX_AFFECTED_OR_ALL --target=postbuild --parallel=3 |
| 78 | +
|
| 79 | + - name: Get number of CPU cores |
| 80 | + uses: SimenB/github-actions-cpu-cores@v2 |
| 81 | + id: cpu-cores |
| 82 | + |
| 83 | + - name: Test |
| 84 | + env: |
| 85 | + NODE_OPTIONS: "--max_old_space_size=4096" |
| 86 | + run: npx nx $NX_AFFECTED_OR_ALL --target=test --coverage --maxWorkers=${{ steps.cpu-cores.outputs.count }} |
| 87 | + |
| 88 | + nx: |
| 89 | + name: Nx |
| 90 | + needs: ci |
| 91 | + if: ${{ github.ref_name == github.event.repository.default_branch || github.ref_name == 'next' }} |
| 92 | + uses: ./.github/workflows/nx.template.yml |
| 93 | + with: |
| 94 | + nx-head: ${{ github.head_ref && format('refs/pull/{0}/merge', github.event.number) || github.ref_name }} |
| 95 | + nx-base: ${{ github.base_ref || inputs.nx-base || github.event.repository.default_branch }} |
| 96 | + nx-skip-cache: ${{ inputs.nx-skip-cache || false }} # This relies on type coercion, an implicit cast from boolean true to 1 or false to 0, which is then used as array index. |
| 97 | + nx-force-all: ${{ inputs.nx-force-all || false }} |
| 98 | + |
| 99 | + release: |
| 100 | + name: Release |
| 101 | + needs: nx |
| 102 | + uses: amplication/amplication/.github/workflows/release.template.yml@master |
| 103 | + if: ${{ github.ref_name == github.event.repository.default_branch }} |
| 104 | + with: |
| 105 | + default-branch: ${{ github.event.repository.default_branch }} |
| 106 | + branch: ${{ github.ref_name }} |
| 107 | + enable-custom-tags: true |
| 108 | + affected-apps: ${{ needs.nx.outputs.affected-apps }} |
| 109 | + affected-lib: ${{ needs.nx.outputs.affected-lib }} |
| 110 | + affected-package-container: ${{ needs.nx.outputs.affected-package-container }} |
| 111 | + affected-deploy-static: ${{ needs.nx.outputs.affected-deploy-static }} |
| 112 | + affected-deploy-container: ${{ needs.nx.outputs.affected-deploy-container }} |
| 113 | + secrets: |
| 114 | + NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }} |
| 115 | + ECR_AWS_ACCESS_KEY_ID: ${{ secrets.ECR_AWS_ACCESS_KEY_ID }} |
| 116 | + ECR_AWS_SECRET_ACCESS_KEY: ${{ secrets.ECR_AWS_SECRET_ACCESS_KEY }} |
| 117 | + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 118 | + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
0 commit comments