* fix: unable to delete user account. Issue #402 * chore: fix checkstyle and import orders * ci: fix sonar project key * chore: improve test condition and test cases
157 lines
5.0 KiB
YAML
157 lines
5.0 KiB
YAML
name: PR Server
|
|
|
|
on:
|
|
pull_request:
|
|
paths:
|
|
- 'server/**'
|
|
|
|
concurrency:
|
|
group: server-${{ github.event.number }}
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
java-code-checks:
|
|
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 SonarQube Cloud packages
|
|
uses: actions/cache@v4.2.3
|
|
with:
|
|
path: ~/.sonar/cache
|
|
key: ${{ runner.os }}-sonar
|
|
restore-keys: ${{ runner.os }}-sonar
|
|
|
|
- name: Cache Maven packages
|
|
uses: actions/cache@v4.2.3
|
|
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: Unit and Integration tests
|
|
run: |
|
|
cd server
|
|
./mvnw --no-transfer-progress clean verify -P tests --file pom.xml
|
|
|
|
- name: Sonar Analysis
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_SERVER }}
|
|
run: |
|
|
cd server
|
|
./mvnw -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=ricardo-campos-org_react-typescript-todolist_server -Dsonar.coverage.jacoco.xmlReportPaths=target/coverage-reports/merged-test-report/jacoco.xml -Dsonar.exclusions='**/config/**,**/entity/**,**/exception/**,**/filter/**,**/**Builder*,**/RestExceptionEndpoint.*,**/JavaApiApiApplication.*'
|
|
|
|
java-docker-build:
|
|
name: Build Server 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: Get current date
|
|
id: date
|
|
run: echo "date=$(date +'%Y-%m-%d-%H%M%S')" >> $GITHUB_OUTPUT
|
|
|
|
- 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:candidate
|
|
build-args: |
|
|
BUILD=v${{ github.event.number }}-${{ steps.date.outputs.date }}
|
|
SOURCE_PR=v${{ github.event.number }}-${{ github.run_id }}-${{ steps.date.outputs.date }}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
|
|
java-stage-deployments:
|
|
name: Deploy Changes to Stage
|
|
runs-on: ubuntu-latest
|
|
needs: java-docker-build
|
|
if: github.event.pull_request.user.login == 'rmcampos' && github.event_name == 'pull_request'
|
|
env:
|
|
DEPLOY_DOMAIN: ${{ vars.DEPLOY_DOMAIN }}
|
|
API_KEY: ${{ secrets.DOKPLOY_API_KEY }}
|
|
SERVER_APPID: ${{ secrets.STAGE_API_CLIENT_ID }}
|
|
CLIENT_APPID: ${{ secrets.STAGE_WEB_CLIENT_ID }}
|
|
steps:
|
|
- name: Checking cURL version
|
|
run: curl --version
|
|
|
|
- name: Pre-deployment check
|
|
run: |
|
|
if ! curl -s -f "${{ vars.API_STAGE_URL }}/actuator/health" > /dev/null; then
|
|
echo "Stage environment is not healthy"
|
|
else
|
|
echo "Stage environment is healthy"
|
|
fi
|
|
|
|
- name: Trigger Deployment
|
|
uses: nick-fields/retry@v3.0.2
|
|
with:
|
|
timeout_minutes: 2
|
|
max_attempts: 3
|
|
command: |
|
|
response=$(curl -X POST \
|
|
"${DEPLOY_DOMAIN}/api/application.deploy" \
|
|
--max-time 30 \
|
|
-H "accept: application/json" \
|
|
-H "x-api-key: ${API_KEY}" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"applicationId\":\"${SERVER_APPID}\"}" \
|
|
-w "\n%{http_code}" \
|
|
-s)
|
|
|
|
status_code=$(echo "$response" | tail -n1)
|
|
echo "Status code: $status_code"
|
|
|
|
if [ "$status_code" != "200" ]; then
|
|
body=$(echo "$response" | sed '$d')
|
|
|
|
echo "Deployment failed with status code $status_code"
|
|
echo -e "Response body: $body"
|
|
exit 1
|
|
else
|
|
echo "Deployment succeeded!"
|
|
fi
|
|
|
|
- name: Verifying post deployment
|
|
run: |
|
|
# Wait for deployment to complete
|
|
sleep 15
|
|
|
|
if ! curl -s -f "${{ vars.API_STAGE_URL }}/actuator/health" > /dev/null; then
|
|
echo "Stage environment is not healthy"
|
|
exit 1
|
|
else
|
|
echo "Stage environment is healthy"
|
|
fi
|