Skip to content

Commit 0902576

Browse files
authored
Merge pull request #124 from cortinico/github-actions
Setup Github Actions for preMerge
2 parents 757ec74 + 5872bc6 commit 0902576

File tree

3 files changed

+45
-7
lines changed

3 files changed

+45
-7
lines changed

.github/workflows/pre-merge.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Pre Merge Checks
2+
on: [push, pull_request]
3+
4+
jobs:
5+
gradle:
6+
strategy:
7+
matrix:
8+
os: [ubuntu-latest, macos-latest, windows-latest]
9+
runs-on: ${{ matrix.os }}
10+
steps:
11+
- name: Checkout Repo
12+
uses: actions/checkout@v1
13+
- name: Setup Python
14+
uses: actions/setup-python@v1
15+
with:
16+
python-version: 3.7.6
17+
- name: Install Python dependencies
18+
run: python -m pip install virtualenv pre-commit
19+
- name: Setup Java
20+
uses: actions/setup-java@v1
21+
with:
22+
java-version: 11
23+
- name: Run gradle preMerge task
24+
uses: eskatos/gradle-command-action@v1
25+
with:
26+
gradle-version: wrapper
27+
arguments: preMerge

.pre-commit-config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ repos:
1111
args: [--autofix, --indent, '4']
1212
exclude: ^samples/[^/]+/src/main/java/swagger.json$
1313
- id: check-yaml
14-
- id: check-executables-have-shebangs
1514
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
1615
rev: v1.3.2
1716
hooks:

build.gradle.kts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import java.nio.file.Paths
2+
13
subprojects {
24
repositories {
35
google()
@@ -9,7 +11,7 @@ subprojects {
911
val installVenv = tasks.register("installVenv", Exec::class.java) {
1012
description = "Install a new virtualenv in ./venv"
1113

12-
outputs.dir("./venv")
14+
outputs.dir(Paths.get(".", "venv"))
1315

1416
commandLine("virtualenv", "venv")
1517
}
@@ -19,28 +21,28 @@ val installPreCommit = tasks.register("installPreCommit", Exec::class.java) {
1921

2022
dependsOn(installVenv)
2123

22-
outputs.file("./venv/bin/pre-commit")
24+
outputs.file(Paths.get(".", "venv", "bin", "pre-commit"))
2325

24-
commandLine("./venv/bin/pip", "install", "pre-commit")
26+
commandLine(Paths.get(".", "venv", binFolder, "pip"), "install", "pre-commit")
2527
}
2628

2729
val installHooks = tasks.register("installHooks", Exec::class.java) {
2830
description = "Run pre-commit hooks without installing them"
2931

3032
dependsOn(installPreCommit)
3133

32-
outputs.file(".git/hooks/pre-commit")
34+
outputs.file(Paths.get(".", "venv", binFolder, "pre-commit"))
3335
inputs.file(".pre-commit-config.yaml")
3436

35-
commandLine("./venv/bin/pre-commit", "install", "--install-hooks")
37+
commandLine(Paths.get(".", "venv", binFolder, "pre-commit"), "install", "--install-hooks")
3638
}
3739

3840
val runHooks = tasks.register("runHooks", Exec::class.java) {
3941
description = "Run pre-commit hooks"
4042

4143
dependsOn(installPreCommit)
4244

43-
commandLine("./venv/bin/pre-commit", "run", "--all-files")
45+
commandLine(Paths.get(".", "venv", binFolder, "pre-commit"), "run", "--all-files")
4446
}
4547

4648
val preMerge = tasks.register("preMerge") {
@@ -69,3 +71,13 @@ subprojects {
6971
}
7072
}
7173
}
74+
75+
/**
76+
* Python `venv/bin` folder is different based on OS.
77+
* On Windows it's inside the `venv/Scripts` folder.
78+
*/
79+
val binFolder : String get() = if (System.getProperty("os.name").toLowerCase().contains("windows")) {
80+
"Scripts"
81+
} else {
82+
"bin"
83+
}

0 commit comments

Comments
 (0)