Skip to content

Commit 73d8868

Browse files
committed
ci: add release workflow to publish all modules
1 parent 39f0949 commit 73d8868

3 files changed

Lines changed: 131 additions & 2 deletions

File tree

.github/workflows/build.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Build
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
workflow_dispatch:
11+
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: true
15+
16+
jobs:
17+
build:
18+
name: Build with Java 21
19+
runs-on: ubuntu-latest
20+
timeout-minutes: 15
21+
env:
22+
VERSION: 0.0.0-SNAPSHOT
23+
24+
steps:
25+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
26+
- uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0
27+
with:
28+
distribution: "adopt"
29+
java-version: 21
30+
31+
- name: Setup Gradle
32+
uses: gradle/actions/setup-gradle@f29f5a9d7b09a7c6b29859002d29d24e1674c884 # v5.0.1
33+
34+
- name: Build with Gradle
35+
run: ./gradlew build
36+
37+
- name: Upload a Build Artifact
38+
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
39+
with:
40+
path: modules/**/build/libs/*.jar

.github/workflows/release.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: 'Library version. ex: x.x.x, x.x.x-SNAPSHOT'
8+
required: true
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
permissions:
15+
contents: write
16+
17+
jobs:
18+
release:
19+
name: Release
20+
runs-on: ubuntu-latest
21+
timeout-minutes: 3
22+
23+
steps:
24+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
25+
- uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654
26+
with:
27+
distribution: "adopt"
28+
java-version: 21
29+
30+
- name: Setup Gradle
31+
uses: gradle/actions/setup-gradle@f29f5a9d7b09a7c6b29859002d29d24e1674c884
32+
33+
- name: Build
34+
run: ./gradlew build
35+
env:
36+
VERSION: ${{ github.event.inputs.version }}
37+
38+
- name: Upload a Build Artifact
39+
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f
40+
with:
41+
path: modules/**/build/libs/*.jar
42+
43+
- name: Publish all modules
44+
run: ./gradlew publishAll
45+
env:
46+
VERSION: ${{ github.event.inputs.version }}
47+
REPO_USERNAME: ${{ secrets.REPO_USERNAME }}
48+
REPO_PASSWORD: ${{ secrets.REPO_PASSWORD }}
49+
50+
- name: Create release
51+
uses: softprops/action-gh-release@a06a81a03ee405af7f2048a818ed3f03bbf83c7b
52+
with:
53+
tag_name: ${{ github.event.inputs.version }}
54+
files: modules/**/build/libs/*.jar
55+
generate_release_notes: true

build.gradle.kts

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ plugins {
66
}
77

88
group = "net.azisaba.data"
9-
version = "1.0-SNAPSHOT"
9+
version = System.getenv("VERSION") ?: "0.0.0-SNAPSHOT"
1010

11-
configure(subprojects.filter { it.childProjects.isEmpty() }) {
11+
val leafProjects = subprojects.filter { it.childProjects.isEmpty() }
12+
13+
configure(leafProjects) {
1214
group = rootProject.group
1315
version = rootProject.version
1416

1517
apply(plugin = "java-library")
18+
apply(plugin = "maven-publish")
1619
apply(plugin = "org.jetbrains.kotlin.jvm")
1720

1821
repositories {
@@ -30,4 +33,35 @@ configure(subprojects.filter { it.childProjects.isEmpty() }) {
3033
configure<JavaPluginExtension> {
3134
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
3235
}
36+
37+
configure<PublishingExtension> {
38+
publications {
39+
create<MavenPublication>("mavenJava") {
40+
from(components["java"])
41+
groupId = group.toString()
42+
artifactId = project.name
43+
version = version.toString()
44+
}
45+
}
46+
repositories {
47+
maven {
48+
name = "azisaba"
49+
url = if (version.toString().endsWith("SNAPSHOT")) {
50+
uri("https://repo.azisaba.net/repository/maven-snapshots/")
51+
} else {
52+
uri("https://repo.azisaba.net/repository/maven-releases/")
53+
}
54+
credentials {
55+
username = System.getenv("REPO_USERNAME")
56+
password = System.getenv("REPO_PASSWORD")
57+
}
58+
}
59+
}
60+
}
61+
}
62+
63+
tasks.register("publishAll") {
64+
dependsOn(
65+
leafProjects.map { "${it.path}:publish" }
66+
)
3367
}

0 commit comments

Comments
 (0)