Skip to content

Commit

Permalink
Setup mod publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
Su5eD committed Jul 7, 2024
1 parent 247fd40 commit 5ec9fcd
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 44 deletions.
80 changes: 68 additions & 12 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
name: Release
on: [workflow_dispatch] # Manual trigger
on:
workflow_dispatch:
inputs:
release_type:
description: 'The published artifact release type'
required: false
default: 'STABLE'
type: choice
options:
- STABLE
- BETA
- ALPHA

permissions:
contents: write

jobs:
build:
name: Build
runs-on: ubuntu-22.04
container:
image: mcr.microsoft.com/openjdk/jdk:21-ubuntu
options: --user root
outputs:
changelog: ${{ steps.changelog.outputs.changelog }}
steps:
- run: apt update && apt install git -y && git --version
- run: git config --global --add safe.directory /__w/fabric/fabric
Expand All @@ -21,16 +32,61 @@ jobs:
with:
context: changelog
workflow_id: release.yml
- uses: actions/setup-java@v3
with:
distribution: 'microsoft'
java-version: '21'
- uses: gradle/wrapper-validation-action@v2
- run: ./gradlew checkVersion build publish publishMods --stacktrace
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
with:
gradle-home-cache-cleanup: true
- name: Build with Gradle
run: ./gradlew clean build --stacktrace
publish:
strategy:
matrix:
include:
- name: Maven
task: publish
url: https://maven.su5ed.dev/releases/org/sinytra/forgified-fabric-api
- name: GitHub
task: publishGithub
url: https://github.com/Sinytra/ForgifiedFabricAPI/releases
- name: CurseForge
task: publishCurseforge
url: https://www.curseforge.com/minecraft/mc-mods/forgified-fabric-api
- name: Modrinth
task: publishModrinth
url: https://modrinth.com/mod/forgified-fabric-api
name: Publish ${{ matrix.name }}
needs: build
runs-on: ubuntu-22.04
environment:
name: ${{ matrix.name }}
url: ${{ matrix.url }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-java@v3
with:
distribution: 'microsoft'
java-version: '21'
- uses: gradle/wrapper-validation-action@v1
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
with:
cache-read-only: true
gradle-home-cache-cleanup: true
- name: Publish with Gradle
run: ./gradlew clean build ${{ matrix.task }} --stacktrace
env:
PUBLISH_RELEASE_TYPE: ${{ inputs.release_type }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CURSEFORGE_TOKEN: ${{ secrets.CURSEFORGE_TOKEN }}
MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}
MAVEN_URL: ${{ secrets.MAVEN_URL }}
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
CURSEFORGE_API_KEY: ${{ secrets.CURSEFORGE_API_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}
CHANGELOG: ${{ steps.changelog.outputs.changelog }}
SIGNING_SERVER: ${{ secrets.SIGNING_SERVER }}
SIGNING_PGP_KEY: ${{ secrets.SIGNING_PGP_KEY }}
SIGNING_JAR_KEY: ${{ secrets.SIGNING_JAR_KEY }}
CHANGELOG: ${{ needs.build.outputs.changelog }}
84 changes: 63 additions & 21 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import me.modmuss50.mpp.ReleaseType
import net.fabricmc.loom.build.nesting.IncludedJarFactory
import net.fabricmc.loom.build.nesting.JarNester
import net.fabricmc.loom.util.Constants
Expand All @@ -9,13 +10,19 @@ plugins {
java
`maven-publish`
id("dev.architectury.loom") // Version declared in buildSrc
id("me.modmuss50.mod-publish-plugin") version "0.5.+"
}

val implementationVersion: String by project
val versionMc: String by project
val versionForge: String by project
val versionForgifiedFabricLoader: String by project

val curseForgeId: String by project
val modrinthId: String by project
val githubRepository: String by project
val publishBranch: String by project

val META_PROJECTS: List<String> = listOf(
"deprecated",
"fabric-api-bom",
Expand Down Expand Up @@ -96,27 +103,6 @@ allprojects {
})
}

tasks.named<Jar>("jar") {
doLast {
val factory = IncludedJarFactory(project)
val nestedJars = factory.getNestedJars(configurations.getByName(Constants.Configurations.INCLUDE))

if (!nestedJars.isPresent) {
logger.info("No jars to nest")
return@doLast
}

val jars: MutableSet<File> = LinkedHashSet(nestedJars.get().files)
JarNester.nestJars(
jars,
emptyList(),
archiveFile.get().asFile,
loom.platform.get(),
project.logger
)
}
}

// Run this task after updating minecraft to regenerate any required resources
tasks.register("generateResources") {

Expand All @@ -129,6 +115,23 @@ dependencies {
}

tasks {
named<Jar>("jar") {
doLast {
val factory = IncludedJarFactory(project)
val config = configurations.getByName(Constants.Configurations.INCLUDE)
val nestedJars = factory.getNestedJars(config)
val forgeNestedJars = factory.getForgeNestedJars(config)

JarNester.nestJars(
nestedJars.get().files,
forgeNestedJars.get().left.map { it.resolve() },
archiveFile.get().asFile,
loom.platform.get(),
project.logger
)
}
}

withType<JavaCompile> {
options.release = 21
}
Expand Down Expand Up @@ -177,6 +180,45 @@ allprojects {
from(components["java"])
}
}
repositories {
val env = System.getenv()
if (env["MAVEN_URL"] != null) {
repositories.maven {
url = uri(env["MAVEN_URL"] as String)
if (env["MAVEN_USERNAME"] != null) {
credentials {
username = env["MAVEN_USERNAME"]
password = env["MAVEN_PASSWORD"]
}
}
}
}
}
}
}

