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:
@@ -12,6 +12,8 @@ jobs:
|
|||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: write
|
||||||
packages: write
|
packages: write
|
||||||
|
issues: read
|
||||||
|
checks: write
|
||||||
pull-requests: write
|
pull-requests: write
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
@@ -39,6 +41,52 @@ jobs:
|
|||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
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
|
- name: Get Latest Master Version
|
||||||
id: get_version
|
id: get_version
|
||||||
run: |
|
run: |
|
||||||
@@ -119,8 +167,8 @@ jobs:
|
|||||||
docker buildx build \
|
docker buildx build \
|
||||||
--platform linux/amd64,linux/arm64 \
|
--platform linux/amd64,linux/arm64 \
|
||||||
--build-arg APP_VERSION=${{ env.image_tag }} \
|
--build-arg APP_VERSION=${{ env.image_tag }} \
|
||||||
--tag booklore/booklore:${{ env.image_tag }} \
|
--tag ${{ secrets.DOCKER_USERNAME }}/booklore:${{ env.image_tag }} \
|
||||||
--tag ghcr.io/booklore-app/booklore:${{ env.image_tag }} \
|
--tag ghcr.io/${{ github.actor }}/booklore:${{ env.image_tag }} \
|
||||||
--push .
|
--push .
|
||||||
|
|
||||||
- name: Push Latest Tag (Only for Master)
|
- name: Push Latest Tag (Only for Master)
|
||||||
@@ -129,8 +177,8 @@ jobs:
|
|||||||
docker buildx build \
|
docker buildx build \
|
||||||
--platform linux/amd64,linux/arm64 \
|
--platform linux/amd64,linux/arm64 \
|
||||||
--build-arg APP_VERSION=${{ env.new_tag }} \
|
--build-arg APP_VERSION=${{ env.new_tag }} \
|
||||||
--tag booklore/booklore:latest \
|
--tag ${{ secrets.DOCKER_USERNAME }}/booklore:latest \
|
||||||
--tag ghcr.io/booklore-app/booklore:latest \
|
--tag ghcr.io/${{ github.actor }}/booklore:latest \
|
||||||
--push .
|
--push .
|
||||||
|
|
||||||
- name: Create Git Tag (Only for Master)
|
- name: Create Git Tag (Only for Master)
|
||||||
@@ -151,6 +199,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Notify Discord of New Release
|
- name: Notify Discord of New Release
|
||||||
if: github.ref == 'refs/heads/master'
|
if: github.ref == 'refs/heads/master'
|
||||||
|
continue-on-error: true
|
||||||
shell: bash
|
shell: bash
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|||||||
+1
-1
@@ -22,7 +22,7 @@ ARG APP_VERSION
|
|||||||
RUN apk add --no-cache yq && \
|
RUN apk add --no-cache yq && \
|
||||||
yq eval '.app.version = strenv(APP_VERSION)' -i /springboot-app/src/main/resources/application.yaml
|
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
|
# Stage 3: Final image
|
||||||
FROM eclipse-temurin:21-jre-alpine
|
FROM eclipse-temurin:21-jre-alpine
|
||||||
|
|||||||
Reference in New Issue
Block a user