Skip to content

Commit fd5b0e4

Browse files
authored
Update version in examples after Maven Central (#81)
Update library version and groupId in README and all examples, following the move from JitPack to Maven Central. Also write a workflow to do this automatically when new version (tag) is released.
1 parent 637c999 commit fd5b0e4

File tree

11 files changed

+137
-34
lines changed

11 files changed

+137
-34
lines changed

.github/scripts/replace_string.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env python3
2+
3+
import argparse
4+
from pathlib import Path
5+
6+
def main() -> None:
7+
parser = argparse.ArgumentParser()
8+
parser.add_argument("path", type=Path, help="Path to root directory")
9+
parser.add_argument("old_string", type=str, help="Old string to be replaced")
10+
parser.add_argument("new_string", type=str, help="New string to replace old string")
11+
args = parser.parse_args()
12+
replace_string(args.path, args.old_string, args.new_string)
13+
14+
15+
def replace_string(path: Path, old_string: str, new_string: str) -> None:
16+
for file in path.glob('**/*'):
17+
if file.is_file():
18+
text = file.read_text()
19+
text = text.replace(old_string, new_string)
20+
file.write_text(text)
21+
22+
23+
if __name__ == "__main__":
24+
main()
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env python3
2+
3+
import unittest
4+
from pathlib import Path
5+
from shutil import copytree
6+
from tempfile import TemporaryDirectory
7+
from replace_string import replace_string
8+
9+
TEST_RESOURCES = Path(__file__).parent / 'test_resources'
10+
11+
class TestReplaceString(unittest.TestCase):
12+
13+
def test_replace_string(self):
14+
old = '0.17.0'
15+
new = '0.17.1'
16+
files = ('README.md', 'build.gradle.kts', 'notebook.ipynb')
17+
with TemporaryDirectory() as temp_dir:
18+
dir = Path(temp_dir) / 'resources'
19+
copytree(TEST_RESOURCES, dir)
20+
replace_string(dir, old, new)
21+
for file in files:
22+
self.assert_replaced(dir / file, old, new)
23+
24+
def assert_replaced(self, file, old, new):
25+
content = file.read_text()
26+
self.assertIn(new, content)
27+
self.assertNotIn(old, content)
28+
29+
if __name__ == "__main__":
30+
unittest.main()
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Title
2+
3+
[![Maven Central](https://img.shields.io/badge/Maven%20Central-0.17.0-blue)][14]
4+
5+
```kotlin
6+
@file:DependsOn("com.gabrielfeo:gradle-enterprise-api-kotlin:0.17.0")
7+
```
8+
9+
```kotlin
10+
implementation("com.gabrielfeo:gradle-enterprise-api-kotlin:0.17.0")
11+
```
12+
13+
```
14+
%use gradle-enterprise-api-kotlin(version=0.17.0)
15+
```
16+
17+
[14]: https://central.sonatype.com/artifact/com.gabrielfeo/gradle-enterprise-api-kotlin/0.17.0
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dependencies {
2+
implementation("com.gabrielfeo:gradle-enterprise-api-kotlin:0.17.0")
3+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"metadata": {},
3+
"nbformat": 4,
4+
"nbformat_minor": 2,
5+
"cells": [
6+
{
7+
"cell_type": "code",
8+
"execution_count": 1,
9+
"source": [
10+
"%use gradle-enterprise-api-kotlin(version=0.17.0)"
11+
],
12+
"outputs": []
13+
}
14+
]
15+
}

.github/workflows/publish-javadoc.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ jobs:
3030
- name: Build javadoc
3131
uses: ./.github/actions/build
3232
with:
33-
args: 'dokkaHtml'
33+
args: >-
34+
dokkaHtml
35+
'-Pversion=${{ github.ref_name }}'
3436
artifact-name: 'docs'
3537
path-to-upload: "library/build/dokka/html/**/*"
3638

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: 'Update examples'
2+
3+
on:
4+
push:
5+
tags: [ '*' ]
6+
workflow_call:
7+
8+
defaults:
9+
run:
10+
shell: bash
11+
12+
jobs:
13+
14+
update-api-spec:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: 'Checkout'
18+
uses: actions/checkout@v3
19+
- name: 'Get versions'
20+
run: |
21+
old_version="$(git tag --sort=-v:refname | head -n 2 | tail -n 1)"
22+
echo "OLD_VERSION=$old_version" >> $GITHUB_ENV
23+
echo "NEW_VERSION=${{ github.ref_name }}" >> $GITHUB_ENV
24+
- name: 'Update version in all files'
25+
run: ./.github/scripts/replace_string.py ./ "$OLD_VERSION" "$NEW_VERSION"
26+
- name: 'Create PR'
27+
uses: peter-evans/create-pull-request@v5
28+
with:
29+
branch: "${{ env.UPDATE_BRANCH }}"
30+
title: "Bump library version in examples to ${{ env.NEW_VERSION }}"
31+
author: "github-actions <github-actions@github.com>"
32+
committer: "github-actions <github-actions@github.com>"

README.md

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Gradle Enterprise API Kotlin
22

3-
[![Release](https://jitpack.io/v/gabrielfeo/gradle-enterprise-api-kotlin.svg)][14]
4-
[![Javadoc](https://img.shields.io/badge/javadoc-latest-orange)][7]
3+
[![Maven Central](https://img.shields.io/badge/Maven%20Central-0.16.2-blue)][14]
4+
[![Javadoc](https://img.shields.io/badge/Javadoc-0.16.2-orange)][7]
55

66
A Kotlin library to access the [Gradle Enterprise API][1], easy to use from Kotlin
77
scripts, projects or Jupyter notebooks:
@@ -29,38 +29,24 @@ That's it! You can now use the library without any code configuration from:
2929

3030
### Setup snippets
3131

32+
ℹ️ The library is now published to Maven Central under `com.gabrielfeo`. Maven Central is
33+
recommended over JitPack.
34+
3235
<details>
3336
<summary>Add to a Kotlin script</summary>
3437

3538
```kotlin
36-
@file:Repository("https://jitpack.io")
37-
@file:DependsOn("com.github.gabrielfeo:gradle-enterprise-api-kotlin:0.16.0")
39+
@file:DependsOn("com.gabrielfeo:gradle-enterprise-api-kotlin:0.16.2")
3840
```
3941

4042
</details>
4143

4244
<details>
4345
<summary>Add to a Kotlin project</summary>
4446

45-
Groovy
46-
47-
```groovy
48-
repositories {
49-
maven { url = 'https://jitpack.io' }
50-
}
51-
dependencies {
52-
implementation 'com.github.gabrielfeo:gradle-enterprise-api-kotlin:0.16.0'
53-
}
54-
```
55-
56-
Kotlin
57-
5847
```kotlin
59-
repositories {
60-
maven(url = "https://jitpack.io")
61-
}
6248
dependencies {
63-
implementation("com.github.gabrielfeo:gradle-enterprise-api-kotlin:0.16.0")
49+
implementation("com.gabrielfeo:gradle-enterprise-api-kotlin:0.16.2")
6450
}
6551
```
6652

@@ -71,7 +57,7 @@ dependencies {
7157

7258
```
7359
%useLatestDescriptors
74-
%use gradle-enterprise-api-kotlin(version=0.16.0)
60+
%use gradle-enterprise-api-kotlin(version=0.16.2)
7561
```
7662

7763
</details>
@@ -186,7 +172,7 @@ import com.gabrielfeo.gradle.enterprise.api.model.extension.*
186172
[11]: https://gabrielfeo.github.io/gradle-enterprise-api-kotlin/library/com.gabrielfeo.gradle.enterprise.api/-gradle-enterprise-api/shutdown.html
187173
[12]: https://gabrielfeo.github.io/gradle-enterprise-api-kotlin/library/com.gabrielfeo.gradle.enterprise.api/-config/-cache-config/cache-enabled.html
188174
[13]: https://gabrielfeo.github.io/gradle-enterprise-api-kotlin/library/com.gabrielfeo.gradle.enterprise.api/-config/-cache-config/index.html
189-
[14]: https://jitpack.io/#gabrielfeo/gradle-enterprise-api-kotlin
175+
[14]: https://central.sonatype.com/artifact/com.gabrielfeo/gradle-enterprise-api-kotlin/0.16.2
190176
[16]: https://gabrielfeo.github.io/gradle-enterprise-api-kotlin/library/com.gabrielfeo.gradle.enterprise.api/-config/api-url.html
191177
[17]: https://gabrielfeo.github.io/gradle-enterprise-api-kotlin/library/com.gabrielfeo.gradle.enterprise.api/-config/api-token.html
192178
[18]: https://gabrielfeo.github.io/gradle-enterprise-api-kotlin/library/com.gabrielfeo.gradle.enterprise.api/-builds-api/index.html

examples/example-notebooks/MostFrequentBuilds.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"`%use` is [line magic](https://github.com/Kotlin/kotlin-jupyter#line-magics) of the Kotlin kernel that can do much more than adding the library. To illustrate, this setup:\n",
3232
"\n",
3333
"```kotlin\n",
34-
"@file:DependsOn(\"com.github.gabrielfeo:gradle-enterprise-api-kotlin:0.15.1\")\n",
34+
"@file:DependsOn(\"com.gabrielfeo:gradle-enterprise-api-kotlin:0.16.2\")\n",
3535
"\n",
3636
"import com.gabrielfeo.gradle.enterprise.api.*\n",
3737
"import com.gabrielfeo.gradle.enterprise.api.model.*\n",
@@ -52,7 +52,7 @@
5252
"outputs": [],
5353
"source": [
5454
"%useLatestDescriptors\n",
55-
"%use gradle-enterprise-api-kotlin(version=0.16.0)\n",
55+
"%use gradle-enterprise-api-kotlin(version=0.16.2)\n",
5656
"%use coroutines(v=1.7.1)"
5757
]
5858
},

examples/example-project/app/build.gradle.kts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,12 @@ application {
77
mainClass.set("com.gabrielfeo.gradle.enterprise.api.example.MainKt")
88
}
99

10-
repositories {
11-
mavenCentral()
12-
maven(url = "https://jitpack.io")
13-
}
14-
1510
java {
1611
toolchain {
1712
languageVersion.set(JavaLanguageVersion.of(8))
1813
}
1914
}
2015

2116
dependencies {
22-
implementation("com.github.gabrielfeo:gradle-enterprise-api-kotlin:0.16.0")
17+
implementation("com.gabrielfeo:gradle-enterprise-api-kotlin:0.16.2")
2318
}

0 commit comments

Comments
 (0)