chore: Add the ability to publish to Github packages

Signed-off-by: Avior <github@avior.me>
This commit is contained in:
Florian Bouillon 2023-12-28 03:03:40 +01:00
parent 238c215d35
commit 7c7ca1742b
Signed by: Florian Bouillon
GPG Key ID: 0A288052C94BD2C8
3 changed files with 61 additions and 20 deletions

View File

@ -5,34 +5,36 @@
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle
name: Java CI with Gradle
name: Build & test the project
on:
push:
branches: [ master ]
branches:
- master
# Run on any pull request
pull_request:
branches: [ master ]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
# follows https://en.wikipedia.org/wiki/Java_version_history#Release_table
java-versions: ['8', '11', '17', '21']
steps:
- uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v3
- name: Set up Java ${{ matrix.java-versions }}
uses: actions/setup-java@v3
with:
java-version: ${{ matrix.java-versions }}
distribution: 'temurin'
- name: Build with Gradle
uses: gradle/gradle-build-action@fec4a42eb0c83154e5c9590748ba8337949c5701
- name: Build & Test
uses: gradle/gradle-build-action@v2
with:
arguments: build
arguments: build test

View File

@ -9,35 +9,34 @@ name: Gradle Package
on:
release:
types: [created]
types:
- created
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
- name: Checkout
uses: actions/checkout@v3
- name: Set up JDK 8
uses: actions/setup-java@v3
with:
java-version: '11'
java-version: '8' # use the lowest version from https://en.wikipedia.org/wiki/Java_version_history#Release_table
distribution: 'temurin'
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file
- name: Build with Gradle
uses: gradle/gradle-build-action@fec4a42eb0c83154e5c9590748ba8337949c5701
- name: Build the project
uses: gradle/gradle-build-action@v2
with:
arguments: build
# The USERNAME and TOKEN need to correspond to the credentials environment variables used in
# the publishing section of your build.gradle
- name: Publish to GitHub Packages
uses: gradle/gradle-build-action@fec4a42eb0c83154e5c9590748ba8337949c5701
uses: gradle/gradle-build-action@v2
with:
arguments: publish
env:

View File

@ -85,5 +85,45 @@ publishing {
}
}
}
register<MavenPublication>("gpr") {
// groupId = group
artifactId = artifact
// version = ver
from(components["java"])
pom {
name.set("TCGdex SDK")
description.set("Communicate with the Open Source TCGdex API in Kotlin/Java using the SDK")
url.set("https://github.com/tcgdex/java-sdk")
licenses {
license {
name.set("MIT License")
url.set("https://github.com/tcgdex/java-sdk/blob/master/LICENSE.txt")
}
}
developers {
developer {
id.set("avior")
name.set("Avior")
email.set("contact@tcgdex.net")
}
}
scm {
connection.set("scm:git@github.com:tcgdex/java-sdk.git")
url.set("https://github.com/tcgdex/java-sdk")
}
}
}
}
repositories {
maven {
name = "GithubPackages"
url = uri("https://maven.pkg.github.com/tcgdex/java-sdk")
credentials {
username = project.findProperty("gpr.user") as String? ?: System.getenv("USERNAME")
password = project.findProperty("gpr.key") as String? ?: System.getenv("TOKEN")
}
}
}
}