Skip to content

Commit

Permalink
CI and CD (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
nulls authored Jul 28, 2023
1 parent 8907c9f commit 8f1a9fc
Show file tree
Hide file tree
Showing 56 changed files with 3,017 additions and 718 deletions.
7 changes: 7 additions & 0 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
codecov:
max_report_age: off
coverage:
status:
project:
default:
threshold: 2%
139 changes: 139 additions & 0 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
name: Build and test

on:
pull_request:
push:
branches:
- 'main'

jobs:
build_and_test_with_code_coverage:
name: Build and test
runs-on: ${{ matrix.os }}
strategy:
# We need multiple builds to run even if the 1st one is failing, because
# test failures may be OS-specific (or the tests themselves flaky).
fail-fast: false
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]

# A possible workaround for <https://github.com/dorny/test-reporter/issues/168>.
permissions:
checks: write
contents: write
pull-requests: write
statuses: write

steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: 11
distribution: temurin
- name: Retrieve Kotlin version
shell: bash
run: |
kv=$(cat gradle/libs.versions.toml | grep '^kotlin =' | awk -F'[=]' '{print $2}' | tr -d '" ')
echo KOTLIN_VERSION=$kv >> $GITHUB_ENV
- name: Cache konan
uses: actions/cache@v3
with:
# [@actions/glob](https://github.com/actions/toolkit/tree/main/packages/glob) is used to match paths
# It should correctly expand `~` on every OS.
path: ~/.konan
key: ${{ runner.os }}-gradle-konan-${{ env.KOTLIN_VERSION }}
- uses: gradle/gradle-build-action@v2
with:
gradle-version: wrapper
# The `--continue` flag is necessary so that Gradle keeps going after the 1st test failure.
# By default, when test for all MPP targets are executed, Kotlin Gradle Plugin generates a single aggregated HTML report.
# Property `kotlin.tests.individualTaskReports` enables individual Junit-style XML reports.
# See org.jetbrains.kotlin.gradle.testing.internal.KotlinTestReport.
arguments: |
build
--continue
-x detekt
-Pkotlin.tests.individualTaskReports=true
-Porg.gradle.caching=true
-Pdetekt.multiplatform.disabled=true
-PdisableRedundantTargets=true
-PenabledExecutables=debug
-PgprUser=${{ github.actor }}
-PgprKey=${{ secrets.GITHUB_TOKEN }}
# This step needs a Git repository, so it's impossible to extract it
# into a separate job (or, otherwise, we'd need to upload the content
# of the whole `.git` folder as an artifact).
- name: JUnit Tests (dorny/test-reporter@v1)
uses: dorny/test-reporter@v1
if: ${{ always() }}
with:
name: JUnit Tests (${{ runner.os }}, dorny/test-reporter@v1)
# Comma-separated values.
path: "**/build/test-results/*/TEST-*.xml"
reporter: java-junit
# Ignore the "Resource not accessible by integration" error when a PR
# originates from a non-collaborator. This is
# <https://github.com/dorny/test-reporter/issues/168> which may be
# potentially fixed with <https://github.com/dorny/test-reporter/pull/174>.
continue-on-error: true

- name: Upload test results
uses: actions/upload-artifact@v3
if: ${{ always() }}
with:
name: xml-test-reports-${{ runner.os }}
path: |
**/build/test-results/*/TEST-*.xml
retention-days: 1

- name: Upload gradle reports
if: ${{ always() }}
uses: actions/upload-artifact@v3
with:
name: gradle-reports-${{ matrix.os }}
path: '**/build/reports/'
- name: Code coverage report
if: ${{ runner.os == 'Linux' }}
uses: codecov/codecov-action@v3
with:
flags: unittests
fail_ci_if_error: false # optional (default = false)

report:
name: Publish JUnit test results
if: ${{ always() }}
needs: build_and_test_with_code_coverage
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]

permissions:
checks: write
pull-requests: write

steps:
- uses: actions/download-artifact@v3
if: ${{ always() }}
with:
name: xml-test-reports-${{ runner.os }}

