Skip to content

test: add tests for templates factory #156

test: add tests for templates factory

test: add tests for templates factory #156

Workflow file for this run

# DO NOT EDIT: this file is automatically synced from the template repository
# in https://github.com/Liber-UFPE/project-starter.
name: CI
on:
push:
branches: [ "main" ]
pull_request:
types: [ "opened", "synchronize", "reopened" ]
env:
GRADLE_OPTS: '-Dorg.gradle.console=plain -Dorg.gradle.caching=true -Dsonar.gradle.skipCompile=true -Dorg.gradle.jvmargs="-Xmx2g -XX:MaxMetaspaceSize=512m"'
concurrency:
# This workflow cuts releases, so we want only a
# single concurrent workflow run per branch/tag/etc.
group: ${{ github.ref }}
cancel-in-progress: true
jobs:
diktat:
name: Code Analysis / diktat
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: marcospereira/kotlin-diktat-action@v1
with:
patterns: "src/main/kotlin src/test/kotlin '!src/main/kotlin/br/ufpe/liber/tasks/*.kt'"
ktlint:
name: Code Analysis / ktlint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: nbadal/action-ktlint-setup@v1
- run: ktlint --version
- run: ktlint --relative >> $GITHUB_STEP_SUMMARY
detekt:
name: Code Analysis / detekt
runs-on: ubuntu-latest
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
stylelint:
name: Code Analysis / stylelint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "lts/*" # latest lts
check-latest: true
cache: "npm"
- name: npm install
run: npm install
- name: run stylelint
run: npx stylelint src/main/**/*.scss
eslint:
name: Code Analysis / eslint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "lts/*" # latest lts
check-latest: true
cache: "npm"
- name: npm install
run: npm install
- name: run eslint
run: npx eslint .
compile:
name: Build / compile
runs-on: ubuntu-latest
needs:
- diktat
- detekt
- ktlint
- stylelint
- eslint
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: ./gradlew --info
- run: ./gradlew testClasses
- name: Gradle Tasks Summary
run: cat build/reports/build-times.md >> $GITHUB_STEP_SUMMARY
esbuild-check:
name: Test / Assets / pipeline
runs-on: ubuntu-latest
needs:
- diktat
- detekt
- ktlint
- stylelint
- eslint
strategy:
matrix:
node-version: [18, 20]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
check-latest: true
cache: "npm"
- run: node --version
- run: npm install
- name: Run assets pipeline
run: |
rm -rf ./build
node assets-pipeline.mjs
tree ./build
test:
name: Tests / test
runs-on: ubuntu-latest
needs:
- compile
- esbuild-check
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Cache SonarCloud packages
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Set up Gradle and Java
uses: ./.github/gradle-action
- name: Run tests
run: ./gradlew check koverXmlReport
- name: Gradle Tasks Summary
run: cat build/reports/build-times.md >> $GITHUB_STEP_SUMMARY
- name: Run SonarCloud Analysis
continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: ./gradlew sonar
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
continue-on-error: true
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
verbose: true
good-to-merge:
name: Good to merge
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request' }}
needs:
- test
steps:
- run: echo "This PR is ready to merge."
check-if-should-release:
if: ${{ github.ref == 'refs/heads/main' }}
name: Check if should release
runs-on: ubuntu-latest
needs:
- test
# This job also has an output that can be used by downstream jobs.
# https://docs.github.com/en/actions/using-jobs/defining-outputs-for-jobs
outputs:
tagName: ${{ steps.generateTagName.outputs.tagName }}
steps:
- run: echo "This is a push to main branch. Following with release a new version"
- name: Generate tag name
id: generateTagName
# TAG_NAME value is trying to emulate semver to avoid release ordering issues.
# See https://github.com/orgs/community/discussions/8226.
run: echo "tagName=v$(date '+%Y%m%d.%H%M.%S')" >> "$GITHUB_OUTPUT"
create-release:
name: Creates a GitHub Release
runs-on: ubuntu-latest
needs:
- test
- check-if-should-release
# Docs:
# https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs
permissions:
contents: write
packages: read # to preserve default permissions
env:
GH_TOKEN: ${{ github.token }}
TAG_NAME: ${{ needs.check-if-should-release.outputs.tagName }}
RELEASE_TITLE: Release ${{ needs.check-if-should-release.outputs.tagName }}
steps:
- uses: actions/checkout@v4
- uses: ./.github/gradle-action
- name: Generate jar artifacts
run: ./gradlew -PreleaseTag=$TAG_NAME clean shadowJar -x test -x accessibilityTest --no-configuration-cache
- name: Create Github Release
run: gh release create "$TAG_NAME" --title "$RELEASE_TITLE" --generate-notes --latest ./build/libs/*.jar
publish-docker-image:
name: Publish docker image
runs-on: ubuntu-latest
env:
REGISTRY: ghcr.io
GH_TOKEN: ${{ github.token }}
TAG_NAME: ${{ needs.check-if-should-release.outputs.tagName }}
needs:
- test
- check-if-should-release
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # 0 indicates all history for all branches and tags.
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- name: Docker / Get image name
id: dockerImageName
run: |
echo "dockerImageName=${{ env.REGISTRY }}/${{ github.repository }}" | tr '[:upper:]' '[:lower:]'>> "$GITHUB_OUTPUT"
- name: Create Image
run: docker image build -t ${{ steps.dockerImageName.outputs.dockerImageName }}:latest .
# Needs to log in to use docker scout below
- uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- uses: docker/scout-action@v1
continue-on-error: true
with:
command: quickview
image: ${{ steps.dockerImageName.outputs.dockerImageName }}
write-comment: false
summary: true
# Adapted from https://docs.docker.com/build/ci/github-actions/test-before-push/
- name: Test Image
# From `docker run --help`:
# -d, --detach Run container in background and print container ID
# --rm Automatically remove the container when it exits
# -p, --publish list Publish a container's port(s) to the host
run: |
containerId=$(docker run -d --rm --publish 8080:8080 ${{ steps.dockerImageName.outputs.dockerImageName }})
wget --retry-connrefused --tries=20 -nv --wait=1 --spider http://localhost:8080/
docker container logs "$containerId"
docker container stop "$containerId"
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Publish to GitHub Registry
run: |
last_git_sha=$(git log --pretty=format:'%h' HEAD -1)
source_image_name=${{ steps.dockerImageName.outputs.dockerImageName }}
echo "Using git tag $TAG_NAME"
echo "Using last git sha $last_git_sha"
echo "Context's github.sha = ${{ github.sha }}"
echo "Images to tag => $source_image_name:$TAG_NAME"
echo "Images to tag => $source_image_name:$last_git_sha"
docker tag "$source_image_name" "$source_image_name:$TAG_NAME"
docker tag "$source_image_name" "$source_image_name:$last_git_sha"
docker push --all-tags ${{ steps.dockerImageName.outputs.dockerImageName }}