diff --git a/.github/workflows/pr_to_master.yml b/.github/workflows/pr_to_master.yml index 7133dea..fbe72af 100644 --- a/.github/workflows/pr_to_master.yml +++ b/.github/workflows/pr_to_master.yml @@ -1,10 +1,20 @@ # Execute only if it's a PR which comes from dev + name: PR to master + +# This pipeline runs everytime there is a PR on master. +# Because the changes on the submodules are track on their own GitHub project, +# I intentionally don't listen to the changes of each submodule in order to trigger this pipeline. + on: pull_request: branches: - master # I allow only PR from dev -> master +permissions: + contents: read + packages: write + jobs: #----------------------------------------------------------------------- #--- Validate the PR's branch @@ -22,53 +32,20 @@ jobs: fi #----------------------------------------------------------------------- - #--- Detect the changes + #--- Build backend services #----------------------------------------------------------------------- - changes: - runs-on: ubuntu-latest + build-backend-services: needs: validate-branch - if: success() - steps: - - name: Checkout the main repository - uses: actions/checkout@v4 - with: - submodules: true - - - name: Detect changes - id: filter - uses: dorny/paths-filter@v3 - with: - filters: | - user: - - 'submodules/user-service/**' - book: - - 'submodules/book-service/**' - review: - - 'submodules/review-service/**' - api_gateway: - - 'submodules/api-gateway/**' - registry_service: - - 'submodules/registry-service/**' - frontend: - - 'mflibrary-frontend/**' - outputs: - user: ${{ steps.filter.outputs.user }} - book: ${{ steps.filter.outputs.book }} - review: ${{ steps.filter.outputs.review }} - api_gateway: ${{ steps.filter.outputs.api_gateway }} - registry_service: ${{ steps.filter.outputs.registry_service }} - frontend: ${{ steps.filter.outputs.frontend }} - - #----------------------------------------------------------------------- - #--- Build and push user-service Docker image - #----------------------------------------------------------------------- - build-user-service: - needs: changes - if: needs.changes.outputs.user == 'true' runs-on: ubuntu-latest + strategy: + matrix: + service: [ api-gateway, registry-service, user-service, book-service, review-service ] + env: + IMAGE_TAG: ${{ github.sha }} + REPO_NAME: ${{ github.repository }} steps: - - name: Checkout the submodule user-service + - name: Checkout repository uses: actions/checkout@v4 with: submodules: true @@ -80,50 +57,20 @@ jobs: distribution: 'temurin' cache: 'maven' - - name: Run the user-service tests + - name: Run tests run: | - chmod +x ./submodules/user-service/mvnw - ./submodules/user-service/mvnw -f ./submodules/user-service/pom.xml clean test - - - name: Login to GitHub Container Registry - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} + chmod +x ./submodules/${{ matrix.service }}/mvnw + ./submodules/${{ matrix.service }}/mvnw -f ./submodules/${{ matrix.service }}/pom.xml clean test - - name: Build and push user-service Docker image - uses: docker/build-push-action@v6 - with: - context: ./submodules/user-service - push: true - tags: ghcr.io/${{ github.repository }}/user-service:latest + # GitHub Container Registry enforces all repository paths to be lowercase. + - name: Set lowercase repo name + run: echo "REPO_LC=${REPO_NAME,,}" >> $GITHUB_ENV - #----------------------------------------------------------------------- - #--- Build and push book-service Docker image - #----------------------------------------------------------------------- - build-book-service: - needs: changes - if: needs.changes.outputs.book == 'true' - runs-on: ubuntu-latest - - steps: - - name: Checkout the submodule book-service - uses: actions/checkout@v4 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 with: - submodules: true - - - name: Set up JDK 21 - uses: actions/setup-java@v4 - with: - java-version: '21' - distribution: 'temurin' - cache: 'maven' - - - name: Run the book-service tests - run: | - chmod +x ./submodules/book-service/mvnw - ./submodules/book-service/mvnw -f ./submodules/book-service/pom.xml clean test + install: true + driver: docker-container - name: Login to GitHub Container Registry uses: docker/login-action@v3 @@ -132,139 +79,30 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Build and push book-service Docker image + - name: Build and push Docker image uses: docker/build-push-action@v6 with: - context: ./submodules/book-service + context: ./submodules/${{ matrix.service }} push: true - tags: ghcr.io/${{ github.repository }}/book-service:latest - - #----------------------------------------------------------------------- - #--- Build and push review-service Docker image - #----------------------------------------------------------------------- - build-review-service: - needs: changes - if: needs.changes.outputs.review == 'true' - runs-on: ubuntu-latest - steps: - - name: Checkout the submodule review-service - uses: actions/checkout@v4 - with: - submodules: true - - - name: Set up JDK 21 - uses: actions/setup-java@v4 - with: - java-version: '21' - distribution: 'temurin' - cache: 'maven' - - - name: Run the review-service tests - run: | - chmod +x ./submodules/review-service/mvnw - ./submodules/review-service/mvnw -f ./submodules/review-service/pom.xml clean test - - - name: Login to GitHub Container Registry - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Build and push review-service Docker image - uses: docker/build-push-action@v6 - with: - context: ./submodules/review-service - push: true - tags: ghcr.io/${{ github.repository }}/review-service:latest - - #----------------------------------------------------------------------- - #--- Build and push registry-service Docker image - #----------------------------------------------------------------------- - build-registry-service: - needs: changes - if: needs.changes.outputs.registry_service == 'true' - runs-on: ubuntu-latest - steps: - - name: Checkout the submodule registry-service - uses: actions/checkout@v4 - with: - submodules: true - - - name: Set up JDK 21 - uses: actions/setup-java@v4 - with: - java-version: '21' - distribution: 'temurin' - cache: 'maven' - - - name: Run the registry-service tests - run: | - chmod +x ./submodules/registry-service/mvnw - ./submodules/registry-service/mvnw -f ./submodules/registry-service/pom.xml clean test - - - name: Login to GitHub Container Registry - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Build and push registry-service Docker image - uses: docker/build-push-action@v6 - with: - context: ./submodules/registry-service - push: true - tags: ghcr.io/${{ github.repository }}/registry-service:latest - - #----------------------------------------------------------------------- - #--- Build and push api-gateway Docker image - #----------------------------------------------------------------------- - build-api-gateway: - needs: changes - if: needs.changes.outputs.api_gateway == 'true' - runs-on: ubuntu-latest - steps: - - name: Checkout the submodule api-gateway - uses: actions/checkout@v4 - with: - submodules: true - - - name: Set up JDK 21 - uses: actions/setup-java@v4 - with: - java-version: '21' - distribution: 'temurin' - cache: 'maven' - - - name: Run the api-gateway tests - run: | - chmod +x ./submodules/api-gateway/mvnw - ./submodules/api-gateway/mvnw -f ./submodules/api-gateway/pom.xml clean test - - - name: Login to GitHub Container Registry - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Build and push api-gateway Docker image - uses: docker/build-push-action@v6 - with: - context: ./submodules/api-gateway - push: true - tags: ghcr.io/${{ github.repository }}/api-gateway:latest + tags: | + ghcr.io/${{ env.REPO_LC }}/${{ matrix.service }}:${{ env.IMAGE_TAG }} + ghcr.io/${{ env.REPO_LC }}/${{ matrix.service }}:latest + cache-from: type=registry,ref=ghcr.io/${{ env.REPO_LC }}/${{ matrix.service }}:buildcache + cache-to: type=registry,ref=ghcr.io/${{ env.REPO_LC }}/${{ matrix.service }}:buildcache,mode=max #----------------------------------------------------------------------- #--- Build and push mflibrary-frontend Docker image #----------------------------------------------------------------------- build-mflibrary-frontend: - needs: changes - if: needs.changes.outputs.frontend == 'true' + needs: validate-branch runs-on: ubuntu-latest + env: + IMAGE_TAG: ${{ github.sha }} + REPO_NAME: ${{ github.repository }} + steps: - - uses: actions/checkout@v4 + - name: Check out repository + uses: actions/checkout@v4 with: submodules: true @@ -275,22 +113,42 @@ jobs: - name: Install dependencies run: npm ci - working-directory: ./mflibrary-frontend + working-directory: ./submodules/mflibrary-frontend + + - name: Install Chrome + run: sudo apt-get update && sudo apt-get install -y google-chrome-stable - name: Run frontend tests - run: npm test -- --watch=false --browsers=ChromeHeadless - working-directory: ./mflibrary-frontend + run: npx ng test --watch=false --browsers=ChromeHeadless + working-directory: ./submodules/mflibrary-frontend - - name: Login to GitHub Container Registry + # GitHub Container Registry enforces all repository paths to be lowercase. + - name: Set lowercase repo name + run: echo "REPO_LC=${REPO_NAME,,}" >> $GITHUB_ENV + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + with: + install: true + driver: docker-container + + - name: Log in to GitHub Container Registry uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Build and push mflibrary-frontend Docker image - uses: docker/build-push-action@v6 + - name: Build and Push mflibrary-frontend Docker Image + uses: docker/build-push-action@v5 with: - context: ./mflibrary-frontend + context: ./submodules/mflibrary-frontend push: true - tags: ghcr.io/${{ github.repository }}/mflibrary-frontend:latest + file: ./submodules/mflibrary-frontend/Dockerfile + tags: | + ghcr.io/${{ env.REPO_LC }}/mflibrary-frontend:latest + ghcr.io/${{ env.REPO_LC }}/mflibrary-frontend:${{ env.IMAGE_TAG }} + # Use Docker build cache stored in GitHub Container Registry to speed up builds. + # 'cache-from' pulls existing cache layers; 'cache-to' pushes new layers for future + cache-from: type=registry,ref=ghcr.io/${{ env.REPO_LC }}/mflibrary-frontend:buildcache + cache-to: type=registry,ref=ghcr.io/${{ env.REPO_LC }}/mflibrary-frontend:buildcache,mode=max diff --git a/.github/workflows/push_pr_to_dev.yml b/.github/workflows/push_pr_to_dev.yml index 6073c72..10e4bc0 100644 --- a/.github/workflows/push_pr_to_dev.yml +++ b/.github/workflows/push_pr_to_dev.yml @@ -1,5 +1,11 @@ # Execute on every push or PR to dev + name: Push or PR to dev + +# This pipeline runs everytime there is a PR or push on dev. +# Because the changes on the submodules are track on their own GitHub project, +# I intentionally don't listen to the changes of each submodule in order to trigger this pipeline. + on: push: branches: @@ -7,154 +13,19 @@ on: pull_request: branches: - dev -jobs: - #----------------------------------------------------------------------- - #--- Detect the changes - #----------------------------------------------------------------------- - changes: - runs-on: ubuntu-latest - steps: - - name: Checkout the main repository - uses: actions/checkout@v4 - with: - submodules: true - - - name: Detect changes - id: filter - uses: dorny/paths-filter@v3 - with: - filters: | - user: - - 'submodules/user-service/**' - book: - - 'submodules/book-service/**' - review: - - 'submodules/review-service/**' - api_gateway: - - 'submodules/api-gateway/**' - registry_service: - - 'submodules/registry-service/**' - frontend: - - 'mflibrary-frontend/**' - outputs: - user: ${{ steps.filter.outputs.user }} - book: ${{ steps.filter.outputs.book }} - review: ${{ steps.filter.outputs.review }} - api_gateway: ${{ steps.filter.outputs.api_gateway }} - registry_service: ${{ steps.filter.outputs.registry_service }} - frontend: ${{ steps.filter.outputs.frontend }} - - #----------------------------------------------------------------------- - #--- Test user-service - #----------------------------------------------------------------------- - test-user-service: - needs: changes - if: needs.changes.outputs.user == 'true' - runs-on: ubuntu-latest - - steps: - - name: Checkout the submodule user-service - uses: actions/checkout@v4 - with: - submodules: true - - - name: Set up JDK 21 - uses: actions/setup-java@v4 - with: - java-version: '21' - distribution: 'temurin' - cache: 'maven' - - - name: Run the user-service tests - run: | - chmod +x ./submodules/user-service/mvnw - ./submodules/user-service/mvnw -f ./submodules/user-service/pom.xml clean test - - #----------------------------------------------------------------------- - #--- Test book-service - #----------------------------------------------------------------------- - test-book-service: - needs: changes - if: needs.changes.outputs.book == 'true' - runs-on: ubuntu-latest - - steps: - - name: Checkout the submodule book-service - uses: actions/checkout@v4 - with: - submodules: true - - - name: Set up JDK 21 - uses: actions/setup-java@v4 - with: - java-version: '21' - distribution: 'temurin' - cache: 'maven' - - - name: Run the book-service tests - run: | - chmod +x ./submodules/book-service/mvnw - ./submodules/book-service/mvnw -f ./submodules/book-service/pom.xml clean test - - #----------------------------------------------------------------------- - #--- Test review-service - #----------------------------------------------------------------------- - test-review-service: - needs: changes - if: needs.changes.outputs.review == 'true' - runs-on: ubuntu-latest - steps: - - name: Checkout the submodule review-service - uses: actions/checkout@v4 - with: - submodules: true - - - name: Set up JDK 21 - uses: actions/setup-java@v4 - with: - java-version: '21' - distribution: 'temurin' - cache: 'maven' - - - name: Run the review-service tests - run: | - chmod +x ./submodules/review-service/mvnw - ./submodules/review-service/mvnw -f ./submodules/review-service/pom.xml clean test +jobs: #----------------------------------------------------------------------- - #--- Test registry-service + #--- Test backend services #----------------------------------------------------------------------- - test-registry-service: - needs: changes - if: needs.changes.outputs.registry_service == 'true' + test-backend-services: runs-on: ubuntu-latest - steps: - - name: Checkout the submodule registry-service - uses: actions/checkout@v4 - with: - submodules: true + strategy: + matrix: + service: [ api-gateway, registry-service, user-service, book-service, review-service ] - - name: Set up JDK 21 - uses: actions/setup-java@v4 - with: - java-version: '21' - distribution: 'temurin' - cache: 'maven' - - - name: Run the registry-service tests - run: | - chmod +x ./submodules/registry-service/mvnw - ./submodules/registry-service/mvnw -f ./submodules/registry-service/pom.xml clean test - - #----------------------------------------------------------------------- - #--- Test api-gateway - #----------------------------------------------------------------------- - test-api-gateway: - needs: changes - if: needs.changes.outputs.api_gateway == 'true' - runs-on: ubuntu-latest steps: - - name: Checkout the submodule api-gateway + - name: Checkout repository uses: actions/checkout@v4 with: submodules: true @@ -166,20 +37,19 @@ jobs: distribution: 'temurin' cache: 'maven' - - name: Run the api-gateway tests + - name: Run tests run: | - chmod +x ./submodules/api-gateway/mvnw - ./submodules/api-gateway/mvnw -f ./submodules/api-gateway/pom.xml clean test + chmod +x ./submodules/${{ matrix.service }}/mvnw + ./submodules/${{ matrix.service }}/mvnw -f ./submodules/${{ matrix.service }}/pom.xml clean test #----------------------------------------------------------------------- #--- Test mflibrary-frontend #----------------------------------------------------------------------- test-mflibrary-frontend: - needs: changes - if: needs.changes.outputs.frontend == 'true' runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - name: Check out repository + uses: actions/checkout@v4 with: submodules: true @@ -190,8 +60,11 @@ jobs: - name: Install dependencies run: npm ci - working-directory: ./mflibrary-frontend + working-directory: ./submodules/mflibrary-frontend + + - name: Install Chrome + run: sudo apt-get update && sudo apt-get install -y google-chrome-stable - name: Run frontend tests - run: npm test -- --watch=false --browsers=ChromeHeadless - working-directory: ./mflibrary-frontend + run: npx ng test --watch=false --browsers=ChromeHeadless + working-directory: ./submodules/mflibrary-frontend diff --git a/submodules/api-gateway b/submodules/api-gateway index fe213db..dd6543f 160000 --- a/submodules/api-gateway +++ b/submodules/api-gateway @@ -1 +1 @@ -Subproject commit fe213dbe355255874e38a420b5aca93f31483283 +Subproject commit dd6543f8e8b706037102679acff7b67a37c4ad08 diff --git a/submodules/book-service b/submodules/book-service index 22ba893..4bb1336 160000 --- a/submodules/book-service +++ b/submodules/book-service @@ -1 +1 @@ -Subproject commit 22ba893ee8f349bd0759b126a564757735372b4f +Subproject commit 4bb1336a77b5d6b47ba7c9e513b778fa658407b2 diff --git a/submodules/registry-service b/submodules/registry-service index fa16f06..6b07445 160000 --- a/submodules/registry-service +++ b/submodules/registry-service @@ -1 +1 @@ -Subproject commit fa16f060c8487b512944e6786f6414a49ffa1fed +Subproject commit 6b07445a36d37204af65ca9bb5d1ddaee3eebad0 diff --git a/submodules/review-service b/submodules/review-service index 072eab4..72c82d9 160000 --- a/submodules/review-service +++ b/submodules/review-service @@ -1 +1 @@ -Subproject commit 072eab45ab39366757486eb3edb88b6a5a6f1ab9 +Subproject commit 72c82d94d65819fdf73500c50350101b3b0724eb diff --git a/submodules/user-service b/submodules/user-service index 85d691e..507007b 160000 --- a/submodules/user-service +++ b/submodules/user-service @@ -1 +1 @@ -Subproject commit 85d691e01a07064e40ca7b641b779a5c173f472a +Subproject commit 507007bb15bf23d2acf9ff5df4bfbee4475af218