SIWF v2 Process Payloads #697
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Test | |
on: | |
pull_request: | |
branches: | |
- main | |
push: | |
branches: | |
- main | |
jobs: | |
service-matrix: | |
runs-on: ubuntu-latest | |
outputs: | |
changes: ${{ steps.determine-matrix.outputs.changes }} | |
# IF you add a new filter it ALSO needs to be here | |
services: >- | |
["account", "content-publishing", "content-watcher", "graph"] | |
# Resolves to true if it should run everything, aka when common files change | |
run-all: ${{ steps.determine-matrix.outputs.changes.common }} | |
steps: | |
- name: Check Out Repo | |
uses: actions/checkout@v4 | |
- uses: dorny/paths-filter@v3 | |
id: determine-matrix | |
with: | |
# Adding a filter? Check for the need to add to the outputs as well | |
filters: | | |
common: | |
- 'Docker/**' | |
- '.github/**' | |
- 'docker-compose.yaml' | |
- 'libs/types' | |
- 'libs/utils' | |
- 'libs/consumer' | |
account: | |
- 'apps/account-api/**' | |
- 'apps/account-worker/**' | |
- 'libs/account-lib/**' | |
graph: | |
- 'apps/graph-api/**' | |
- 'apps/graph-worker/**' | |
- 'libs/graph-lib/**' | |
content-publishing: | |
- 'apps/content-publishing-api/**' | |
- 'apps/content-publishing-worker/**' | |
- 'libs/content-publishing-lib/**' | |
- 'libs/storage/**' | |
content-watcher: | |
- 'apps/content-watcher/**' | |
- 'libs/content-watcher-lib/**' | |
- 'libs/storage/**' | |
build: | |
name: '[${{ matrix.service }}] Build and Test' | |
runs-on: ubuntu-latest | |
needs: service-matrix | |
strategy: | |
fail-fast: false | |
matrix: | |
service: ${{ fromJson(needs.service-matrix.outputs.services) }} | |
# NOTE: The if statement has to be on each step. :( | |
# This is because the job level if statement cannot handle matrix values | |
steps: | |
- name: Run or Skip | |
id: should | |
run: echo "RUN=${{ needs.service-matrix.outputs.run-all || contains(fromJson(needs.service-matrix.outputs.changes), matrix.service) }}" >> "$GITHUB_OUTPUT" | |
- name: Checkout | |
if: ${{ steps.should.outputs.RUN == 'true' }} | |
uses: actions/checkout@v4 | |
- name: Install Node.js | |
if: ${{ steps.should.outputs.RUN == 'true' }} | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
cache: 'npm' | |
registry-url: 'https://registry.npmjs.org' | |
cache-dependency-path: ./package-lock.json | |
- name: Install dependencies | |
if: ${{ steps.should.outputs.RUN == 'true' }} | |
run: npm ci | |
- name: Build NestJS | |
if: ${{ steps.should.outputs.RUN == 'true' }} | |
run: npm run build:${{ matrix.service }} | |
- name: Lint | |
if: ${{ steps.should.outputs.RUN == 'true' }} | |
run: npm run lint:${{ matrix.service }} | |
- name: Unit Test | |
if: ${{ steps.should.outputs.RUN == 'true' }} | |
run: npm run test:${{ matrix.service }} | |
- name: License Check | |
if: ${{ steps.should.outputs.RUN == 'true' }} | |
# List all the licenses and error out if it is not one of the supported licenses | |
run: npx license-report --fields=name --fields=licenseType | jq 'map(select(.licenseType | IN("MIT", "Apache-2.0", "ISC", "BSD-3-Clause", "BSD-2-Clause", "(Apache-2.0 AND MIT)", "Apache-2.0 OR MIT") | not)) | if length == 0 then halt else halt_error(1) end' | |
- name: Build OpenAPI spec | |
if: ${{ steps.should.outputs.RUN == 'true' }} | |
uses: ./.github/workflows/common/openapi-build | |
with: | |
service: ${{ matrix.service }} | |
# Test build of the Docker images | |
- name: Set up QEMU | |
if: ${{ steps.should.outputs.RUN == 'true' }} | |
uses: docker/setup-qemu-action@v3 | |
with: | |
platforms: | | |
linux/amd64 | |
- name: Set up Docker Buildx | |
if: ${{ steps.should.outputs.RUN == 'true' }} | |
uses: docker/setup-buildx-action@v3 | |
# Use GitHub Container Registry instead due to rate limits | |
with: | |
buildkitd-config-inline: | | |
[registry."ghcr.io"] | |
- name: Login to DockerHub | |
if: ${{ steps.should.outputs.RUN == 'true' }} | |
uses: docker/login-action@v3 | |
with: | |
username: ${{secrets.DOCKERHUB_USERNAME}} | |
password: ${{secrets.DOCKERHUB_TOKEN}} | |
- name: Build Docker Image | |
if: ${{ steps.should.outputs.RUN == 'true' }} | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
platforms: linux/amd64 | |
push: false | |
file: Docker/Dockerfile.${{ matrix.service }} |