diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..45fe36a --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,33 @@ +name: CI + +on: + push: + branches: + - master + workflow_dispatch: + +permissions: + contents: read + +jobs: + build-and-test: + runs-on: ubuntu-latest + permissions: + packages: write + steps: + - uses: actions/checkout@v4 + + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + + - name: Publish package + run: | + COMMIT_SHA="`git log -n 1 --pretty=format:%H`" ./gradlew publish + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/numbers/build.gradle.kts b/numbers/build.gradle.kts index c662710..e3f9147 100644 --- a/numbers/build.gradle.kts +++ b/numbers/build.gradle.kts @@ -1,6 +1,9 @@ +import java.net.URI + plugins { alias(libs.plugins.org.jetbrains.kotlin.jvm) id("java-library") + id("maven-publish") } kotlin { @@ -11,3 +14,31 @@ dependencies { implementation(libs.nanojson) testImplementation(libs.junit) } + +val sourcesJar by tasks.registering(Jar::class) { + archiveClassifier.convention("sources"); + archiveClassifier.set("sources"); + from(sourceSets.main.get().allSource) +} + +publishing { + repositories { + maven { + name = "GitHubPackages" + url = URI("https://maven.pkg.github.com/octocat/hello-world") + credentials { + username = System.getenv("GITHUB_ACTOR") + password = System.getenv("GITHUB_TOKEN") + } + } + } + publications { + register("mavenJava", MavenPublication::class) { + groupId = "org.dicio" + artifactId = "numbers" + version = System.getenv("COMMIT_SHA") + from(components["java"]) + artifact(sourcesJar.get()) + } + } +}