Skip to content

Commit

Permalink
chore: Add the ability to publish to Github packages
Browse files Browse the repository at this point in the history
Signed-off-by: Avior <[email protected]>
  • Loading branch information
Aviortheking committed Dec 28, 2023
1 parent 238c215 commit 7c7ca17
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 20 deletions.
22 changes: 12 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 9 additions & 10 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
40 changes: 40 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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("[email protected]")
}
}
scm {
connection.set("scm:[email protected]: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")
}
}
}
}

0 comments on commit 7c7ca17

Please sign in to comment.