Fix docker build tests (#1005)

* build(docker): skip test during docker build

* build(gha): do test directly on GHA instead of docker build

* build(gha): publish test results

* build(gha): publish docker build to personal docker hub and GH registry
This commit is contained in:
Alexander Puzynia
2025-08-27 20:56:06 -07:00
committed by GitHub
parent 09bc2f6e9e
commit c18692ae13
2 changed files with 55 additions and 6 deletions

View File

@@ -12,6 +12,8 @@ jobs:
permissions:
contents: write
packages: write
issues: read
checks: write
pull-requests: write
steps:
@@ -39,6 +41,52 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# Set up Java for backend tests
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
# Run backend tests with testcontainers
- name: Run Backend Tests
id: backend_tests
working-directory: ./booklore-api
run: |
echo "Running backend tests with testcontainers..."
./gradlew test
continue-on-error: true
# Publish test results
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: |
booklore-api/build/test-results/**/*.xml
check_name: Backend Test Results
comment_title: Backend Test Results
report_individual_runs: true
report_suite_logs: 'any'
# Upload test reports as artifacts
- name: Upload Test Reports
uses: actions/upload-artifact@v4
if: always()
with:
name: test-reports
path: |
booklore-api/build/reports/tests/
booklore-api/build/test-results/
retention-days: 30
# Fail the workflow if tests failed
- name: Check Test Results
if: steps.backend_tests.outcome == 'failure'
run: |
echo "❌ Backend tests failed! Check the test results above."
exit 1
- name: Get Latest Master Version
id: get_version
run: |
@@ -119,8 +167,8 @@ jobs:
docker buildx build \
--platform linux/amd64,linux/arm64 \
--build-arg APP_VERSION=${{ env.image_tag }} \
--tag booklore/booklore:${{ env.image_tag }} \
--tag ghcr.io/booklore-app/booklore:${{ env.image_tag }} \
--tag ${{ secrets.DOCKER_USERNAME }}/booklore:${{ env.image_tag }} \
--tag ghcr.io/${{ github.actor }}/booklore:${{ env.image_tag }} \
--push .
- name: Push Latest Tag (Only for Master)
@@ -129,8 +177,8 @@ jobs:
docker buildx build \
--platform linux/amd64,linux/arm64 \
--build-arg APP_VERSION=${{ env.new_tag }} \
--tag booklore/booklore:latest \
--tag ghcr.io/booklore-app/booklore:latest \
--tag ${{ secrets.DOCKER_USERNAME }}/booklore:latest \
--tag ghcr.io/${{ github.actor }}/booklore:latest \
--push .
- name: Create Git Tag (Only for Master)
@@ -151,6 +199,7 @@ jobs:
- name: Notify Discord of New Release
if: github.ref == 'refs/heads/master'
continue-on-error: true
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -193,4 +242,4 @@ jobs:
echo "$payload"
echo "======================="
curl -H "Content-Type: application/json" -d "$payload" "$DISCORD_WEBHOOK_URL"
curl -H "Content-Type: application/json" -d "$payload" "$DISCORD_WEBHOOK_URL"

View File

@@ -22,7 +22,7 @@ ARG APP_VERSION
RUN apk add --no-cache yq && \
yq eval '.app.version = strenv(APP_VERSION)' -i /springboot-app/src/main/resources/application.yaml
RUN gradle clean build
RUN gradle clean build -x test
# Stage 3: Final image
FROM eclipse-temurin:21-jre-alpine