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

Repo infrastructure #5

Merged
merged 4 commits into from
Feb 11, 2021
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
12 changes: 12 additions & 0 deletions .git-hooks/commit-msg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

commit_pattern="(Merge (remote-tracking )?branch|### What's done:)"
error_msg="Your commit message doesn't match the pattern $commit_pattern. Please fix it."

if [[ ! $( cat "$1" ) =~ $commit_pattern ]]
then
echo "$error_msg"
exit 1
fi

exit 0
13 changes: 13 additions & 0 deletions .git-hooks/pre-commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

branch_name="$(git rev-parse --abbrev-ref HEAD)"
branch_pattern="^(feature|bugfix|hotfix|infra)/.*$"
error_message="Your branch name doesn't match the pattern $branch_pattern. Please correct it before committing."

if [[ ! $branch_name =~ $branch_pattern ]]
then
echo "$error_message"
exit 1
fi

exit 0
9 changes: 6 additions & 3 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
name: Build and test

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

jobs:
build_and_test_with_code_coverage:
Expand Down Expand Up @@ -31,7 +34,7 @@ jobs:
run: |
ARCH=$(uname -m)
URL=https://storage.googleapis.com/gvisor/releases/release/latest/${ARCH}
wget ${URL}/runsc ${URL}/runsc.sha512 \
wget -nv ${URL}/runsc ${URL}/runsc.sha512 \
${URL}/containerd-shim-runsc-v1 ${URL}/containerd-shim-runsc-v1.sha512
sha512sum -c runsc.sha512 \
-c containerd-shim-runsc-v1.sha512
Expand All @@ -42,7 +45,7 @@ jobs:
sudo systemctl reload docker
- name: Gradle build
run: |
./gradlew build
./gradlew build -x detekt
- name: Upload test reports
uses: actions/upload-artifact@v2
with:
Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/detekt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Run deteKT

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
detekt_check:
runs-on: ubuntu-20.04
env:
GRADLE_OPTS: -Dorg.gradle.daemon=false

steps:
- uses: actions/[email protected]
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 1.11
- name: Cache gradle caches
uses: actions/cache@v2
with:
path: |
~/.gradle/caches/
~/.gradle/wrapper/
key: ${{ runner.os }}-gradle-detekt-${{ hashFiles('**/*.gradle*') }}
restore-keys: ${{ runner.os }}-gradle-detekt
- name: Run detekt
run: ./gradlew detektAll
30 changes: 30 additions & 0 deletions .github/workflows/diktat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Run diKTat

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
diktat_check:
runs-on: ubuntu-20.04
env:
GRADLE_OPTS: -Dorg.gradle.daemon=false

steps:
- uses: actions/[email protected]
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 1.11
- name: Cache gradle caches
uses: actions/cache@v2
with:
path: |
~/.gradle/caches/
~/.gradle/wrapper/
key: ${{ runner.os }}-gradle-diktat-${{ hashFiles('**/*.gradle*') }}
restore-keys: ${{ runner.os }}-gradle-diktat
- name: Run diktat
run: ./gradlew diktatCheckAll
38 changes: 0 additions & 38 deletions .github/workflows/metrics_for_master.yml

This file was deleted.

13 changes: 13 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
import org.cqfn.save.buildutils.configureDetekt
import org.cqfn.save.buildutils.configureDiktat
import org.cqfn.save.buildutils.createDetektTask
import org.cqfn.save.buildutils.createDiktatTask
import org.cqfn.save.buildutils.installGitHooks

plugins {
kotlin("jvm") version "1.4.21" apply false
id("com.github.ben-manes.versions") version "0.36.0"
}

allprojects {
repositories {
jcenter()
mavenCentral()
}
configureDiktat()
configureDetekt()
}

createDiktatTask()
createDetektTask()
installGitHooks()
5 changes: 5 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@ plugins {

repositories {
jcenter()
}

dependencies {
implementation("org.cqfn.diktat:diktat-gradle-plugin:0.4.0")
implementation("io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.15.0")
}
16 changes: 8 additions & 8 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
object Versions {
val kotlin = "1.4.30"
val springBoot = "2.4.2"
val springSecurity = "5.4.2"
val hibernate = "5.4.2.Final"
val liquibase = "4.2.2"
val slf4j = "1.7.30"
val logback = "1.2.3"
val dockerJavaApi = "3.2.7"
const val kotlin = "1.4.30"
const val springBoot = "2.4.2"
const val springSecurity = "5.4.2"
const val hibernate = "5.4.2.Final"
const val liquibase = "4.3.0"
const val slf4j = "1.7.30"
const val logback = "1.2.3"
const val dockerJavaApi = "3.2.7"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Configuration for detekt static analysis
*/

package org.cqfn.save.buildutils

import io.gitlab.arturbosch.detekt.DetektPlugin
import io.gitlab.arturbosch.detekt.extensions.DetektExtension
import org.gradle.api.Project
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.configure

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

/**
* Register a unified detekt task
*/
fun Project.createDetektTask() {
tasks.register("detektAll") {
allprojects {
[email protected](tasks.getByName("detekt"))
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Configuration for diktat static analysis
*/

package org.cqfn.save.buildutils

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")
inputs = files("src/**/*.kt")
}
}

/**
* Creates unified tasks to run diktat on all projects
*/
fun Project.createDiktatTask() {
tasks.register("diktatCheckAll") {
allprojects {
[email protected](tasks.getByName("diktatCheck"))
}
}
tasks.register("diktatFixAll") {
allprojects {
[email protected](tasks.getByName("diktatFix"))
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Gradle tasks to install git hooks as a part of the build
*/

package org.cqfn.save.buildutils

import org.gradle.api.Project
import org.gradle.api.tasks.Copy
import org.gradle.kotlin.dsl.register

/**
* Task of type [Copy] that install git hooks from directory in repo to .git directory
*/
fun Project.installGitHooks() {
val installGitHooksTask = tasks.register("installGitHooks", Copy::class) {
from(file("$rootDir/.git-hooks"))
into(file("$rootDir/.git/hooks"))
}
// add git hooks installation to build by adding it as a dependency for some common task
subprojects.mapNotNull {
it.tasks.findByName("build")
}
.firstOrNull()
?.dependsOn(installGitHooksTask)
}
Loading