publishMods {
file.set(tasks.jar.flatMap { it.archiveFile })
changelog.set(providers.environmentVariable("CHANGELOG").orElse("# $version"))
type.set(providers.environmentVariable("PUBLISH_RELEASE_TYPE").orElse("alpha").map(ReleaseType::of))
modLoaders.add("neoforge")
dryRun.set(!providers.environmentVariable("CI").isPresent)
displayName.set("[$versionMc] Forgified Fabric API $version")

github {
accessToken.set(providers.environmentVariable("GITHUB_TOKEN"))
repository.set(githubRepository)
commitish.set(publishBranch)
}
curseforge {
accessToken.set(providers.environmentVariable("CURSEFORGE_TOKEN"))
projectId.set(curseForgeId)
minecraftVersions.add(versionMc)
}
modrinth {
accessToken.set(providers.environmentVariable("MODRINTH_TOKEN"))
projectId.set(modrinthId)
minecraftVersions.add(versionMc)
}
}

Expand Down
3 changes: 3 additions & 0 deletions buildSrc/src/main/kotlin/ffapi.neo-conversion.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ extensions.getByType<SourceSetContainer>().configureEach {
tasks.named("generate") {
dependsOn(task)
}
tasks.named<Jar>("jar") {
exclude("fabric.mod.json")
}
}

afterEvaluate {
Expand Down
30 changes: 19 additions & 11 deletions buildSrc/src/main/kotlin/ffapi.neo-setup.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ val versionFabricLoader: String by rootProject
val loom = extensions.getByType<LoomGradleExtensionAPI>()
val sourceSets = extensions.getByType<SourceSetContainer>()

val jar = tasks.named<Jar>("jar")

val mainSourceSet = sourceSets.getByName("main")

mainSourceSet.apply {
Expand Down Expand Up @@ -49,15 +47,25 @@ dependencies {
"testRuntimeOnly"("org.junit.jupiter:junit-jupiter-engine:5.8.1")
}

tasks.named<Test>("test") {
useJUnitPlatform()
enabled = false
}

tasks.named<ProcessResources>("processResources") {
filesMatching("assets/*/icon.png") {
exclude()
rootProject.file("src/main/resources/assets/fabric/icon.png").copyTo(destinationDir.resolve(path))
tasks {
named<Jar>("jar") {
manifest {
attributes(
"Implementation-Version" to project.version
)
}
}

named<Test>("test") {
useJUnitPlatform()
enabled = false
}

named<ProcessResources>("processResources") {
filesMatching("assets/*/icon.png") {
exclude()
rootProject.file("src/main/resources/assets/fabric/icon.png").copyTo(destinationDir.resolve(path))
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions ffapi.gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ versionMc=1.21
versionForge=21.0.57-beta
versionForgifiedFabricLoader=2.5.24+0.15.10+1.21
versionFabricLoader=0.15.10

curseForgeId=889079
modrinthId=Aqlf1Shp
githubRepository=Sinytra/Connector
# This is the branch the release tag will be created from
publishBranch=neo/1.21

0 comments on commit 5ec9fcd

Please sign in to comment.