Skip to content

Commit edb9ce5

Browse files
committed
feat: add commit.timestamp.year.2digit placeholder
1 parent 13e21ab commit edb9ce5

File tree

4 files changed

+64
-88
lines changed

4 files changed

+64
-88
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 7.1.0
4+
5+
##### Features
6+
* New Placeholder `${commit.timestamp.year.2digit}`
7+
8+
39
## 5.0.0
410

511
##### Features

README.md

Lines changed: 56 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ This extension can virtually set project version and properties, based on curren
2929

3030
```groovy
3131
plugins {
32-
id 'me.qoomon.git-versioning' version '5.0.0'
32+
id 'me.qoomon.git-versioning' version '5.1.0'
3333
}
3434
3535
version = '0.0.0-SNAPSHOT'
@@ -42,7 +42,7 @@ gitVersioning.apply {
4242

4343
```kotlin
4444
plugins {
45-
id("me.qoomon.git-versioning") version "5.0.0"
45+
id("me.qoomon.git-versioning") version "5.1.0"
4646
}
4747

4848

@@ -153,23 +153,16 @@ e.g `${dirty:-SNAPSHOT}` resolves to `-SNAPSHOT` instead of `-DIRTY`
153153

154154
###### Placeholders
155155

156-
- `${env.VARIABLE}`
157-
- Value of environment variable `VARIABLE`
158-
- `${property.name}`
159-
- Value of commandline property `-Pname=value`
160-
<br><br>
161-
162-
- `${version}`
163-
- project `version` (probably set in `build.gradle`)
164-
- e.g. '1.0.0-SNAPSHOT'
165-
- `${version.release}`
166-
- like `${version}` without `-SNAPSHOT` postfix
167-
- e.g. '1.0.0'
168-
<br><br>
169-
170-
- `${ref}` `${ref.slug}`
171-
- HEAD ref name (branch or tag name or commit hash)
172-
- `Ref Pattern Groups`
156+
- `${env.VARIABLE}` Value of environment variable `VARIABLE`
157+
- `${property.name}` Value of commandline property `-Pname=value`
158+
<br><br>
159+
160+
- `${version}` `<version>` set in `pom.xml` e.g. '1.0.0-SNAPSHOT'
161+
- `${version.release}` like `${version}` without `-SNAPSHOT` postfix e.g. '1.0.0'
162+
<br><br>
163+
164+
- `${ref}` `${ref.slug}` ref name (branch or tag name or commit hash)
165+
- Ref Pattern Groups
173166
- Content of regex groups in branch/tag `pattern` can be addressed like this:
174167
- `${ref.GROUP_NAME}` `${ref.GROUP_NAME.slug}`
175168
- `${ref.GROUP_INDEX}` `${ref.GROUP_INDEX.slug}`
@@ -189,76 +182,52 @@ e.g `${dirty:-SNAPSHOT}` resolves to `-SNAPSHOT` instead of `-DIRTY`
189182
```
190183
<br>
191184
192-
- `${commit}`
193-
- The `HEAD` commit hash
194-
- e.g. '0fc20459a8eceb2c4abb9bf0af45a6e8af17b94b'
195-
- `${commit.short}`
196-
- The short `HEAD` commit hash (7 characters)
197-
- e.g. '0fc2045'
198-
- `${commit.timestamp}`
199-
- The `HEAD` commit timestamp (epoch seconds)
200-
- e.g. '1560694278'
201-
- `${commit.timestamp.year}`
202-
- The `HEAD` commit year
203-
- e.g. '2021'
204-
- `${commit.timestamp.month}`
205-
- The `HEAD` commit month of year
206-
- e.g. '01'
207-
- `${commit.timestamp.day}`
208-
- The `HEAD` commit day of month
209-
- e.g. '01'
210-
- `${commit.timestamp.hour}`
211-
- The `HEAD` commit hour of day (24h)
212-
- e.g. '01'
213-
- `${commit.timestamp.minute}`
214-
- The `HEAD` commit minute of hour
215-
- e.g. '01'
216-
- `${commit.timestamp.second}`
217-
- The `HEAD` commit second of minute
218-
- e.g. '01'
219-
- `${commit.timestamp.datetime}`
220-
- The `HEAD` commit timestamp formatted as `yyyyMMdd.HHmmss`
221-
- e.g. '20190616.161442'
222-
<br><br>
223-
224-
- `${describe}`
225-
- Will resolve to `git describe` output
226-
- ⚠️ Can lead to performance issue on projects with a lot of tags
227-
- `${describe.distance}`
228-
- The distance count to last matching tag
229-
- `${describe.tag}`
230-
- The matching tag of `git describe`
231-
- Describe Tag Pattern Groups
232-
- Content of regex groups in `describeTagPattern` can be addressed like this:
233-
- `${describe.tag.GROUP_NAME}` `${describe.tag.GROUP_NAME.slug}`
234-
- `${describe.tag.GROUP_INDEX}` `${describe.tag.GROUP_INDEX.slug}`
235-
- Named Group Example
236-
237-
**groovy**
238-
```groovy
239-
branch('main') {
240-
describeTagPattern = 'v(?<version>.*)'
241-
version = '${ref.feature}-SNAPSHOT'
242-
}
243-
```
244-
**kotlin**
245-
```kotlin
246-
branch("main") {
247-
describeTagPattern = "v(?<version>.*)"
248-
version = "\${describe.tag.version}-SNAPSHOT"
249-
}
250-
```
251-
<br>
252-
253-
- `${dirty}`
254-
- If repository has untracked files or uncommitted changes this placeholder will resolve to `-DIRTY`, otherwise it will resolve to an empty string.
185+
- `${commit}` commit hash '0fc20459a8eceb2c4abb9bf0af45a6e8af17b94b'
186+
- `${commit.short}` commit hash (7 characters) e.g. '0fc2045'
187+
- `${commit.timestamp}` commit timestamp (epoch seconds) e.g. '1560694278'
188+
- `${commit.timestamp.year}` commit year e.g. '2021'
189+
- `${commit.timestamp.year.2digit}` 2-digit commit year.g. '21'
190+
- `${commit.timestamp.month}` commit month of year e.g. '12'
191+
- `${commit.timestamp.day}` commit day of month e.g. '23'
192+
- `${commit.timestamp.hour}` commit hour of day (24h)e.g. '13'
193+
- `${commit.timestamp.minute}` commit minute of hour e.g. '59'
194+
- `${commit.timestamp.second}` commit second of minute e.g. '30'
195+
- `${commit.timestamp.datetime}` commit timestamp formatted as `yyyyMMdd.HHmmss`e.g. '20190616.161442'
196+
<br><br>
197+
198+
- `${describe}` Will resolve to `git describe` output
199+
- ⚠️ `${describe....}` placeholders can lead to performance issue on projects with a lot of tags
200+
- `${describe.distance}` The distance count to last matching tag
201+
- `${describe.tag}` The matching tag of `git describe`
202+
- Describe Tag Pattern Groups
203+
- Content of regex groups in `describeTagPattern` can be addressed like this:
204+
- `${describe.tag.GROUP_NAME}` `${describe.tag.GROUP_NAME.slug}`
205+
- `${describe.tag.GROUP_INDEX}` `${describe.tag.GROUP_INDEX.slug}`
206+
- Named Group Example
207+
208+
**groovy**
209+
```groovy
210+
branch('main') {
211+
describeTagPattern = 'v(?<version>.*)'
212+
version = '${ref.feature}-SNAPSHOT'
213+
}
214+
```
215+
**kotlin**
216+
```kotlin
217+
branch("main") {
218+
describeTagPattern = "v(?<version>.*)"
219+
version = "\${describe.tag.version}-SNAPSHOT"
220+
}
221+
```
222+
<br>
223+
224+
- `${dirty}` If repository has untracked files or uncommitted changes this placeholder will resolve to `-DIRTY`, otherwise it will resolve to an empty string.
255225
- ⚠️ Can lead to performance issue on very large projects
256-
- `${dirty.snapshot}`
257-
- Like `${dirty}`, but will resolve to `-SNAPSHOT`
258-
<br><br>
226+
- `${dirty.snapshot}` Like `${dirty}`, but will resolve to `-SNAPSHOT`
227+
<br><br>
228+
229+
- `${value}` Original value of matching property (Only available within property format)
259230
260-
- `${value}` - Only available within property format
261-
- Original value of matching property
262231
263232
### Parameters & Environment Variables
264233

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ plugins {
1212
}
1313

1414
group 'me.qoomon'
15-
version '5.0.0'
15+
version '5.1.0'
1616

1717
sourceCompatibility = JavaVersion.VERSION_1_8
1818
targetCompatibility = JavaVersion.VERSION_1_8

src/main/java/me/qoomon/gradle/gitversioning/GitVersioningPluginExtension.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ private Map<String, Supplier<String>> generateGlobalFormatPlaceholderMap(GitSitu
467467
final Lazy<ZonedDateTime> headCommitDateTime = Lazy.by(gitSituation::getTimestamp);
468468
placeholderMap.put("commit.timestamp", Lazy.by(() -> String.valueOf(headCommitDateTime.get().toEpochSecond())));
469469
placeholderMap.put("commit.timestamp.year", Lazy.by(() -> String.valueOf(headCommitDateTime.get().getYear())));
470+
placeholderMap.put("commit.timestamp.year.2digit", Lazy.by(() -> String.valueOf(headCommitDateTime.get().getYear() % 100)));
470471
placeholderMap.put("commit.timestamp.month", Lazy.by(() -> leftPad(String.valueOf(headCommitDateTime.get().getMonthValue()), 2, "0")));
471472
placeholderMap.put("commit.timestamp.day", Lazy.by(() -> leftPad(String.valueOf(headCommitDateTime.get().getDayOfMonth()), 2, "0")));
472473
placeholderMap.put("commit.timestamp.hour", Lazy.by(() -> leftPad(String.valueOf(headCommitDateTime.get().getHour()), 2, "0")));

0 commit comments

Comments
 (0)