android tests #113
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: Spring Boot App API tests | |
on: | |
push: | |
branches: | |
- master | |
pull_request: | |
paths-ignore: | |
- 'README.md' | |
workflow_dispatch: | |
jobs: | |
run-tests: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Spring Boot app repository | |
uses: actions/checkout@v4 | |
with: | |
repository: aceton41k/spring-boot-app | |
ref: main | |
path: app | |
- name: Build Spring Boot Docker image | |
run: | | |
docker build -t spring-boot-app:latest ./app | |
- name: Create Docker network | |
run: docker network create my-network | |
- name: Run PostgreSQL container | |
run: | | |
docker run -d --name db \ | |
--network my-network \ | |
-e POSTGRES_USER=appuser \ | |
-e POSTGRES_PASSWORD=${{ secrets.DB_USER_PASSWORD }} \ | |
-e POSTGRES_DB=appdb \ | |
-p 5432:5432 \ | |
postgres:16.4-alpine | |
- name: Run Spring Boot app container | |
run: | | |
docker run -d -p 8080:8080 \ | |
--name spring-boot-app \ | |
--network my-network \ | |
--env SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/appdb \ | |
--env SPRING_DATASOURCE_USERNAME=appuser \ | |
--env SPRING_DATASOURCE_PASSWORD=${{ secrets.DB_USER_PASSWORD }} \ | |
--env SECURITY_JWT_SECRET_KEY=${{ secrets.SECURITY_JWT_SECRET_KEY }} \ | |
spring-boot-app:latest | |
- name: Wait for PostgreSQL to be ready | |
run: | | |
for i in {1..30}; do | |
if docker exec db pg_isready -U appuser; then | |
echo "PostgreSQL is ready!" | |
break | |
else | |
echo "Waiting for PostgreSQL..." | |
sleep 10 | |
fi | |
done | |
- name: Wait for Spring Boot app to be ready | |
run: | | |
for i in {1..30}; do | |
if curl -s http://localhost:8080/actuator/health | grep '"status":"UP"'; then | |
echo "Spring Boot app is ready!" | |
break | |
else | |
echo "Waiting for Spring Boot app..." | |
sleep 10 | |
fi | |
done | |
- name: Checkout API tests | |
uses: actions/checkout@v4 | |
with: | |
path: tests | |
- name: Set up JDK 22 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '22' | |
distribution: 'temurin' | |
- name: Compile test classes | |
run: | | |
cd tests | |
./gradlew compileTestJava | |
- name: Run tests | |
continue-on-error: true | |
run: | | |
cd tests | |
./gradlew test -Dapi.url=http://localhost:8080 -Ddb.url=jdbc:postgresql://localhost:5432/appdb -Ddb.password=${{ secrets.DB_USER_PASSWORD }} -Ddb.user=appuser --info | |
- name: Check if tests were run | |
id: check-test-results | |
run: | | |
if [ -d "./tests/build/allure-results" ] && [ "$(ls -A ./tests/build/allure-results)" ]; then | |
if ls ./tests/build/allure-results/*container.json 1> /dev/null 2>&1; then | |
echo "At least one *container.json file is present." | |
echo "tests_found=true" >> $GITHUB_ENV | |
else | |
echo "No *container.json file found." | |
echo "tests_found=false" >> $GITHUB_ENV | |
fi | |
else | |
echo "No test results found." | |
echo "tests_found=false" >> $GITHUB_ENV | |
fi | |
- name: Get Allure history | |
uses: actions/checkout@v4 | |
continue-on-error: true | |
with: | |
ref: gh-pages | |
path: gh-pages | |
- name: Build Allure report | |
uses: simple-elf/allure-report-action@v1.9 | |
with: | |
gh_pages: gh-pages | |
allure_results: './tests/build/allure-results' | |
allure_history: allure-history | |
- name: Deploy Allure report to GitHub Pages | |
if: env.tests_found == 'true' | |
uses: peaceiris/actions-gh-pages@v4 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_branch: gh-pages | |
publish_dir: allure-history |