184 lines
5.5 KiB
YAML
184 lines
5.5 KiB
YAML
name: PR
|
|
|
|
on:
|
|
pull_request:
|
|
|
|
concurrency:
|
|
group: ${{ github.event.number }}
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
# JOB to run change detection
|
|
changes:
|
|
name: Check changes
|
|
runs-on: ubuntu-latest
|
|
# Required permissions
|
|
permissions:
|
|
pull-requests: read
|
|
# Set job outputs to values from filter step
|
|
outputs:
|
|
server: ${{ steps.filter.outputs.server }}
|
|
client: ${{ steps.filter.outputs.client }}
|
|
steps:
|
|
# For pull requests it's not necessary to checkout the code
|
|
- uses: dorny/paths-filter@v3
|
|
id: filter
|
|
with:
|
|
filters: |
|
|
server:
|
|
- 'server/**'
|
|
client:
|
|
- 'client/**'
|
|
|
|
client-code-checks:
|
|
needs: changes
|
|
if: ${{ needs.changes.outputs.client == 'true' }}
|
|
name: Client Code Checks
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- uses: actions/setup-node@v4
|
|
name: Set up Node
|
|
with:
|
|
node-version: '20'
|
|
- name: Clean and Install
|
|
run: cd client && npm ci
|
|
- name: Build
|
|
run: cd client && npm run build
|
|
- name: Lint
|
|
run: cd client && npm run lint
|
|
- name: Unit tests
|
|
run: cd client && npm run test:coverage
|
|
- name: SonarCloud Scan
|
|
uses: SonarSource/sonarcloud-github-action@v3.1.0
|
|
with:
|
|
projectBaseDir: client
|
|
args: >
|
|
-Dsonar.organization=ricardo-campos-org
|
|
-Dsonar.projectKey=ricardo-campos-org_react-typescript-todolist
|
|
-Dsonar.javascript.lcov.reportPaths=coverage/lcov.info
|
|
-Dsonar.typescript.tsconfigPaths=tsconfig.json
|
|
-Dsonar.sources=src/
|
|
-Dsonar.exclusions=src/__test__/**
|
|
-Dsonar.tests=src/__test__/
|
|
-Dsonar.verbose=false
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
|
|
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
|
|
|
client-zip:
|
|
name: Build Client and Zip it
|
|
runs-on: ubuntu-latest
|
|
needs: client-code-checks
|
|
env:
|
|
VITE_BUILD: client:${{ github.event.number }}
|
|
VITE_BACKEND_SERVER: ${{ secrets.SERVER_ADDRESS }}/server
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- uses: actions/setup-node@v4
|
|
name: Set up Node
|
|
with:
|
|
node-version: '20'
|
|
- name: Clean and Install
|
|
run: cd client && npm ci --ignore-scripts --no-update-notifier --omit=dev
|
|
- name: Build
|
|
run: cd client && npm run build && rm -rf node_modules
|
|
- uses: vimtor/action-zip@v1.2
|
|
name: Zip it
|
|
with:
|
|
files: client/dist/
|
|
dest: client_${{ github.event.number }}.zip
|
|
- uses: actions/upload-artifact@v4
|
|
with:
|
|
name: client_${{ github.event.number }}.zip
|
|
path: client_${{ github.event.number }}.zip
|
|
retention-days: 10
|
|
overwrite: true
|
|
|
|
client-docker-build:
|
|
name: Build Client Docker image
|
|
runs-on: ubuntu-latest
|
|
needs: client-zip
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- uses: docker/setup-buildx-action@v3
|
|
name: Set up Docker Buildx
|
|
|
|
- uses: docker/login-action@v3
|
|
name: Login to GitHub Container Registry
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Build and push
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
push: true
|
|
context: ./client
|
|
tags: ghcr.io/ricardo-campos-org/react-typescript-todolist/client:${{ github.event.number }}
|
|
build-args: BUILD=${{ github.event.number }}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
|
|
java-code-checks:
|
|
needs: changes
|
|
if: ${{ needs.changes.outputs.server == 'true' }}
|
|
name: Server Code Checks
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
ref: ${{ github.event.pull_request.head.ref }}
|
|
|
|
- name: Set up JDK 17
|
|
uses: actions/setup-java@v4
|
|
with:
|
|
java-version: '17'
|
|
distribution: 'temurin'
|
|
cache: 'maven'
|
|
|
|
- name: Cache Maven packages
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: ~/.m2
|
|
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
|
|
restore-keys: ${{ runner.os }}-m2
|
|
|
|
- name: Build with Maven
|
|
run: cd server && ./mvnw --no-transfer-progress clean compile -DskipTests
|
|
|
|
- name: Google Check-Style
|
|
run: cd server && ./mvnw --no-transfer-progress checkstyle:checkstyle -Dskip.checkstyle=false
|
|
|
|
#- name: All Tests
|
|
# run: cd server && ./mvnw --no-transfer-progress clean verify -P tests --file pom.xml
|
|
|
|
java-docker-build:
|
|
name: Build Java Docker image
|
|
runs-on: ubuntu-latest
|
|
needs: java-code-checks
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- uses: docker/setup-buildx-action@v3
|
|
name: Set up Docker Buildx
|
|
|
|
- uses: docker/login-action@v3
|
|
name: Login to GitHub Container Registry
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Build and push
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
push: true
|
|
context: ./server
|
|
tags: ghcr.io/ricardo-campos-org/react-typescript-todolist/server:${{ github.event.number }}
|
|
build-args: BUILD=${{ github.event.number }}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|