# Uses Docker, that's why Linux-only.
- name: JUnit Tests (EnricoMi/publish-unit-test-result-action@v1, Linux)
uses: EnricoMi/publish-unit-test-result-action@v1
if: ${{ runner.os == 'Linux' }}
with:
check_name: JUnit Tests (${{ runner.os }}, EnricoMi/publish-unit-test-result-action@v1)
files: |
**/build/test-results/*/TEST-*.xml
- name: JUnit Tests (EnricoMi/publish-unit-test-result-action@v1, Windows or Mac OS X)
uses: EnricoMi/publish-unit-test-result-action/composite@v1
if: ${{ runner.os == 'Windows' || runner.os == 'macOS' }}
with:
check_name: JUnit Tests (${{ runner.os }}, EnricoMi/publish-unit-test-result-action@v1)
files: |
**/build/test-results/*/TEST-*.xml
25 changes: 25 additions & 0 deletions .github/workflows/detekt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Run deteKT

on:
push:
branches: [ main ]
pull_request:

jobs:
detekt_check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: 11
distribution: temurin
- uses: gradle/gradle-build-action@v2
with:
gradle-version: wrapper
arguments: |
detektAll
--build-cache
-PgprUser=${{ github.actor }}
-PgprKey=${{ secrets.GITHUB_TOKEN }}
31 changes: 31 additions & 0 deletions .github/workflows/diktat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Run diKTat

on:
push:
branches: [ main ]
pull_request:

jobs:
diktat_check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: 11
distribution: temurin
- uses: gradle/gradle-build-action@v2
with:
gradle-version: wrapper
arguments: |
diktatCheck
mergeDiktatReports
-Pdetekt.multiplatform.disabled=true
-Pdiktat.githubActions=true
--continue
- name: Upload SARIF report to Github
if: always()
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: build/reports/diktat/diktat-merged.sarif
71 changes: 71 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: 'Release'

on:
push:
tags:
- 'v*'

env:
GRADLE_OPTS: -Dorg.gradle.daemon=true -Dorg.gradle.parallel=true -Dorg.gradle.welcome=never
GPG_SEC: ${{ secrets.PGP_SEC }}
GPG_PASSWORD: ${{ secrets.PGP_PASSWORD }}
OSSRH_USERNAME: ${{ secrets.SONATYPE_USER }}
OSSRH_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}

jobs:
release:
name: 'Release'
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
# Fetch Git tags, so that semantic version can be calculated.
# Alternatively, run `git fetch --prune --unshallow --tags` as the
# next step, see
# https://github.com/actions/checkout/issues/206#issuecomment-607496604.
fetch-depth: 0

- name: 'Set up Java'
uses: actions/setup-java@v3
with:
java-version: 11
distribution: temurin

- name: 'Publish a release to GitHub'
id: publish-github
uses: gradle/gradle-build-action@v2
with:
gradle-version: wrapper
arguments: |
-Preckon.stage=
publishAllPublicationsToGitHubRepository
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: 'Publish a release to Maven Central'
id: publish-sonatype
uses: gradle/gradle-build-action@v2
with:
gradle-version: wrapper
arguments: |
-Preckon.stage=
publishToSonatype
closeAndReleaseSonatypeStagingRepository
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

github_release:
needs: release
name: 'Github Release'
runs-on: ubuntu-latest
steps:
- name: 'Github Release'
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
43 changes: 28 additions & 15 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import com.saveourtool.osv4k.buildutils.createDetektTask

plugins {
alias(libs.plugins.kotlin.multiplatform)
alias(libs.plugins.kotlin.plugin.serialization)
id("com.saveourtool.osv4k.buildutils.kotlin-library")
id("com.saveourtool.osv4k.buildutils.publishing-configuration")
}

group = "com.saveourtool.osv4k"
Expand All @@ -9,26 +11,27 @@ repositories {
mavenCentral()
}

createDetektTask()

kotlin {
jvm {
withJava()
compilations.all {
kotlinOptions.run {
jvmTarget = "1.8"
}
kotlinOptions.jvmTarget = "1.8"
}
}
linuxX64()
mingwX64()
macosX64()
val nativeTargets = setOf(
linuxX64(),
mingwX64(),
macosX64(),
)
sourceSets {
val commonMain by getting {
dependencies {
api(libs.kotlinx.serialization.json)
api(libs.kotlinx.datetime)
}
}
@Suppress("UNUSED_VARIABLE")
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
Expand All @@ -38,12 +41,8 @@ kotlin {
val commonNonJvmMain by creating {
dependsOn(commonMain)
}
listOf(
"linuxX64",
"mingwX64",
"macosX64",
).forEach { nonJvmTarget ->
getByName("${nonJvmTarget}Main").dependsOn(commonNonJvmMain)
nativeTargets.forEach { nativeTarget ->
getByName("${nativeTarget.name}Main").dependsOn(commonNonJvmMain)
}
@Suppress("UNUSED_VARIABLE")
val jvmMain by getting {
Expand All @@ -52,5 +51,19 @@ kotlin {
api(libs.jackson.databind)
}
}
@Suppress("UNUSED_VARIABLE")
val jvmTest by getting {
dependsOn(commonTest)
dependencies {
implementation(kotlin("test-junit5"))
}
}
}
}

setOf("compileJava", "compileTestJava").forEach { taskName ->
tasks.named<JavaCompile>(taskName) {
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
}
}
22 changes: 22 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
plugins {
`kotlin-dsl`
}

repositories {
mavenCentral()
gradlePluginPortal()
}

dependencies {
// workaround https://github.com/gradle/gradle/issues/15383
implementation(files(project.libs.javaClass.superclass.protectionDomain.codeSource.location))
implementation(libs.kotlin.gradle.plugin) {
because("Add plugin on plugin classpath here to automatically set its version for the whole build")
}
implementation(libs.diktat.gradle.plugin)
implementation(libs.detekt.gradle.plugin)
implementation(libs.kotlin.plugin.serialization)
implementation("org.ajoberstar.reckon:reckon-gradle:0.18.0")
implementation(libs.dokka.gradle.plugin)
implementation(libs.gradle.nexus.publish.plugin)
}
7 changes: 7 additions & 0 deletions buildSrc/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
dependencyResolutionManagement {
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}
Loading

0 comments on commit 8f1a9fc

Please sign in to comment.