Create a GitHub Actions pipeline for a monorepo with Angular and NestJS. It should use a…
- User
Create a GitHub Actions pipeline for a monorepo with Angular and NestJS. It should use a matrix strategy to test on Node 18, 20, and 22, with path filtering so backend builds only trigger for /backend changes. Also build and push a Docker image to ECR on passing tags.
- Assistant
Crafting comprehensive GitHub Actions YAML
Preparing a single workflow YAML for the monorepo with Angular frontend and NestJS backend, featuring matrix Node versions, path-based job gating via dorny/paths-filter, and a Docker image build-and-push to AWS ECR triggered on tagged releases after successful tests. Here’s a single workflow file that covers:
- Matrix testing on Node 18, 20, 22
- Path filtering so the backend job only runs when
/backendchanges - Tag-based build & push of the backend Docker image to ECR (after tests pass)
Save as
.github/workflows/ci.yml:name: CI on: push: branches: [ main ] tags: [ 'v*' ] # run on version tags for releases pull_request: branches: [ main ] workflow_dispatch: jobs: changes: name: Detect changes runs-on: ubuntu-latest outputs: backend: ${{ steps.filter.outputs.backend }} frontend: ${{ steps.filter.outputs.frontend }} steps: - uses: actions/checkout@v4 - id: filter uses: dorny/paths-filter@v3 with: filters: | backend: - 'backend/**' frontend: - 'frontend/**' test-backend: name: Test backend (NestJS) needs: changes if: needs.changes.outputs.backend == 'true' || (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')) runs-on: ubuntu-latest strategy: fail-fast: false matrix: node: [ 18.x, 20.x, 22.x ] steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: ${{ matrix.node }} cache: npm cache-dependency-path: backend/package-lock.json - name: Install dependencies run: npm ci working-directory: backend - name: Lint run: npm run lint working-directory: backend - name: Test run: npm test -- --watch=false --runInBand working-directory: backend # - name: Build (optional) # run: npm run build # working-directory: backend test-frontend: name: Test frontend (Angular) needs: changes if: needs.changes.outputs.frontend == 'true' runs-on: ubuntu-latest strategy: fail-fast: false matrix: node: [ 18.x, 20.x, 22.x ] steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: ${{ matrix.node }} cache: npm cache-dependency-path: frontend/package-lock.json - name: Install dependencies run: npm ci working-directory: frontend - name: Lint run: npm run lint working-directory: frontend - name: Test run: npm test -- --watch=false working-directory: frontend # - name: Build (optional) # run: npm run build # working-directory: frontend docker-ecr: name: Build & push backend image to ECR needs: [ test-backend ] if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') runs-on: ubuntu-latest env: AWS_REGION: us-east-1 # change to your region ECR_REPOSITORY: my-backend # change to your ECR repo name IMAGE_TAG: ${{ github.ref_name }} # tag name, e.g., v1.2.3 steps: - uses: actions/checkout@v4 - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v4 with: aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} aws-region: ${{ env.AWS_REGION }} - name: Login to Amazon ECR id: login-ecr uses: aws-actions/amazon-ecr-login@v2 - name: Build & push image env: ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} run: | docker build -t $ECR_REGISTRY/${ECR_REPOSITORY}:${IMAGE_TAG} -f backend/Dockerfile backend docker push $ECR_REGISTRY/${ECR_REPOSITORY}:${IMAGE_TAG} # optionally push "latest" docker tag $ECR_REGISTRY/${ECR_REPOSITORY}:${IMAGE_TAG} $ECR_REGISTRY/${ECR_REPOSITORY}:latest docker push $ECR_REGISTRY/${ECR_REPOSITORY}:latestNotes:
- Update
AWS_REGION,ECR_REPOSITORY, and setAWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEYsecrets in your repo. - The backend job always runs on tag pushes to allow releasing even if the last changes were elsewhere.
- Adjust
cache-dependency-pathto your lockfile type if you use Yarn/PNPM.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.