Merge pull request #1 from daniellaera/feature/test-pr #141
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: Deploy Spring Boot App | |
on: | |
push: | |
branches: [ main ] | |
permissions: | |
contents: write | |
env: | |
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} | |
jobs: | |
deploy: | |
name: Deploy App | |
runs-on: ubuntu-latest | |
outputs: | |
backend: ${{ steps.filter.outputs.backend }} | |
frontend: ${{ steps.filter.outputs.frontend }} | |
steps: | |
- uses: actions/checkout@v4 # Checkout the code from the repository | |
- uses: dorny/paths-filter@v2 # Filter the paths that have been changed | |
id: filter | |
with: | |
filters: | | |
backend: | |
- 'backend/**' | |
frontend: | |
- 'frontend/**' | |
build-and-test-backend: | |
name: Build and Test Application (Backend) | |
runs-on: ubuntu-latest | |
needs: deploy | |
if: ${{ needs.deploy.outputs.backend == 'true' }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '21' | |
distribution: 'temurin' | |
cache: maven | |
- name: Build and Test Backend | |
working-directory: ./backend | |
run: mvn clean verify | |
- name: Upload JaCoCo Coverage Report (Backend) | |
uses: actions/upload-artifact@v4 | |
with: | |
name: jacoco-report-backend | |
path: | | |
backend/target/site/jacoco/jacoco.csv | |
backend/target/site/jacoco/jacoco.xml | |
backend/target/site/jacoco/index.html | |
- name: Generate JaCoCo Badge (Backend) | |
id: generate_badge_backend | |
uses: cicirello/jacoco-badge-generator@v2 | |
with: | |
jacoco-csv-file: backend/target/site/jacoco/jacoco.csv | |
badges-directory: .github/badges | |
generate-coverage-badge: true | |
coverage-badge-filename: jacoco.svg | |
generate-coverage-endpoint: true | |
coverage-endpoint-filename: jacoco.json | |
- name: Commit and push badges to badges branch (Backend) | |
if: ${{ github.event_name != 'pull_request' }} | |
run: | | |
git config --global user.name 'github-actions' | |
git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
# Create or switch to the badges branch | |
git checkout -B badges | |
# Ensure badges directory exists | |
mkdir -p badges | |
# Copy generated badge files | |
cp .github/badges/jacoco.svg badges/ | |
cp .github/badges/jacoco.json badges/ | |
# Stage and commit changes | |
git add badges/* | |
git commit -m "Update JaCoCo coverage badges" || echo "No changes to commit" | |
git push origin badges --force # Push to badges branch | |
deploy-backend: | |
name: Deploy Backend | |
runs-on: ubuntu-latest | |
needs: build-and-test-backend | |
if: ${{ needs.deploy.outputs.backend == 'true' }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Fly CLI | |
uses: superfly/flyctl-actions/setup-flyctl@master | |
- name: Deploy Spring Boot App | |
working-directory: ./backend | |
run: | | |
flyctl deploy --remote-only | |
deploy-frontend: | |
name: Deploy Frontend | |
runs-on: ubuntu-latest | |
needs: deploy | |
if: ${{ needs.deploy.outputs.frontend == 'true' }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Fly CLI | |
uses: superfly/flyctl-actions/setup-flyctl@master | |
- name: Deploy Angular App | |
working-directory: ./frontend | |
env: | |
FLY_API_TOKEN: ${{ secrets.FLY_API_FRONTEND_TOKEN }} | |
run: | | |
flyctl deploy --remote-only |