Skip to content

Commit

Permalink
Repo infrastructure (#5)
Browse files Browse the repository at this point in the history
### What's done:
* Diktat code analysis
* Detekt code analysis
* Git hooks
* Fixed code style
  • Loading branch information
petertrr authored Feb 11, 2021
1 parent c4e4590 commit 31ce1b6
Show file tree
Hide file tree
Showing 22 changed files with 1,222 additions and 94 deletions.
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 {
this@register.dependsOn(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 {
this@register.dependsOn(tasks.getByName("diktatCheck"))
}
}
tasks.register("diktatFixAll") {
allprojects {
this@register.dependsOn(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

1 comment on commit 31ce1b6

@0pdd
Copy link

@0pdd 0pdd commented on 31ce1b6 Feb 11, 2021

Choose a reason for hiding this comment

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

I wasn't able to retrieve PDD puzzles from the code base and submit them to GitHub. If you think that it's a bug on our side, please submit it to yegor256/0pdd:

set -x && set -e && set -o pipefail && cd /tmp/0pdd20201201-12-in0cd3/cqfn/save && pdd -v -f /tmp/20210211-4565-16uyd9w [1]: + set -e + set -o pipefail + cd /tmp/0pdd20201201-12-in0cd3/cqfn/save + pdd -v -f /tmp/20210211-4565-16uyd9w My version is 0.20.6 Ruby version is 2.6.0 at x86_64-linux...

Please, copy and paste this stack trace to GitHub:

UserError
set -x && set -e && set -o pipefail && cd /tmp/0pdd20201201-12-in0cd3/cqfn/save && pdd -v -f /tmp/20210211-4565-16uyd9w [1]:
+ set -e
+ set -o pipefail
+ cd /tmp/0pdd20201201-12-in0cd3/cqfn/save
+ pdd -v -f /tmp/20210211-4565-16uyd9w

My version is 0.20.6
Ruby version is 2.6.0 at x86_64-linux
Reading /tmp/0pdd20201201-12-in0cd3/cqfn/save
44 file(s) found, 479 excluded
/tmp/0pdd20201201-12-in0cd3/cqfn/save/save-core/README.md is a binary file (0 bytes)
/tmp/0pdd20201201-12-in0cd3/cqfn/save/save-plugins/README.md is a binary file (0 bytes)
/tmp/0pdd20201201-12-in0cd3/cqfn/save/save-common/README.md is a binary file (0 bytes)
/tmp/0pdd20201201-12-in0cd3/cqfn/save/gradle/wrapper/gradle-wrapper.jar is a binary file (59203 bytes)
/tmp/0pdd20201201-12-in0cd3/cqfn/save/save-frontend/README.md is a binary file (0 bytes)
Reading diktat-analysis.yml...
Reading .git-hooks/pre-commit.sh...
Reading .git-hooks/commit-msg.sh...
Reading LICENSE...
Reading .gitignore...
Reading README.md...
Reading .gitattributes...
Reading save-orchestrator/build.gradle.kts...
Reading save-orchestrator/src/main/resources/application.properties...
Reading save-orchestrator/src/main/kotlin/org/cqfn/save/orchestrator/SaveOrchestrator.kt...
Reading save-orchestrator/src/main/kotlin/org/cqfn/save/orchestrator/docker/ContainerManager.kt...
Reading save-orchestrator/src/test/kotlin/org/cqfn/save/orchestrator/docker/ContainerManagerTest.kt...
Reading save-core/build.gradle.kts...
Reading settings.gradle.kts...
Reading save-plugins/build.gradle.kts...
Reading .github/codecov.yml...
Reading .github/workflows/diktat.yml...
Reading .github/workflows/build_and_test.yml...
Reading .github/workflows/detekt.yml...
Reading buildSrc/build.gradle.kts...
Reading buildSrc/src/main/kotlin/Versions.kt...
Reading buildSrc/src/main/kotlin/org/cqfn/save/buildutils/JacocoConfiguration.kt...
Reading buildSrc/src/main/kotlin/org/cqfn/save/buildutils/DetektConfiguration.kt...
Reading buildSrc/src/main/kotlin/org/cqfn/save/buildutils/GitHookInstallation.kt...
Reading buildSrc/src/main/kotlin/org/cqfn/save/buildutils/DiktatConfiguration.kt...
Reading gradlew.bat...
Reading gradlew...
Reading save-common/build.gradle.kts...
Reading save-common/src/commonMain/kotlin/org/cqfn/save/domain/RunConfiguration.kt...
Reading gradle/wrapper/gradle-wrapper.properties...
Reading build.gradle.kts...
Reading save-backend/build.gradle.kts...
Reading save-backend/src/main/resources/logback.xml...
Reading save-backend/src/main/resources/application.properties...
Reading save-backend/src/main/kotlin/org/cqfn/save/backend/controllers/DownloadFilesController.kt...
Reading save-backend/src/main/kotlin/org/cqfn/save/backend/SaveApplication.kt...
Reading save-backend/src/test/kotlin/org/cqfn/save/backend/DownloadFilesTest.kt...
Reading save-frontend/build.gradle.kts...
Reading detekt.yml...
ERROR: detekt.yml; puzzle at line #643; TODO must have a leading space to become a puzzle, as this page explains: https://github.com/yegor256/pdd#how-to-format
If you can't understand the cause of this issue or you don't know how to fix it, please submit a GitHub issue, we will try to help you: https://github.com/yegor256/pdd/issues. This tool is still in its beta version and we will appreciate your feedback. Here is where you can find more documentation: https://github.com/yegor256/pdd/blob/master/README.md.
Exit code is 1

/app/objects/git_repo.rb:66:in `rescue in block in xml'
/app/objects/git_repo.rb:63:in `block in xml'
/app/vendor/ruby-2.6.0/lib/ruby/2.6.0/tempfile.rb:295:in `open'
/app/objects/git_repo.rb:62:in `xml'
/app/objects/puzzles.rb:36:in `deploy'
/app/objects/job.rb:38:in `proceed'
/app/objects/job_starred.rb:33:in `proceed'
/app/objects/job_recorded.rb:32:in `proceed'
/app/objects/job_emailed.rb:35:in `proceed'
/app/objects/job_commiterrors.rb:36:in `proceed'
/app/objects/job_detached.rb:48:in `exclusive'
/app/objects/job_detached.rb:36:in `block in proceed'
/app/objects/job_detached.rb:36:in `fork'
/app/objects/job_detached.rb:36:in `proceed'
/app/0pdd.rb:357:in `block in <top (required)>'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:1675:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:1675:in `block in compile!'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:1013:in `block (3 levels) in route!'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:1032:in `route_eval'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:1013:in `block (2 levels) in route!'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:1061:in `block in process_route'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:1059:in `catch'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:1059:in `process_route'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:1011:in `block in route!'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:1008:in `each'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:1008:in `route!'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:1129:in `block in dispatch!'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:1101:in `block in invoke'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:1101:in `catch'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:1101:in `invoke'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:1124:in `dispatch!'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:939:in `block in call!'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:1101:in `block in invoke'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:1101:in `catch'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:1101:in `invoke'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:939:in `call!'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:929:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-protection-2.1.0/lib/rack/protection/xss_header.rb:18:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-protection-2.1.0/lib/rack/protection/path_traversal.rb:16:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-protection-2.1.0/lib/rack/protection/json_csrf.rb:26:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-protection-2.1.0/lib/rack/protection/base.rb:50:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-protection-2.1.0/lib/rack/protection/base.rb:50:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-protection-2.1.0/lib/rack/protection/frame_options.rb:31:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-2.2.3/lib/rack/logger.rb:17:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-2.2.3/lib/rack/common_logger.rb:38:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:253:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:246:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-2.2.3/lib/rack/head.rb:12:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-2.2.3/lib/rack/method_override.rb:24:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:216:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:1991:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:1542:in `block in call'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:1769:in `synchronize'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:1542:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-2.2.3/lib/rack/handler/webrick.rb:95:in `service'
/app/vendor/ruby-2.6.0/lib/ruby/2.6.0/webrick/httpserver.rb:140:in `service'
/app/vendor/ruby-2.6.0/lib/ruby/2.6.0/webrick/httpserver.rb:96:in `run'
/app/vendor/ruby-2.6.0/lib/ruby/2.6.0/webrick/server.rb:307:in `block in start_thread'

Please sign in to comment.