Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support GitHub actions #1

Merged
merged 6 commits into from
Apr 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* text=auto
*.bat eol=crlf
63 changes: 63 additions & 0 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Build and test

on:
pull_request:
push:
branches:
- 'master'

concurrency:
# https://docs.github.com/en/actions/using-jobs/using-concurrency
# The latest queued workflow is preferred; the ones already in progress get cancelled
# Workflows on master branch shouldn't be cancelled, that's why they are identified by commit SHA
group: ${{ github.ref == 'refs/heads/master' && format('{0}-{1}', github.workflow, github.sha) || format('{0}-{1}', github.workflow, github.ref) }}
cancel-in-progress: true

jobs:
build_and_test_with_code_coverage:
name: Build, test and upload code coverage
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
# required for correct codecov upload
fetch-depth: 0
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: 11
distribution: temurin
- name: Retrieve Kotlin version
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:
path: ~/.konan
key: ${{ runner.os }}-gradle-konan-${{ env.KOTLIN_VERSION }}
- name: Build
uses: gradle/gradle-build-action@v2
with:
gradle-version: wrapper
gradle-home-cache-cleanup: true
arguments: |
build
-x detekt
-Pdetekt.multiplatform.disabled=true
-PgprUser=${{ github.actor }}
-PgprKey=${{ secrets.GITHUB_TOKEN }}
--scan
--build-cache
- name: Upload gradle reports
if: ${{ always() }}
uses: actions/upload-artifact@v3
with:
name: gradle-reports
path: '**/build/reports/'
retention-days: 1
- name: Code coverage report
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: false
41 changes: 41 additions & 0 deletions .github/workflows/detekt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Run deteKT

on:
push:
branches: [ master ]
pull_request:

jobs:
detekt_check:
runs-on: ubuntu-latest
permissions:
# required for all workflows
security-events: write
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
--continue
-PgprUser=${{ github.actor }}
-PgprKey=${{ secrets.GITHUB_TOKEN }}
- name: Upload SARIF report to Github
uses: github/codeql-action/upload-sarif@v2
if: ${{ always() }}
with:
sarif_file: build/detekt-sarif-reports/detekt-merged.sarif
- name: Upload SARIF artifacts
uses: actions/upload-artifact@v3
if: ${{ failure() }}
with:
name: sarif-reports
path: "**/build/detekt-sarif-reports/"
retention-days: 1
44 changes: 44 additions & 0 deletions .github/workflows/diktat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Run diKTat

on:
push:
branches: [ master ]
pull_request:

jobs:
diktat_check:
runs-on: ubuntu-latest
permissions:
# required for all workflows
security-events: write
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
-Pdiktat.githubActions=true
-Pdetekt.multiplatform.disabled=true
--build-cache
--continue
-PgprUser=${{ github.actor }}
-PgprKey=${{ secrets.GITHUB_TOKEN }}
- name: Upload SARIF report to Github
uses: github/codeql-action/upload-sarif@v2
if: ${{ always() }}
with:
sarif_file: build/reports/diktat/diktat-merged.sarif
- name: Upload SARIF artifacts
uses: actions/upload-artifact@v3
if: ${{ failure() }}
with:
name: sarif-reports
path: "**/build/reports/diktat"
retention-days: 1
14 changes: 14 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

import com.saveourtool.processbuilder.configureDiktat
import com.saveourtool.processbuilder.createDetektTask

group = "com.saveourtool"
description = "Kotlin Process Builder"

plugins {
id("org.cqfn.diktat.diktat-gradle-plugin")
id("io.gitlab.arturbosch.detekt")
}

configureDiktat()
createDetektTask()
16 changes: 16 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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.diktat.gradle.plugin)
implementation(libs.detekt.gradle.plugin)
implementation(libs.kotlin.gradle.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"))
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* Configuration for detekt static analysis
*/

package com.saveourtool.processbuilder

import io.gitlab.arturbosch.detekt.Detekt
import io.gitlab.arturbosch.detekt.DetektPlugin
import io.gitlab.arturbosch.detekt.extensions.DetektExtension
import io.gitlab.arturbosch.detekt.report.ReportMergeTask
import org.gradle.api.Project
import org.gradle.api.tasks.TaskProvider
import org.gradle.kotlin.dsl.*

/**
* Configure Detekt for a single project
*/
fun Project.configureDetekt() {
apply<DetektPlugin>()
configure<DetektExtension> {
config = rootProject.files("detekt.yml")
basePath = rootDir.canonicalPath
buildUponDefaultConfig = true
}
}

/**
* Register a unified detekt task
*/
fun Project.createDetektTask() {
val detektAllTask = tasks.register("detektAll") {
allprojects {
[email protected](tasks.withType<Detekt>())
}
}

tasks.register("mergeDetektReports", ReportMergeTask::class) {
mustRunAfter(detektAllTask)
output.set(buildDir.resolve("detekt-sarif-reports/detekt-merged.sarif"))
}

@Suppress("GENERIC_VARIABLE_WRONG_DECLARATION")
val reportMerge: TaskProvider<ReportMergeTask> = rootProject.tasks.named<ReportMergeTask>("mergeDetektReports") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's the same task as created on prev line tasks.register("mergeDetektReports", ReportMergeTask::class) {
why not merged them?

input.from(
tasks.withType<Detekt>().map { it.sarifReportFile }
)
shouldRunAfter(tasks.withType<Detekt>())
}
tasks.withType<Detekt>().configureEach {
reports.sarif.required.set(true)
finalizedBy(reportMerge)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Configuration for diktat static analysis
*/

package com.saveourtool.processbuilder

import org.cqfn.diktat.plugin.gradle.DiktatExtension
import org.cqfn.diktat.plugin.gradle.DiktatGradlePlugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.configure

/**
* Applies diktat gradle plugin and configures diktat for [this] project
*/
fun Project.configureDiktat() {
apply<DiktatGradlePlugin>()
configure<DiktatExtension> {
diktatConfigFile = rootProject.file("diktat-analysis.yml")
githubActions = findProperty("diktat.githubActions")?.toString()?.toBoolean() ?: false
inputs {
include("src/**/*.kt", "*.kts", "src/**/*.kts")
exclude("build/**")
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* File containing constants
*/

package com.saveourtool.processbuilder.utils

const val NOT_IMPLEMENTED_IN_JS = "Not implemented in JS"
Loading