Skip to content

Commit b6a68df

Browse files
committed
Add GitHub action to build artifact
1 parent 2a4cb7a commit b6a68df

2 files changed

Lines changed: 64 additions & 0 deletions

File tree

.github/workflows/publish.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
build-and-test:
14+
runs-on: ubuntu-latest
15+
permissions:
16+
packages: write
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Set up JDK 17
21+
uses: actions/setup-java@v4
22+
with:
23+
java-version: '17'
24+
distribution: 'temurin'
25+
26+
- name: Setup Gradle
27+
uses: gradle/actions/setup-gradle@v3
28+
29+
- name: Publish package
30+
run: |
31+
COMMIT_SHA="`git log -n 1 --pretty=format:%H`" ./gradlew publish
32+
env:
33+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

numbers/build.gradle.kts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import java.net.URI
2+
13
plugins {
24
alias(libs.plugins.org.jetbrains.kotlin.jvm)
35
id("java-library")
6+
id("maven-publish")
47
}
58

69
kotlin {
@@ -11,3 +14,31 @@ dependencies {
1114
implementation(libs.nanojson)
1215
testImplementation(libs.junit)
1316
}
17+
18+
val sourcesJar by tasks.registering(Jar::class) {
19+
archiveClassifier.convention("sources");
20+
archiveClassifier.set("sources");
21+
from(sourceSets.main.get().allSource)
22+
}
23+
24+
publishing {
25+
repositories {
26+
maven {
27+
name = "GitHubPackages"
28+
url = URI("https://maven.pkg.github.com/octocat/hello-world")
29+
credentials {
30+
username = System.getenv("GITHUB_ACTOR")
31+
password = System.getenv("GITHUB_TOKEN")
32+
}
33+
}
34+
}
35+
publications {
36+
register("mavenJava", MavenPublication::class) {
37+
groupId = "org.dicio"
38+
artifactId = "numbers"
39+
version = System.getenv("COMMIT_SHA")
40+
from(components["java"])
41+
artifact(sourcesJar.get())
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)