testing new ci/cd
CI/CD / Backend Unit Tests (push) Successful in 1m48s
CI/CD / Deploy (push) Has been skipped
CI/CD / Backend Unit Tests (pull_request) Successful in 1m45s
CI/CD / Deploy (pull_request) Has been skipped

This commit is contained in:
2026-06-10 18:03:56 +02:00
parent 28bd6a8cbc
commit b53805ee3f
5 changed files with 121 additions and 14 deletions
+90 -13
View File
@@ -1,29 +1,106 @@
name: CI
name: CI/CD
on:
push:
branches: [dev]
branches:
- dev
- main
pull_request:
branches: [main]
branches:
- main
env:
JAVA_VERSION: "21"
jobs:
backend-tests:
backend-unit-tests:
name: Backend Unit Tests
runs-on: ubuntu-latest
defaults:
run:
working-directory: backend
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up JDK ${{ env.JAVA_VERSION }}
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
distribution: temurin
java-version: ${{ env.JAVA_VERSION }}
- name: Make Gradle wrapper executable
run: chmod +x ./gradlew
run: chmod +x gradlew
- name: Run tests
run: ./gradlew test --no-daemon
- name: Run unit tests
run: ./gradlew test
# TODO: CD logic — deploy after successful tests on merge to main
deploy:
name: Deploy
needs: backend-unit-tests
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up JDK ${{ env.JAVA_VERSION }}
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: ${{ env.JAVA_VERSION }}
- name: Build boot jar
working-directory: backend
run: |
chmod +x gradlew
./gradlew bootJar
- name: Stage jar for Docker
working-directory: backend
run: |
BOOT_JAR=$(find build/libs -name "*.jar" ! -name "*-plain.jar" | head -n 1)
cp "$BOOT_JAR" app.jar
- name: Login to Docker registry
run: |
echo "${{ secrets.REGISTRY_PASSWORD }}" | \
docker login git.${{ secrets.DOMAIN }} \
-u "${{ secrets.REGISTRY_USER }}" \
--password-stdin
- name: Build Docker image
run: |
docker build \
-t git.${{ secrets.DOMAIN }}/${{ secrets.REGISTRY_USER }}/etf-oglasi-server:latest \
backend/
- name: Push Docker image
run: |
docker push \
git.${{ secrets.DOMAIN }}/${{ secrets.REGISTRY_USER }}/etf-oglasi-server:latest
- name: Deploy to VPS
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/key
chmod 600 ~/.ssh/key
ssh-keyscan -H "${{ secrets.DEPLOY_HOST }}" >> ~/.ssh/known_hosts
# Write secrets to VPS (only if they've changed or first deploy)
ssh -i ~/.ssh/key "${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}" \
"mkdir -p ~/programs/etf-oglasi-server/config"
echo "${{ secrets.FIREBASE_CREDENTIALS }}" | \
ssh -i ~/.ssh/key "${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}" \
"cat > ~/programs/etf-oglasi-server/config/firebase.json"
ssh -i ~/.ssh/key "${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}" \
"cd ~/programs/etf-oglasi-server && docker compose pull && docker compose up -d"
+1
View File
@@ -35,6 +35,7 @@ backend/**/*temp.java
backend/src/main/resources/google-services.json
backend/src/main/resources/etf-oglasi-firebase.json
backend/src/main/resources/firebase.json
# Java / Eclipse / STS
.classpath
+5
View File
@@ -0,0 +1,5 @@
FROM eclipse-temurin:21-jre-jammy
WORKDIR /app
COPY app.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "/app/app.jar"]
@@ -17,7 +17,7 @@ public class FirebaseConfig {
@Bean
public FirebaseApp firebaseApp() throws IOException {
GoogleCredentials credentials = GoogleCredentials
.fromStream(new ClassPathResource("etf-oglasi-firebase.json").getInputStream())
.fromStream(new ClassPathResource("firebase.json").getInputStream())
.createScoped(List.of("https://www.googleapis.com/auth/firebase.messaging"));
FirebaseOptions options = FirebaseOptions.builder()
+24
View File
@@ -0,0 +1,24 @@
name: CI - full
on:
pull_request:
branches: [main]
jobs:
backend-test:
uses: ./.gitea/workflows/backend-test.yaml
frontend-build:
runs-on: ubuntu-latest
defaults:
run:
working-directory: frontend
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- name: Install dependencies
run: npm ci
- name: Build frontend
run: npx expo export --platform web