build: Better use of Micronaut Gradle plugin #43
Workflow file for this run
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: CI | |
on: | |
push: | |
branches: [ main ] | |
pull_request: | |
branches: [ main ] | |
env: | |
GRADLE_OPTS: "-Dorg.gradle.console=plain -Dorg.gradle.caching=true -Dkotlin.caching.enabled=true" | |
jobs: | |
compile: | |
name: Build / compile | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Gradle and Java | |
uses: ./.github/gradle-action | |
with: | |
# Allows this job to write to the cache every time it runs | |
gradle-cache-read-only: false | |
- name: Start Gradle Daemon | |
run: gradle --info | |
- run: gradle testClasses | |
- name: Gradle Tasks Summary | |
run: cat build/reports/build-times.md >> $GITHUB_STEP_SUMMARY | |
detekt: | |
name: Code Analysis / detekt | |
runs-on: ubuntu-latest | |
needs: | |
- compile | |
steps: | |
- uses: actions/checkout@v4 | |
- name: detekt report | |
uses: natiginfo/[email protected] | |
with: | |
args: | | |
--report md:build/reports/detekt/detekt.md | |
- name: Detekt Summary | |
run: cat build/reports/detekt/detekt.md >> $GITHUB_STEP_SUMMARY | |
ktlint: | |
name: Code Analysis / ktlint | |
runs-on: ubuntu-latest | |
needs: | |
- compile | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: nbadal/action-ktlint-setup@v1 | |
- name: ktlint version | |
run: ktlint --version | |
- name: run ktlin | |
run: ktlint --relative >> $GITHUB_STEP_SUMMARY | |
test: | |
name: Tests / test | |
runs-on: ubuntu-latest | |
needs: | |
- detekt | |
- ktlint | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Gradle and Java | |
uses: ./.github/gradle-action | |
- name: Run tests | |
run: gradle koverHtmlReport -x accessibilityTest | |
- name: Gradle Tasks Summary | |
run: cat build/reports/build-times.md >> $GITHUB_STEP_SUMMARY | |
- name: Setup Pandoc | |
uses: r-lib/actions/setup-pandoc@v2 | |
- name: Output Kover summary | |
# Adapted from https://github.com/Kotlin/kotlinx-kover/issues/419#issuecomment-1632572084 | |
run: | | |
pandoc build/reports/kover/html/index.html -f html -t gfm | \ | |
sed -n '/# project-starter: Overall Coverage Summary/,/<\/div>/p' | \ | |
grep -v "</div>" >> $GITHUB_STEP_SUMMARY | |
- name: Test Summary Report | |
uses: phoenix-actions/test-reporting@v12 | |
if: always() | |
with: | |
name: Kotest Report | |
path: "build/test-results/test/TEST-*.xml" | |
reporter: java-junit | |
output-to: "step-summary" | |
only-summary: "true" | |
build-docker: | |
name: Package / Docker / build | |
runs-on: ubuntu-latest | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
needs: | |
- test | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Gradle and Java | |
uses: ./.github/gradle-action | |
- name: Docker / Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Docker / Set up Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Docker / Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Docker / Create Image | |
run: gradle dockerBuild | |
- name: Gradle Tasks Summary | |
run: cat build/reports/build-times.md >> $GITHUB_STEP_SUMMARY | |
- name: Docker / List images | |
run: docker images | |
- name: Docker / Get image name | |
id: dockerImageName | |
run: echo "dockerImageName=$(gradle -q dockerImageName)" >> "$GITHUB_OUTPUT" | |
- name: Docker / Get image metadata | |
id: dockerImageMetadata | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ steps.dockerImageName.outputs.dockerImageName }} | |
- name: Docker / Analyse image | |
uses: docker/scout-action@v1 | |
with: | |
command: quickview | |
image: ${{ steps.dockerImageName.outputs.dockerImageName }} | |
write-comment: false | |
summary: true | |
check-if-prod: | |
if: ${{ github.ref == 'refs/heads/main' }} | |
name: Check if prod | |
runs-on: ubuntu-latest | |
needs: | |
- test | |
steps: | |
- run: echo "This is a push to main branch. Following with release and deploy" | |
create-release: | |
name: Creates a GitHub Release | |
runs-on: ubuntu-latest | |
needs: | |
- check-if-prod | |
- build-docker | |
# Docs: | |
# https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs | |
permissions: | |
contents: write | |
packages: read # to preserve default permissions | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Gradle and Java | |
uses: ./.github/gradle-action | |
- name: Create Github Release | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
RELEASE_TITLE=$(gradle releaseDate --quiet) | |
TAG_NAME="v${{ github.run_number }}-$(git log HEAD -1 --pretty=format:'%h')" | |
gh release create "$TAG_NAME" --title "$RELEASE_TITLE" --generate-notes --latest | |
- name: Gradle Tasks Summary | |
run: cat build/reports/build-times.md >> $GITHUB_STEP_SUMMARY |