Skip to content

Commit

Permalink
Migration to Gradle (#1625)
Browse files Browse the repository at this point in the history
  • Loading branch information
nulls authored Mar 23, 2023
1 parent 42da8e0 commit d6e9848
Show file tree
Hide file tree
Showing 60 changed files with 1,500 additions and 2,406 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ ij_smart_tabs = false
ij_visual_guides = 80,120,180
ij_wrap_on_typing = false

[{*.yaml,*.yml}]
indent_size = 2

[{*.kt,*.kts}]
ij_kotlin_align_in_columns_case_branch = false
ij_kotlin_align_multiline_binary_operation = false
Expand Down
139 changes: 87 additions & 52 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,67 @@ on:
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:
distribution: zulu
java-version: 11
- name: Cache local Maven repository
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
shell: bash
- name: Cache konan
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: maven-build-${{ hashFiles('**/pom.xml') }}
restore-keys: |
maven-build-
- name: Maven Install
run: mvn -B -Dstyle.color=always clean install
- name: Code coverage report
uses: codecov/codecov-action@v3
path: ~/.konan
key: ${{ runner.os }}-gradle-konan-${{ env.KOTLIN_VERSION }}
- name: Build all
uses: gradle/gradle-build-action@v2
with:
gradle-version: wrapper
gradle-home-cache-cleanup: true
arguments: |
build
-x detekt
--scan
--build-cache
- name: Upload gradle reports
if: ${{ always() }}
uses: actions/upload-artifact@v3
with:
files: '**/target/site/jacoco*/jacoco.xml,**/reports/jacoco/**/*.xml'
flags: unittests
fail_ci_if_error: true # optional (default = false)
name: gradle-reports
path: '**/build/reports/'
retention-days: 1
- name: Upload diktat jar
uses: actions/upload-artifact@v3
with:
name: diktat-ruleset
path: diktat-ruleset/target/diktat-*.jar
path: diktat-ruleset/build/libs/diktat-*.jar
# no need to store artifact longer, it is used only by dependant jobs
retention-days: 1
- name: Upload gradle reports
if: ${{ failure() }}
uses: actions/upload-artifact@v3
- name: Code coverage report
uses: codecov/codecov-action@v3
with:
name: gradle-test-report-${{ runner.os }}
path: 'diktat-gradle-plugin/build/reports/'
retention-days: 1
fail_ci_if_error: false

run_diktat_from_CLI:
name: Run diktat via CLI
Expand All @@ -60,10 +80,11 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Setup environment variables

- name: Retrieve Ktlint version
run: |
cat pom.xml | grep "<version>.*</version>" | head -1 | awk -F'[><]' '{ printf "DIKTAT_VERSION=%s\n",$3 }' >> $GITHUB_ENV
cat pom.xml | grep "<ktlint.version>.*</ktlint.version>" | head -1 | awk -F'[><]' '{ printf "KTLINT_VERSION=%s\n",$3 }' >> $GITHUB_ENV
ktlint_version=$(cat gradle/libs.versions.toml | grep '^ktlint =' | awk -F'[=]' '{print $2}' | tr -d '" ')
echo KTLINT_VERSION=$ktlint_version >> $GITHUB_ENV
shell: bash

- name: Setup environment
Expand All @@ -77,10 +98,16 @@ jobs:
with:
name: diktat-ruleset

- name: Retrieve diktat jar file name
run: |
filename=$(ls diktat-*.jar)
echo DIKTAT_JAR=$filename >> $GITHUB_ENV
shell: bash

- name: Run diKTat from cli
continue-on-error: true
run: |
java -jar ktlint -R diktat-${{ env.DIKTAT_VERSION }}.jar --disabled_rules=standard 'examples/maven/src/main/kotlin/Test.kt' &>out.txt
java -jar ktlint -R ${{ env.DIKTAT_JAR }} --disabled_rules=standard 'examples/maven/src/main/kotlin/Test.kt' &>out.txt
shell: bash

- name: Check output
Expand All @@ -94,14 +121,14 @@ jobs:
continue-on-error: true
if: ${{ runner.os == 'Linux' || runner.os == 'macOS' }}
run: |
java -jar ktlint -R diktat-${{ env.DIKTAT_VERSION }}.jar --disabled_rules=standard "$PWD/examples/maven/src/main/kotlin/Test.kt" &>out.txt
java -jar ktlint -R ${{ env.DIKTAT_JAR }} --disabled_rules=standard "$PWD/examples/maven/src/main/kotlin/Test.kt" &>out.txt
shell: bash

- name: Run diKTat from cli on windows (absolute paths)
continue-on-error: true
if: runner.os == 'Windows'
run: |
java -jar ktlint -R diktat-${{ env.DIKTAT_VERSION }}.jar --disabled_rules=standard "%cd%/examples/maven/src/main/kotlin/Test.kt" > out.txt 2>&1
java -jar ktlint -R ${{ env.DIKTAT_JAR }} --disabled_rules=standard "%cd%/examples/maven/src/main/kotlin/Test.kt" > out.txt 2>&1
shell: cmd

- name: Check output (absolute paths)
Expand All @@ -114,7 +141,7 @@ jobs:
- name: Run diKTat from cli (glob paths, 1 of 4)
continue-on-error: true
run: |
java -jar ktlint -R diktat-${{ env.DIKTAT_VERSION }}.jar --disabled_rules=standard 'examples/maven/src/main/kotlin/*.kt' &>out.txt
java -jar ktlint -R ${{ env.DIKTAT_JAR }} --disabled_rules=standard 'examples/maven/src/main/kotlin/*.kt' &>out.txt
shell: bash

- name: Check output (glob paths, 1 of 4)
Expand All @@ -127,7 +154,7 @@ jobs:
- name: Run diKTat from cli (glob paths, 2 of 4)
continue-on-error: true
run: |
java -jar ktlint -R diktat-${{ env.DIKTAT_VERSION }}.jar --disabled_rules=standard 'examples/**/main/kotlin/*.kt' &>out.txt
java -jar ktlint -R ${{ env.DIKTAT_JAR }} --disabled_rules=standard 'examples/**/main/kotlin/*.kt' &>out.txt
shell: bash

- name: Check output (glob paths, 2 of 4)
Expand All @@ -140,7 +167,7 @@ jobs:
- name: Run diKTat from cli (glob paths, 3 of 4)
continue-on-error: true
run: |
java -jar ktlint -R diktat-${{ env.DIKTAT_VERSION }}.jar --disabled_rules=standard 'examples/**/*.kt' &>out.txt
java -jar ktlint -R ${{ env.DIKTAT_JAR }} --disabled_rules=standard 'examples/**/*.kt' &>out.txt
shell: bash

- name: Check output (glob paths, 3 of 4)
Expand All @@ -153,7 +180,7 @@ jobs:
- name: Run diKTat from cli (glob paths, 4 of 4)
continue-on-error: true
run: |
java -jar ktlint -R diktat-${{ env.DIKTAT_VERSION }}.jar --disabled_rules=standard '**/*.kt' &>out.txt
java -jar ktlint -R ${{ env.DIKTAT_JAR }} --disabled_rules=standard '**/*.kt' &>out.txt
shell: bash

- name: Check output (glob paths, 4 of 4)
Expand All @@ -171,7 +198,7 @@ jobs:
# test failures may be OS-specific (or the tests themselves flaky).
fail-fast: false
matrix:
os: [ windows-latest, macos-latest ]
os: [ ubuntu-latest, windows-latest, macos-latest ]

# A possible workaround for <https://github.com/dorny/test-reporter/issues/168>.
permissions:
Expand All @@ -182,30 +209,35 @@ jobs:

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:
distribution: zulu
java-version: 11
- name: Cache local Maven repository
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: maven-build-${{ hashFiles('**/pom.xml') }}
restore-keys: |
maven-build-
- name: Maven Install
if: ${{ runner.os == 'Linux' || runner.os == 'macOS' }}
distribution: temurin
- name: Retrieve Kotlin version
run: |
mvn -B -Dstyle.color=always -T1C clean install
kv=$(cat gradle/libs.versions.toml | grep '^kotlin =' | awk -F'[=]' '{print $2}' | tr -d '" ')
echo KOTLIN_VERSION=$kv >> $GITHUB_ENV
shell: bash
- name: Cache konan
uses: actions/cache@v3
with:
path: ~/.konan
key: ${{ runner.os }}-gradle-konan-${{ env.KOTLIN_VERSION }}

- name: Maven Install on windows
if: runner.os == 'Windows'
run: |
mvn -B -Dstyle.color=always -T1C clean install
shell: cmd
- name: Build all
uses: gradle/gradle-build-action@v2
with:
gradle-version: wrapper
gradle-home-cache-cleanup: true
arguments: |
build
-x detekt
--scan
--build-cache
# 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
Expand All @@ -216,7 +248,7 @@ jobs:
with:
name: JUnit Tests (${{ runner.os }}, dorny/test-reporter@v1)
# Comma-separated values.
path: "**/target/*-reports/TEST-*.xml, **/build/test-results/*/TEST-*.xml"
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
Expand All @@ -230,17 +262,20 @@ jobs:
with:
name: xml-test-reports-${{ runner.os }}
path: |
**/target/*-reports/TEST-*.xml
**/build/test-results/*/TEST-*.xml
retention-days: 1

- name: Upload gradle reports
if: ${{ failure() }}
if: ${{ always() }}
uses: actions/upload-artifact@v3
with:
name: gradle-test-report-${{ matrix.os }}
path: 'diktat-gradle-plugin/build/reports/'
path: '**/build/reports/'
retention-days: 1
- name: Code coverage report
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: false

report:
name: Publish JUnit test results
Expand Down
22 changes: 19 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
matrix:
# Override automatic language detection by changing the below list
# Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python']
language: ['java']
language: ['kotlin']
# Learn more...
# https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection

Expand Down Expand Up @@ -58,8 +58,24 @@ jobs:
# and modify them (or add more) to build your code if your project
# uses a compiled language

- run: |
mvn clean install
- 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 }}
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
39 changes: 26 additions & 13 deletions .github/workflows/detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,37 @@ on:
pull_request:

jobs:
test:
name: Running detekt
runs-on: ubuntu-18.04
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:
distribution: zulu
java-version: 11
- name: Cache local Maven repository
uses: actions/cache@v3
distribution: temurin
- uses: gradle/gradle-build-action@v2
with:
path: ~/.m2/repository
key: maven-detekt-${{ hashFiles('**/pom.xml') }}
restore-keys: |
maven-detekt-
# when running detekt with type resolution, we need to have all project modules compiled too
- name: running deteKT
run: mvn -B compile dependency:build-classpath@detekt detekt:check@detekt -DskipPluginMarker
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
Loading

0 comments on commit d6e9848

Please sign in to comment.