Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
297 changes: 297 additions & 0 deletions .github/workflows/pr_to_master.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,297 @@
# Execute only if it's a PR which comes from dev
name: PR to master
on:
pull_request:
branches:
- master # I allow only PR from dev -> master

jobs:
#-----------------------------------------------------------------------
#--- Validate the PR's branch
#-----------------------------------------------------------------------
validate-branch:
runs-on: ubuntu-latest
steps:
- name: Enforce PRs to master must come from dev
run: |
if [[ "${{ github.head_ref }}" != "dev" ]]; then
echo "❌ PRs to master must come from dev!"
exit 1
else
echo "✅ PR from dev to master authorized."
fi

#-----------------------------------------------------------------------
#--- Detect the changes
#-----------------------------------------------------------------------
changes:
runs-on: ubuntu-latest
needs: validate-branch
if: success()
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 }}

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:
- 'services/user-service/**'
book:
- 'services/book-service/**'
review:
- 'services/review-service/**'
api_gateway:
- 'services/api-gateway/**'
registry_service:
- 'services/registry-service/**'
frontend:
- 'mflibrary-frontend/**'

#-----------------------------------------------------------------------
#--- Build and push user-service Docker image
#-----------------------------------------------------------------------
build-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

- 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 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

#-----------------------------------------------------------------------
#--- 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
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

- 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 book-service Docker image
uses: docker/build-push-action@v6
with:
context: ./submodules/book-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

#-----------------------------------------------------------------------
#--- Build and push mflibrary-frontend Docker image
#-----------------------------------------------------------------------
build-mflibrary-frontend:
needs: changes
if: needs.changes.outputs.frontend == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Install dependencies
run: npm ci
working-directory: ./mflibrary-frontend

- name: Run frontend tests
run: npm test -- --watch=false --browsers=ChromeHeadless
working-directory: ./mflibrary-frontend

- 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 mflibrary-frontend Docker image
uses: docker/build-push-action@v6
with:
context: ./mflibrary-frontend
push: true
tags: ghcr.io/${{ github.repository }}/mflibrary-frontend:latest
Loading