chore: add block 4 #4
This file contains hidden or 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: Build, Test and Publish Container | |
| on: | |
| pull_request: | |
| branches: | |
| - main | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| packages: write | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: erhardtconsulting/database-development-app | |
| jobs: | |
| maven: | |
| name: Maven build and root tests | |
| runs-on: ubuntu-24.04 | |
| outputs: | |
| app-version: ${{ steps.project-version.outputs.version }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Java 24 | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: temurin | |
| java-version: "24" | |
| cache: maven | |
| - name: Read project version | |
| id: project-version | |
| run: echo "version=$(./mvnw -q -DforceStdout help:evaluate -Dexpression=project.version)" >> "$GITHUB_OUTPUT" | |
| - name: Run fast tests | |
| run: ./mvnw -B test | |
| - name: Run Testcontainers integration tests | |
| run: ./mvnw -B -Ptestcontainers test | |
| - name: Build application package | |
| run: ./mvnw -B package -DskipTests | |
| checkpoint-states: | |
| name: Checkpoint state / ${{ matrix.state }} | |
| runs-on: ubuntu-24.04 | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| state: | |
| - block-2-start | |
| - block-2-complete | |
| - block-3-start | |
| - block-3-complete | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Java 24 | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: temurin | |
| java-version: "24" | |
| cache: maven | |
| - name: Test checkpoint state | |
| run: ./course-state test "${{ matrix.state }}" | |
| container: | |
| name: Container build and publish | |
| runs-on: ubuntu-24.04 | |
| needs: | |
| - maven | |
| - checkpoint-states | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to GitHub Container Registry | |
| if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Prepare image tags | |
| id: image-tags | |
| run: | | |
| SHORT_SHA="${GITHUB_SHA::7}" | |
| VERSION="${{ needs.maven.outputs.app-version }}" | |
| IMAGE="${REGISTRY}/${IMAGE_NAME}" | |
| { | |
| echo "tags<<EOF" | |
| echo "${IMAGE}:${VERSION}-${SHORT_SHA}" | |
| if [ "${GITHUB_EVENT_NAME}" = "push" ] && [ "${GITHUB_REF}" = "refs/heads/main" ]; then | |
| echo "${IMAGE}:latest" | |
| fi | |
| echo "EOF" | |
| } >> "$GITHUB_OUTPUT" | |
| - name: Build container image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: Dockerfile | |
| platforms: linux/amd64 | |
| push: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} | |
| tags: ${{ steps.image-tags.outputs.tags }} |