[2024/25] Refactor Part 1 #236
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: "Build and Test" | |
on: | |
push: | |
branches: | |
- "master" | |
jobs: | |
build-natively-with-gradle: | |
name: "Build natively with Gradle" | |
runs-on: "ubuntu-latest" | |
steps: | |
- name: "Check out source code" | |
uses: "actions/checkout@v4.2.2" | |
- name: "Set up JDK 21" | |
uses: "actions/setup-java@v4.5.0" | |
with: | |
java-version: "21" | |
distribution: "corretto" | |
- name: "Validate Gradle wrapper" | |
uses: "gradle/actions/wrapper-validation@v3.5.0" | |
- name: "Set up Gradle" | |
uses: "gradle/actions/setup-gradle@v3.5.0" | |
- name: "Build with Gradle" | |
run: "gradle build" | |
- name: "Upload 'AdventOfCode.jar' artifact" | |
uses: "actions/upload-artifact@v4.4.3" | |
with: | |
name: "AdventOfCode.jar" | |
path: "build/libs/AdventOfCode.jar" | |
if-no-files-found: "error" | |
- name: "Upload Ktlint reports artifact" | |
if: "${{ always() }}" | |
uses: "actions/upload-artifact@v4.4.3" | |
with: | |
name: "Ktlint Reports" | |
path: "build/reports/ktlint" | |
if-no-files-found: "error" | |
- name: "Upload test summary artifact" | |
if: "${{ always() }}" | |
uses: "actions/upload-artifact@v4.4.3" | |
with: | |
name: "Test Summary" | |
path: "build/reports/tests/test" | |
if-no-files-found: "error" | |
- name: "Upload coverage report artifact" | |
if: "${{ always() }}" | |
uses: "actions/upload-artifact@v4.4.3" | |
with: | |
name: "Coverage Report" | |
path: "build/reports/jacoco/test" | |
if-no-files-found: "error" | |
run-jar-natively: | |
name: "Run JAR archive natively" | |
needs: "build-natively-with-gradle" | |
runs-on: "ubuntu-latest" | |
steps: | |
- name: "Download 'AdventOfCode.jar' artifact" | |
uses: "actions/download-artifact@v4.1.8" | |
with: | |
name: "AdventOfCode.jar" | |
path: "." | |
- name: "Set up JDK 21" | |
uses: "actions/setup-java@v4.5.0" | |
with: | |
java-version: "21" | |
distribution: "corretto" | |
- name: "Run JAR archive" | |
run: "java -jar AdventOfCode.jar 2024" | |
build-docker-image: | |
name: "Build Docker Image" | |
runs-on: "ubuntu-latest" | |
steps: | |
- name: "Check out source code" | |
uses: "actions/checkout@v4.2.2" | |
- name: "Lint Dockerfile" | |
uses: "luke142367/Docker-Lint-Action@v1.1.1" | |
env: | |
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" | |
- name: "Set up Docker Buildx" | |
uses: "docker/setup-buildx-action@v3.7.1" | |
- name: "Build Docker Image" | |
uses: "docker/build-push-action@v6.9.0" | |
with: | |
tags: "pfolta/advent-of-code:latest" | |
outputs: "type=docker, dest=AdventOfCode.tar" | |
push: false | |
- name: "Upload Docker image artifact" | |
uses: "actions/upload-artifact@v4.4.3" | |
with: | |
name: "Docker Image" | |
path: "AdventOfCode.tar" | |
if-no-files-found: "error" | |
run-docker-image: | |
name: "Run Docker Image" | |
needs: "build-docker-image" | |
runs-on: "ubuntu-latest" | |
steps: | |
- name: "Download Docker image artifact" | |
uses: "actions/download-artifact@v4.1.8" | |
with: | |
name: "Docker Image" | |
path: "." | |
- name: "Load Docker image" | |
run: | | |
docker load --input AdventOfCode.tar | |
docker image ls pfolta/advent-of-code | |
- name: "Run Docker image" | |
uses: "addnab/docker-run-action@v3" | |
with: | |
image: "pfolta/advent-of-code:latest" | |
run: "java -jar AdventOfCode.jar 2024" | |
publish-coverage-data: | |
name: "Publish coverage data to Codecov" | |
needs: ["run-jar-natively", "run-docker-image"] | |
runs-on: "ubuntu-latest" | |
steps: | |
- name: "Check out source code" | |
uses: "actions/checkout@v4.2.2" | |
- name: "Download coverage report artifact" | |
uses: "actions/download-artifact@v4.1.8" | |
with: | |
name: "Coverage Report" | |
path: "build/reports/jacoco/test" | |
- name: "Publish coverage data to Codecov" | |
uses: "codecov/codecov-action@v5.0.4" | |
with: | |
token: "${{ secrets.CODECOV_TOKEN }}" |