Skip to content

Commit

Permalink
[#2] Implement auto publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMeinerLP committed Feb 13, 2024
1 parent a7a2b9a commit 4bf6c20
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ jobs:
# Only run on PRs if the source branch is on someone else's repo
if: ${{ github.event_name != 'pull_request' || github.repository != github.event.pull_request.head.repo.full_name }}
runs-on: ubuntu-latest
env:
GPG_PRIVATE_KEY: ${{ secrets.ONELITEFEATHER_GPG_KEY }}
GPG_PASSPHRASE: ${{ secrets.ONELITEFEATHER_GPG_PASSWORD }}
GITLAB_API_URL: ${{ secrets.GITLAB_API_URL }}
GITLAB_PROJECT_ID: ${{ secrets.GITLAB_PROJECT_ID }}
GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }}
steps:
- name: Checkout Git Repository
uses: actions/checkout@v3
Expand All @@ -28,3 +34,8 @@ jobs:
run: ./gradlew applyPatches
- name: Build
run: ./gradlew build
- name: Publish API
run: ./gradle :onelitepaper-API:publishMavenPublicationToGitlabRepository
- name: Publish DevBundle
run: ./gradle publishDevBundlePublicationToGitlabRepository -PpublishDevBundle

29 changes: 26 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ plugins {

// In general, keep this version in sync with upstream. Sometimes a newer version than upstream might work, but an older version is extremely likely to break.
id("io.papermc.paperweight.patcher") version "1.5.11"
signing
}

val paperMavenPublicUrl = "https://repo.papermc.io/repository/maven-public/"
Expand All @@ -27,6 +28,7 @@ dependencies {
allprojects {
apply(plugin = "java")
apply(plugin = "maven-publish")
apply(plugin = "signing")

java {
toolchain {
Expand Down Expand Up @@ -84,9 +86,12 @@ paperweight {
tasks.generateDevelopmentBundle {
apiCoordinates = "net.onelitefeather.onelitepaper:onelitepaper-api"
mojangApiCoordinates = "io.papermc.paper:paper-mojangapi"
val ciApiv4Url = System.getenv("GITLAB_API_URL")
val projectId = System.getenv("GITLAB_PROJECT_ID")
libraryRepositories = listOf(
"https://repo.maven.apache.org/maven2/",
paperMavenPublicUrl,
"$ciApiv4Url/projects/$projectId/packages/maven"
// "https://my.repo/", // This should be a repo hosting your API (in this example, 'com.example.paperfork:forktest-api')
)
}
Expand All @@ -97,11 +102,19 @@ allprojects {
publishing {
repositories {
maven {
name = "myRepoSnapshots"
url = uri("https://my.repo/")
name = "Gitlab"
val ciApiv4Url = System.getenv("GITLAB_API_URL")
val projectId = System.getenv("GITLAB_PROJECT_ID")
url = uri("$ciApiv4Url/projects/$projectId/packages/maven")
// See Gradle docs for how to provide credentials to PasswordCredentials
// https://docs.gradle.org/current/samples/sample_publishing_credentials.html
credentials(PasswordCredentials::class)
credentials(HttpHeaderCredentials::class) {
name = "github"
value = System.getenv("GITLAB_TOKEN")
}
authentication {
create<HttpHeaderAuthentication>("header")
}
}
}
}
Expand All @@ -118,3 +131,13 @@ publishing {
}
}
}

signing {
isRequired = System.getenv("CI") != null

val privateKey = System.getenv("GPG_PRIVATE_KEY")
val keyPassphrase = System.getenv()["GPG_PASSPHRASE"]
useInMemoryPgpKeys(privateKey, keyPassphrase)

sign(publishing.publications)
}

0 comments on commit 4bf6c20

Please sign in to comment.