Skip to content

Commit 505efd3

Browse files
committed
Initial implementation
This is a scaled-back implementation of binks. Not all features were brought forward. Checks for dirty tree, and version tag existence. This version does not validate version format.
1 parent ae1373e commit 505efd3

12 files changed

Lines changed: 218 additions & 137 deletions

File tree

.vogue.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
packageRules:
2+
-
3+
package: "com.github.mxenabled.binks"
4+
rules:
5+
major:
6+
requireLatest: false
7+
minor:
8+
requireLatest: false
9+
patch:
10+
requireLatest: false

README.md

Lines changed: 14 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -2,99 +2,30 @@
22

33
# Binks
44

5-
Ruby command line utilty for managing jar (currently only supports maven) deployments via Gitlab pipelines.
6-
7-
Works by doing the following:
8-
9-
* Parse version out of ./pom.xml
10-
* Validate the version
11-
* Apply and push git tag for version (which launches the deploy pipeline)
12-
135
### Installation
146

15-
Binks can be used in two ways -- as a standalone binary or rake task add-in
16-
17-
#### Add Raketasks
18-
19-
Add the following to Gemfile:
20-
21-
```ruby
22-
source "https://artifactory.internal.mx/api/gems/gems.internal.mx/" do
23-
gem "binks"
24-
end
25-
```
26-
27-
Add the following to Rakefile
28-
29-
```ruby
30-
require "binks/rake_task"
7+
```groovy
8+
plugins {
9+
id "com.github.mxenabled.binks" version "[VERSION]"
10+
}
3111
```
3212

3313
### Usage
3414

35-
#### As a rake task
36-
37-
Regular release (from master)
38-
```shell
39-
rake release
40-
```
41-
42-
Force retag
43-
```shell
44-
rake release -- -f
45-
```
46-
47-
#### As a binary
48-
49-
Regular release (from master)
50-
```shell
51-
binks release
5215
```
53-
54-
Force retag
55-
```shell
56-
binks release -f
16+
./gradlew release
5717
```
5818

59-
### Contributing
60-
61-
See [process wiki page](https://gitlab.mx.com/mx/io/wikis/Gems) for details on updating a gem.
62-
63-
1. Create your feature branch (`git checkout -b my-new-feature`)
64-
3. Commit your changes (`git commit -am 'Add some feature'`)
65-
4. Push to the branch (`git push origin my-new-feature`)
66-
5. Create new Pull Request
67-
68-
### Versioning
69-
70-
Clone the repo and create a topic branch. Generate a merge request. Once approved, merge to master. In master bump the gem version. To maintain some semblance of sanity, slight modifications should result in point bump (e.g. 0.1.0 to 0.1.1) and more significant changes like new messages or endpoints should result in a minor bump (e.g. 0.1.1 to 0.2.0).
71-
72-
**Please commit your version bump separately from your other changes.** It makes it much easier to track down when versions changed and what changes are in each version.
73-
74-
After committing and pushing the version change, run:
75-
76-
```shell
77-
rake release
19+
Just run validation on current version
7820
```
79-
80-
If prompted for an `Email` and `Password`, use your `username` and `api_key`
81-
(respectively) for artifactory:
82-
https://artifactory.internal.mx/ui/admin/artifactory/user_profile
83-
84-
For example:
85-
86-
```
87-
Email: bob.ross
88-
Password: QctLW6hhgk+QSID3F4hG8tNwNIgDKYCWcL1ElVkJD74gW6iZFbYFnghzGlt4m3iV7TzOgmY3hW+GdsNnFxG2Jg
21+
./gradlew release --check-only
8922
```
9023

91-
to push the gem to `gems.internal.mx`
92-
93-
## Dependencies
94-
95-
* [Thor](http://whatisthor.com/)
96-
* [Maven](https://maven.apache.org/)
97-
98-
## Future Enhancements
24+
#### Arguments
9925

100-
Look implementing something like [thor-scmversion](https://github.com/RiotGamesMinions/thor-scmversion) with version bump actions
26+
| Arg | Description |
27+
|-------------------|-----------------------------------------------------------------|
28+
| check-only | Skip apply tag and push. Will still do validations |
29+
| force | Skip version existence check and force more tag to current hash |
30+
| ignore-dirty-tree | Don't fail if git tree is dirty |
31+
| refresh-tags | Removes all local tags and fetches tags from origin |

build.gradle

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
plugins {
22
id "com.github.mxenabled.coppuccino" version "2.0.0"
3+
id "com.github.mxenabled.vogue" version "1.0.1"
4+
id "com.github.mxenabled.hush" version "1.0.6"
5+
// id "com.github.mxenabled.binks" version "0.0.1"
6+
// id "com.mx.binks" version "0.0.1" // for local testing
37
id "groovy"
48
id "java"
59
id "maven-publish"
610
id "java-gradle-plugin"
7-
id "org.jetbrains.kotlin.jvm" version "1.6.10"
11+
id "org.jetbrains.kotlin.jvm" version "1.7.10"
812
}
913

1014
group "com.mx.binks"
@@ -20,10 +24,7 @@ repositories {
2024

2125
dependencies {
2226
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
23-
24-
// implementation "com.google.code.gson:gson:2.+"
25-
// implementation "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.13.3"
26-
// implementation "com.github.ben-manes.versions:com.github.ben-manes.versions.gradle.plugin:0.42.0"
27+
implementation "com.lordcodes.turtle:turtle:0.7.0" // Provides git and commandline interaction API
2728

2829
constraints {
2930
implementation ("com.thoughtworks.xstream:xstream:1.4.19") { because "It resolves a bajillion CVEs" }
@@ -53,10 +54,7 @@ compileKotlin { kotlinOptions { jvmTarget = "1.8" } }
5354

5455
compileTestKotlin { kotlinOptions { jvmTarget = "1.8" } }
5556

56-
coppuccino {
57-
kotlin { enabled = true }
58-
coverage { minimumCoverage = 0.01 }
59-
}
57+
coppuccino { kotlin { enabled = true } }
6058

6159
sourceSets {
6260
test { groovy { srcDirs "src/test/groovy" } }

dependency_suppression.xml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,3 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<suppressions xmlns="https://jeremylong.github.io/DependencyCheck/dependency-suppression.1.3.xsd">
3-
<suppress>
4-
<notes>This plugin is not used in runtime code, so we are safe to suppress these.</notes>
5-
<cpe>cpe:/a:gradle:gradle</cpe>
6-
<cpe>cpe:/a:jetbrains:kotlin</cpe>
7-
<cve>CVE-2021-29425</cve>
8-
<cve>CVE-2021-35517</cve>
9-
<cve>CVE-2021-35516</cve>
10-
<cve>CVE-2021-35515</cve>
11-
<cve>CVE-2021-36090</cve>
12-
<cve>CVE-2020-36518</cve> <!-- False Positive -->
13-
</suppress>
14-
<suppress>
15-
<notes>GSON false positive. We are on an unaffected version.</notes>
16-
<cve>CVE-2022-25647</cve>
17-
</suppress>
183
</suppressions>

gradle.lockfile

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# This file is expected to be part of source control.
44
cglib:cglib-nodep:3.3.0=testRuntimeClasspath
55
com.beust:jcommander:1.78=detekt
6+
com.lordcodes.turtle:turtle:0.7.0=compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
67
io.gitlab.arturbosch.detekt:detekt-api:1.10.0=detekt
78
io.gitlab.arturbosch.detekt:detekt-cli:1.10.0=detekt
89
io.gitlab.arturbosch.detekt:detekt-core:1.10.0=detekt
@@ -24,28 +25,29 @@ org.jacoco:org.jacoco.agent:0.8.7=jacocoAgent,jacocoAnt
2425
org.jacoco:org.jacoco.ant:0.8.7=jacocoAnt
2526
org.jacoco:org.jacoco.core:0.8.7=jacocoAnt
2627
org.jacoco:org.jacoco.report:0.8.7=jacocoAnt
27-
org.jetbrains.intellij.deps:trove4j:1.0.20181211=detekt,kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
28+
org.jetbrains.intellij.deps:trove4j:1.0.20181211=detekt
29+
org.jetbrains.intellij.deps:trove4j:1.0.20200330=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
2830
org.jetbrains.kotlin:kotlin-compiler-embeddable:1.3.72=detekt
29-
org.jetbrains.kotlin:kotlin-compiler-embeddable:1.6.10=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
31+
org.jetbrains.kotlin:kotlin-compiler-embeddable:1.7.10=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
3032
org.jetbrains.kotlin:kotlin-daemon-embeddable:1.3.72=detekt
31-
org.jetbrains.kotlin:kotlin-daemon-embeddable:1.6.10=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
32-
org.jetbrains.kotlin:kotlin-klib-commonizer-embeddable:1.6.10=kotlinKlibCommonizerClasspath
33+
org.jetbrains.kotlin:kotlin-daemon-embeddable:1.7.10=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
34+
org.jetbrains.kotlin:kotlin-klib-commonizer-embeddable:1.7.10=kotlinKlibCommonizerClasspath
3335
org.jetbrains.kotlin:kotlin-reflect:1.3.72=detekt
34-
org.jetbrains.kotlin:kotlin-reflect:1.6.10=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
36+
org.jetbrains.kotlin:kotlin-reflect:1.7.10=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
3537
org.jetbrains.kotlin:kotlin-script-runtime:1.3.72=detekt
36-
org.jetbrains.kotlin:kotlin-script-runtime:1.6.10=kotlinCompilerClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath
37-
org.jetbrains.kotlin:kotlin-scripting-common:1.6.10=kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest
38-
org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable:1.6.10=kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest
39-
org.jetbrains.kotlin:kotlin-scripting-compiler-impl-embeddable:1.6.10=kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest
40-
org.jetbrains.kotlin:kotlin-scripting-jvm:1.6.10=kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest
38+
org.jetbrains.kotlin:kotlin-script-runtime:1.7.10=kotlinCompilerClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath
39+
org.jetbrains.kotlin:kotlin-scripting-common:1.7.10=kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest
40+
org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable:1.7.10=kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest
41+
org.jetbrains.kotlin:kotlin-scripting-compiler-impl-embeddable:1.7.10=kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest
42+
org.jetbrains.kotlin:kotlin-scripting-jvm:1.7.10=kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest
4143
org.jetbrains.kotlin:kotlin-stdlib-common:1.3.72=detekt
42-
org.jetbrains.kotlin:kotlin-stdlib-common:1.6.10=compileClasspath,implementationDependenciesMetadata,kotlinCompilerClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
44+
org.jetbrains.kotlin:kotlin-stdlib-common:1.7.10=compileClasspath,implementationDependenciesMetadata,kotlinCompilerClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
4345
org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.72=detekt
44-
org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.10=compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
46+
org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.10=compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
4547
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.72=detekt
46-
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.10=compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
48+
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.10=compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
4749
org.jetbrains.kotlin:kotlin-stdlib:1.3.72=detekt
48-
org.jetbrains.kotlin:kotlin-stdlib:1.6.10=compileClasspath,implementationDependenciesMetadata,kotlinCompilerClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
50+
org.jetbrains.kotlin:kotlin-stdlib:1.7.10=compileClasspath,implementationDependenciesMetadata,kotlinCompilerClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
4951
org.jetbrains.kotlinx:kotlinx-html-common:0.7.1=detekt
5052
org.jetbrains.kotlinx:kotlinx-html-jvm:0.7.1=detekt
5153
org.jetbrains:annotations:13.0=compileClasspath,detekt,implementationDependenciesMetadata,kotlinCompilerClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata

src/main/kotlin/com/mx/binks/BinksExtension.kt

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/main/kotlin/com/mx/binks/BinksPlugin.kt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,6 @@ import org.gradle.api.Project
66
class BinksPlugin : Plugin<Project> {
77
@Suppress("MaxLineLength")
88
override fun apply(project: Project) {
9-
var dependenciesExtension = project.extensions.create("binks", BinksExtension::class.java)
10-
11-
project.afterEvaluate {
12-
}
13-
14-
project.tasks.register("release") { task ->
15-
task.doLast {
16-
println("Released")
17-
}
18-
}
9+
project.tasks.register("release", ReleaseTask::class.java)
1910
}
2011
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package com.mx.binks
2+
3+
import com.mx.binks.core.Git
4+
import com.mx.binks.core.cyan
5+
import com.mx.binks.core.exceptions.ReleaseError
6+
import com.mx.binks.core.green
7+
import com.mx.binks.core.red
8+
import com.mx.binks.core.yellow
9+
import org.gradle.api.DefaultTask
10+
import org.gradle.api.tasks.Input
11+
import org.gradle.api.tasks.TaskAction
12+
import org.gradle.api.tasks.options.Option
13+
14+
@Suppress("UnstableApiUsage")
15+
open class ReleaseTask : DefaultTask() {
16+
init {
17+
description = "Validate and push version tag to launch release pipeline."
18+
group = "Publishing"
19+
}
20+
21+
@set:Option(
22+
option = "check-only",
23+
description = "Does a dry run. Just check the version. Don't tag or push."
24+
)
25+
@get:Input
26+
var checkOnly: Boolean = false
27+
28+
@set:Option(
29+
option = "force",
30+
description = "Force tag. Moves existing tag to current hash"
31+
)
32+
33+
@get:Input
34+
var force: Boolean = false
35+
36+
@set:Option(
37+
option = "ignore-dirty-tree",
38+
description = "Don't check for dirty tree. Release with uncommitted changes."
39+
)
40+
@get:Input
41+
var ignoreDirtyTree: Boolean = false
42+
43+
@set:Option(
44+
option = "refresh-tags",
45+
description = "Clean out all local tags and fetch from origin"
46+
)
47+
@get:Input
48+
var refreshTags: Boolean = false
49+
50+
@TaskAction
51+
fun release() {
52+
if (!ignoreDirtyTree && Git(false).isDirty()) {
53+
throw ReleaseError("${red("You'sa in big doodoo, dis time!")}\n${yellow("Dirty git tree. Commit your changes or use --ignore-dirty-tree")}")
54+
}
55+
56+
if (refreshTags) {
57+
Git(true).deleteLocalTags()
58+
}
59+
60+
val branch = Git(false).currentBranch()
61+
val version = project.version.toString()
62+
val tags = Git(false).allTags()
63+
64+
if (!force && tags.contains(project.version.toString())) {
65+
println(cyan("Existing tags:"))
66+
for (tag in tags) {
67+
if (tag == version) {
68+
println(red("> $tag"))
69+
} else {
70+
println(cyan(tag))
71+
}
72+
}
73+
throw ReleaseError(
74+
"${
75+
red("You'sa in big doodoo, dis time!")
76+
}\n${
77+
yellow("Version ($version) already in use. Change the version or use --force")
78+
}"
79+
)
80+
}
81+
82+
if (!checkOnly) {
83+
Git(true).applyTag(version, force)
84+
Git(true).pushTag(version, force)
85+
}
86+
87+
println(green("Released $version from $branch${if (checkOnly) " (DRY RUN)" else ""}"))
88+
}
89+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.mx.binks.core
2+
3+
private const val ESC = "\u001B"
4+
private const val CYAN =
5+
"""$ESC[36m"""
6+
private const val RED =
7+
"""$ESC[31m"""
8+
private const val GREEN =
9+
"""$ESC[32m"""
10+
private const val YELLOW =
11+
"""$ESC[33m"""
12+
private const val NO_COLOR =
13+
"""$ESC[0m"""
14+
15+
fun cyan(text: String): String {
16+
return "$CYAN$text$NO_COLOR"
17+
}
18+
19+
fun red(text: String): String {
20+
return "$RED$text$NO_COLOR"
21+
}
22+
23+
fun green(text: String): String {
24+
return "$GREEN$text$NO_COLOR"
25+
}
26+
27+
fun yellow(text: String): String {
28+
return "$YELLOW$text$NO_COLOR"
29+
}

0 commit comments

Comments
 (0)