Skip to content

Commit

Permalink
feat: trigger deployment only on path changes
Browse files Browse the repository at this point in the history
  • Loading branch information
bmstefanski committed Jan 2, 2025
1 parent 77533ed commit d094d41
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
28 changes: 25 additions & 3 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ name: Deploy

on:
push:
paths:
- "apps/**"
- "package.json"
branches:
- main
tags:
Expand All @@ -13,7 +10,26 @@ on:
workflow_dispatch:

jobs:
changes:
runs-on: ubuntu-latest
outputs:
services: ${{ steps.filter.outputs.changes }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v2
id: filter
with:
filters: |
gateway-service:
- 'apps/gateway-service/**'
- 'package.json'
storefront:
- 'apps/storefront/**'
- 'package.json'
push:
needs: changes
if: ${{ needs.changes.outputs.services != '[]' }}
strategy:
matrix:
service:
Expand All @@ -25,6 +41,8 @@ jobs:
path: apps/storefront
package: "@cavaliercommerce/storefront"
dockerfile: apps/storefront/Dockerfile
include:
- ${{ fromJSON(needs.changes.outputs.services) }}

runs-on: ubuntu-latest
permissions:
Expand Down Expand Up @@ -58,15 +76,19 @@ jobs:
run: pnpm install

- name: Run tests
if: contains(needs.changes.outputs.services, matrix.service.name)
run: pnpm test --filter ${{ matrix.service.package }}

- name: Build image
if: contains(needs.changes.outputs.services, matrix.service.name)
run: docker build . --file ${{ matrix.service.dockerfile }} --tag ${{ matrix.service.name }} --label "runnumber=${GITHUB_RUN_ID}"

- name: Log in to registry
if: contains(needs.changes.outputs.services, matrix.service.name)
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin

- name: Push image
if: contains(needs.changes.outputs.services, matrix.service.name)
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/${{ matrix.service.name }}
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
Expand Down
2 changes: 1 addition & 1 deletion apps/gateway-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"test:watch": "vitest",
"test:cov": "vitest run --coverage",
"test:debug": "vitest --inspect-brk --inspect --logHeapUsage --threads=false",
"test:e2e": "vitest run --config ./vitest.config.e2e.ts"
"test:e2e": "vitest run --config ./vitest.config.e2e.ts "
},
"dependencies": {
"@nestjs/common": "10.0.0",
Expand Down
2 changes: 1 addition & 1 deletion apps/storefront/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"start": "next start",
"lint": "next lint --max-warnings 0",
"format": "prettier --no-error-on-unmatched-pattern --write \"**/*.(ts|tsx)\"",
"check-types": "tsc --noEmit"
"check-types": "tsc --noEmit "
},
"dependencies": {
"next": "15.1.0",
Expand Down

0 comments on commit d094d41

Please sign in to comment.