Skip to content

Commit 60c6618

Browse files
authored
Add convention plugin for publishing (#20)
1 parent 5796581 commit 60c6618

File tree

17 files changed

+281
-218
lines changed

17 files changed

+281
-218
lines changed

.github/workflows/ci-build.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ on:
55
paths-ignore:
66
- '**.md'
77

8+
concurrency:
9+
group: ci-${{ github.ref }}
10+
cancel-in-progress: true
11+
812
env:
913
NEXUS_USER: ${{ secrets.NEXUS_USER }}
1014
NEXUS_PASS: ${{ secrets.NEXUS_PASS }}

README.md

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
# Gradle Semver Plugin
22

3-
* [Overview](#overview)
4-
* [Version Calculation](#version-calculation)
5-
* [Branch Matching Strategy](#branch-matching-strategy)
6-
* [Usage](#usage)
7-
* [Plugin Extension Properties](#plugin-extension-properties)
8-
* [Plugin Tasks](#plugin-tasks)
9-
* [Using with CI/CD](#using-with-cicd)
10-
* [Unsupported](#not-supported)
3+
Welcome to the gradle-semver-plugin!
4+
This plugin adds a flexible approach to adding semantic versioning to your gradle project.
5+
It supports multi-module gradle projects, running in CI, and multiple types of git strategies.
116

12-
## Overview
137

14-
A Gradle plugin with a flexible approach to generating semantic versions, typically for use within a Gradle project. It supports running under Github Actions.
158

9+
- [Version Calculation](#version-calculation)
10+
- [Branch Matching Strategy](#branch-matching-strategy)
11+
- [Usage](#usage)
12+
- [Plugin Extension Properties](#plugin-extension-properties)
13+
- [Plugin Tasks](#plugin-tasks)
14+
- [Using with CI](#using-with-ci)
15+
- [Unsupported](#not-supported)
16+
17+
## Overview
1618
It comes bundled with a single Version Calculator that implements a target branch calculator: the version of the current branch is based on the latest version of the branch it targets, eg `develop` is branched from `main`, thus the version of `develop` is based on the current version of `main`.
1719

1820
The Target Branch Version Calculator includes two Branch Matching strategies:
19-
-Flow - broadly based on a [Git Flow workflow](https://nvie.com/posts/a-successful-git-branching-model/) without release branches, the following branches are supported:
21+
- `Flow` - Broadly based on a [Git Flow workflow](https://nvie.com/posts/a-successful-git-branching-model/) without release branches, the following branches are supported:
2022

2123
| branch | pre release label | target branch | example |
2224
|--------------------------|-------------------|---------------|------------------------|
@@ -25,29 +27,30 @@ The Target Branch Version Calculator includes two Branch Matching strategies:
2527
| `hotfix/badthings` | rc | main | 1.2.4-rc.2 |
2628
| `xxx` | xxx | develop | 1.2.5-xxx.13 |
2729

28-
- Flat - ideal for simpler projects without an integration branch such as `develop`:
30+
- `Flat` - Ideal for projects using a single branch strategy with `main`.
2931

3032
| branch | pre release label | target branch | example |
3133
|--------|-------------------|---------------|--------------|
3234
| `main` | | main | 1.2.3 |
3335
| `xxx` | xxx | main | 1.2.4-xxx.13 |
3436

35-
The `Flow` strategy is automatically selected if a `develop` branch is present, otherwise the `Flat` strategy is selected.
37+
38+
By default, the `Flow` strategy is selected if a `develop` branch is present, otherwise the `Flat` strategy will be used.
3639

3740
## Version Calculation
3841

3942
The semver is calculated primarily based on:
40-
* the version of the target branch
41-
* the current branch
42-
* the branchMatching strategy
43+
- The version of the target branch
44+
- The current branch
45+
- The branchMatching strategy
4346

4447
## Branch Matching Strategy
4548

4649
A Strategy contains a list of `BranchMatchingConfiguration` instances which are applied in order until the first match is reached, it contains the following properties:
47-
* branch name regex
48-
* target branch
49-
* version modifier: modifies the major, minor or patch components of the semver
50-
* version qualifier: optionally qualifies the semver with a prerelease label and build metadata
50+
- branch name regex
51+
- target branch
52+
- version modifier: modifies the major, minor or patch components of the semver
53+
- version qualifier: optionally qualifies the semver with a prerelease label and build metadata
5154

5255
The `VersionModifier` can be set for every `BranchMatchingConfiguration` instance in the strategy with the plugin extension:
5356

@@ -108,18 +111,19 @@ semver {
108111
_**PLEASE NOTE:**_ the `semver` stanza should be declared **before** the `semver` extension functions are used.
109112

110113
## Plugin Extension Properties
111-
* `version: String` returns the calculated version
112-
* `versionTagName: String` returns the tag name for the current calculated version, ie `tagPrefix` + `version`
114+
- `version: String` returns the calculated version
115+
- `versionTagName: String` returns the tag name for the current calculated version, ie `tagPrefix` + `version`
113116

114117
## Plugin Tasks
115-
* `cv` that will print out the current calculated version
116-
* `generateVersionFile` will generate `build/semver/version.txt` containing the raw version and the tag version
117-
* `createAndPushVersionTag` will create a tag from `semver.versionTagName` and push the tag to the remote repo, take care to use `:createAndPushVersionTag` in a multi module project otherwise it will attempt to create duplicates
118+
- `cv` that will print out the current calculated version
119+
- `generateVersionFile` will generate `build/semver/version.txt` containing the raw version and the tag version
120+
- `createAndPushVersionTag` will create a tag from `semver.versionTagName` and push the tag to the remote repo, take care to use `:createAndPushVersionTag` in a multi module project otherwise it will attempt to create duplicates
118121

119-
## Using with CI/CD
122+
## Using with CI
120123

121-
Make sure to check out all branches & tags, eg using GitHub Actions:
124+
When using this plugin in CI check out all branches & tags to ensure an accurate version calculation.
122125

126+
GitHub Actions Example:
123127
```yaml
124128
- name: Checkout
125129
uses: actions/checkout@v3
@@ -128,4 +132,4 @@ Make sure to check out all branches & tags, eg using GitHub Actions:
128132
```
129133
130134
## Not Supported
131-
* Discrete versions for subprojects, all subprojects are calculated with the same version
135+
- Discrete versions for subprojects, all subprojects are calculated with the same version
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
plugins {
2+
`kotlin-dsl`
3+
}
4+
5+
repositories {
6+
gradlePluginPortal() // so that external plugins can be resolved in dependencies section
7+
}
8+
9+
dependencies {
10+
// note: this `libs` is from build-logic/settings.gradle.kts, technically different from the 'main' project
11+
implementation(libs.gradle.plugin.publish)
12+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import org.gradle.kotlin.dsl.`java-gradle-plugin`
2+
3+
plugins {
4+
`maven-publish`
5+
`java-gradle-plugin`
6+
id("com.gradle.plugin-publish")
7+
}
8+
9+
/*
10+
* Project information
11+
*/
12+
group = "com.figure.gradle"
13+
description = "Gradle Plugin for Automated Semantic Versioning"
14+
15+
inner class ProjectInfo {
16+
val longName = "Gradle Semver Plugin"
17+
val description = "Gradle Plugin for Automated Semantic Versioning"
18+
val pluginImplementationClass = "$group.semver.SemverPlugin"
19+
val tags = listOf("semver", "gradle", "gitflow", "gitubflow")
20+
val website = "https://github.com/FigureTechnologies/gradle-semver-plugin"
21+
val vcsURL = "https://github.com/FigureTechnologies/gradle-semver-plugin.git"
22+
}
23+
val info = ProjectInfo()
24+
25+
/**
26+
* Eventually we will be able to merge the pluginBundle and gradlePlugin section.
27+
* Unfortunately, we can't do that gradle 7.6 is out, so we wait.
28+
*
29+
* Gradle 8+ will remove the pluginBundle
30+
* Link: https://plugins.gradle.org/docs/publish-plugin-new
31+
*/
32+
33+
// I think this is specifically for the gradle portal
34+
pluginBundle {
35+
website = info.website
36+
vcsUrl = info.vcsURL
37+
tags = info.tags
38+
39+
// shared description
40+
// description = info.description
41+
}
42+
43+
gradlePlugin {
44+
45+
plugins {
46+
create(project.name) {
47+
id = "$group.${project.name}"
48+
displayName = info.longName
49+
description = info.description
50+
implementationClass = info.pluginImplementationClass
51+
}
52+
}
53+
}
54+
55+
publishing {
56+
repositories {
57+
maven {
58+
url = uri("https://nexus.figure.com/repository/figure")
59+
credentials {
60+
username = System.getenv("NEXUS_USER")
61+
password = System.getenv("NEXUS_PASS")
62+
}
63+
}
64+
}
65+
publications {
66+
create<MavenPublication>("mavenJava") {
67+
pom {
68+
// This line is what includes the java{} block, aka javadocs and sources
69+
from(components["java"])
70+
71+
name.set(info.longName)
72+
description.set(info.description)
73+
url.set(info.website)
74+
licenses {
75+
license {
76+
name.set("The Apache License, Version 2.0")
77+
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
78+
}
79+
}
80+
developers {
81+
developer {
82+
id.set("ahatzz11")
83+
name.set("Alex Hatzenbuhler")
84+
email.set("[email protected]")
85+
}
86+
developer {
87+
id.set("happyphan")
88+
name.set("Emily Harris")
89+
email.set("[email protected]")
90+
}
91+
developer {
92+
id.set("luinstra")
93+
name.set("Jeremy Luinstra")
94+
email.set("[email protected]")
95+
}
96+
developer {
97+
id.set("jonasg13")
98+
name.set("Jonas Gorauskas")
99+
email.set("[email protected]")
100+
}
101+
}
102+
scm {
103+
connection.set("scm:git:git://github.com/FigureTechnologies/gradle-semver-plugin.git")
104+
developerConnection.set("scm:git:ssh://github.com/FigureTechnologies/gradle-semver-plugin.git")
105+
url.set(info.website)
106+
}
107+
}
108+
}
109+
}
110+
}

build-logic/settings.gradle.kts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
2+
enableFeaturePreview("VERSION_CATALOGS")
3+
4+
// This is for the kotlin-dsl
5+
dependencyResolutionManagement {
6+
repositories {
7+
mavenLocal()
8+
mavenCentral()
9+
10+
gradlePluginPortal() // so that external plugins can be resolved in dependencies section
11+
}
12+
13+
// kinda hacky way to make a catalog from our own catalog, but it works!
14+
// Link: https://github.com/gradle/gradle/issues/15383#issuecomment-779893192
15+
versionCatalogs {
16+
create("libs") {
17+
from(files("../gradle/libs.versions.toml"))
18+
}
19+
}
20+
}
21+
22+
plugins {
23+
24+
}
25+
26+
include("build-conventions")

0 commit comments

Comments
 (0)