Skip to content

Commit

Permalink
Merge pull request #15 from Erdragh/chore/autopublishing
Browse files Browse the repository at this point in the history
Start setting up autopublishing
  • Loading branch information
Erdragh authored Oct 11, 2023
2 parents 364f623 + 56815c1 commit 85163ef
Show file tree
Hide file tree
Showing 12 changed files with 226 additions and 33 deletions.
10 changes: 10 additions & 0 deletions .github/scripts/extract_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
version_grep=$(grep mod_version "gradle.properties")
minecraft_grep=$(grep minecraft_version "gradle.properties")
minecraft_version=${minecraft_grep#minecraft_version=}
version="${version_grep#mod_version=}"

build="${GITHUB_RUN_NUMBER:-local}"
[[ -z $PATCH_NUMBER ]] && ([[ $PATCH_NUMBER != 0 ]] && patch=" Patch $PATCH_NUMBER" || patch="" ) || patch=""

echo "$version-$build+mc${minecraft_version}$patch"
100 changes: 82 additions & 18 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
# Automatically build the project and run any configured tests for every push
# and submitted pull request. This can help catch issues that only occur on
# certain platforms or Java versions, and provides a first line of defence
# against bad commits.

name: build
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
workflow_dispatch:
inputs:
publish:
description: Publish to Modrinth, CurseForge and GitHub
required: true
default: "false"
patch:
description: Patch number, 0 for first
required: true
push:
branches: [ "main", "develop" ]
pull_request:
Expand All @@ -11,34 +23,86 @@ jobs:
build:
strategy:
matrix:
java: [ 17 ]
runs-on: ubuntu-latest
# Use these Java versions
java: [
17, # Current Java LTS & minimum supported by Minecraft
]
# and run on both Linux and macOS
os: [ubuntu-latest, macos-latest]

runs-on: ${{ matrix.os }}
env:
PUBLISH_SUFFIX: snapshots
MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}
CURSEFORGE_TOKEN: ${{ secrets.CURSEFORGE_TOKEN }}
PATCH_NUMBER: ${{ github.event.inputs.patch }}
PUBLISHING: ${{ github.event.inputs.publish }}
steps:
- name: checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: validate gradle wrapper
uses: gradle/wrapper-validation-action@v1

- name: setup jdk ${{ matrix.java }}
uses: actions/setup-java@v1
uses: actions/setup-java@v3
with:
java-version: ${{ matrix.java }}

- uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/loom-cache
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/gradle-wrapper.properties') }}
restore-keys: ${{ runner.os }}-gradle
distribution: 'temurin'
cache: gradle

- name: make gradle wrapper executable
if: ${{ runner.os != 'Windows' }}
run: chmod +x ./gradlew

- name: build
run: ./gradlew build
- name: extract version
if: ${{ runner.os != 'Windows' }}
id: getversion
run: |
echo "version=$(.github/scripts/extract_version.sh)" >> "$GITHUB_OUTPUT"
- name: gradle clean build
env:
VERSION_NAME: ${{ steps.getversion.outputs.version }}
run: ./gradlew clean build

- name: extract changelog
if: ${{ runner.os == 'Linux' && matrix.java == '17' && github.event.inputs.publish }} # only publish from one OS with latest Java
id: getchangelog
env:
VERSION_NAME: ${{ steps.getversion.outputs.version }}
run: |
echo "changelog=$(./gradlew -q printChangelog)" >> "$GITHUB_OUTPUT"
# windows throws an error if the second parameter for
# echo is not set, which it will never be, because it's
# only set for Linux
- name: show version
if: ${{ runner.os == 'Linux' && matrix.java == '17' && github.event.inputs.publish }} # only publish from one OS with latest Java
run: echo ${{ steps.getversion.outputs.version }}

- name: show changelog
if: ${{ runner.os == 'Linux' && matrix.java == '17' && github.event.inputs.publish }} # only publish from one OS with latest Java
run: echo "${{ steps.getchangelog.outputs.changelog }}"
continue-on-error: true

- name: capture build artifacts
uses: actions/upload-artifact@v2
if: ${{ runner.os == 'Linux' && matrix.java == '17' }} # Only upload artifacts built from latest java on one OS
uses: actions/upload-artifact@v3
with:
name: Artifacts
path: build/libs/

# - name: publish to Modrinth and CurseForge
# env:
# VERSION_NAME: ${{ steps.getversion.outputs.version }}
# if: ${{ runner.os == 'Linux' && matrix.java == '17' && github.event.inputs.publish }} # only publish from one OS with latest Java
# run: ./gradlew publishMod

- name: create GitHub Release
if: ${{ runner.os == 'Linux' && matrix.java == '17' && github.event.inputs.publish }} # only publish from one OS with latest Java
uses: ncipollo/release-action@v1
with:
artifacts: "LICENSE,build/libs/*.jar"
body: ${{ steps.getchangelog.outputs.changelog }}
tag: ${{ steps.getversion.outputs.version }}
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# indev

# 1.4.1
- Fix hover mode ascending on sneak+jump (Issue #13)

# 1.4.0
- Thruster Boots

# 1.3.2
Expand Down
19 changes: 15 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
plugins {
id 'fabric-loom' version '1.1-SNAPSHOT'
id 'fabric-loom' version '1.3.9'
id 'maven-publish'
id "io.github.juuxel.loom-vineflower" version "1.+" // Vineflower, a better decompiler
id "io.github.p03w.machete" version "1.+" // automatic jar compressing on build
id "com.modrinth.minotaur" version "2.+" // modrinth plugin
id "com.matthewprenger.cursegradle" version "1.+" // curseforge publishing
}

version = project.mod_version
Expand Down Expand Up @@ -53,11 +57,11 @@ dependencies {
}

processResources {
inputs.property "version", project.version
filteringCharset "UTF-8"
def props = new Properties()
file("gradle.properties").withInputStream { props.load(it) }

filesMatching("fabric.mod.json") {
expand "version": project.version
expand props
}
}

Expand Down Expand Up @@ -91,6 +95,11 @@ jar {
}
}

machete {
// Only optimize published releases
enabled = Boolean.getBoolean("PUBLISHING")
}

// configure the maven publication
publishing {
publications {
Expand All @@ -107,3 +116,5 @@ publishing {
// retrieving dependencies.
}
}

apply from: "gradle/publishing/publishing.gradle"
5 changes: 3 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ org.gradle.jvmargs=-Xmx4G
minecraft_version=1.18.2
loader_version=0.14.14
# Mod Properties
mod_version=1.4.0
mod_version=1.4.1
maven_group=com.github.erdragh
archives_base_name=per_aspera
display_name=Per Aspera
# Dependencies
# check this on https://modmuss50.me/fabric.html
fabric_version=0.75.1+1.18.2
fabric_version=0.76.0+1.18.2
yarn_mappings=1.18.2+build.4

ad_astra_version=1.0.6
Expand Down
30 changes: 30 additions & 0 deletions gradle/publishing/curseforge.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
curseforge {
String token = System.getenv("CURSEFORGE_TOKEN")
apiKey = token == null || token.isEmpty() ? "unset" : token

project {
id = curseforge_id
changelog = changelog_text
releaseType = release_type
addGameVersion("Fabric")
addGameVersion(minecraft_version)

relations {
requiredDependency("fabric-api")
requiredDependency("fabric-language-kotlin")
requiredDependency("forge-config-api-port-fabric")
optionalDependency("roughly-enough-items")
}

// https://github.com/mraliscoder/plasmo-voice/blob/41243bc77589d975acde5385dd86414b1c92a2a8/fabric/build.gradle.kts#L173
mainArtifact(file("build/libs/${remapJar.archiveBaseName.get()}-${version}.jar")) {
displayName = published_version_name
}

afterEvaluate {
uploadTask.dependsOn(remapJar)
}
}

curseGradleOptions.forgeGradleIntegration = false
}
18 changes: 18 additions & 0 deletions gradle/publishing/modrinth.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// task that publishes to modrinth
modrinth {
token = System.getenv("MODRINTH_TOKEN")
projectId = modrinth_id
versionNumber = version
versionType = release_type
versionName = published_version_name
changelog = changelog_text
uploadFile = file("build/libs/${remapJar.archiveBaseName.get()}-${version}.jar")
gameVersions = [ minecraft_version ]
loaders = ["fabric"]
dependencies {
required.project "fabric-api"
required.project "fabric-language-kotlin"
required.project "forge-config-api-port"
optional.project "rei"
}
}
51 changes: 51 additions & 0 deletions gradle/publishing/publishing.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import java.nio.file.Files

ext /*-ra properties*/ {
Properties properties = new Properties()
properties.load(new FileInputStream(file("gradle/publishing/publishing.properties")))

properties.forEach ((k, v) -> set(k, v))

versionEnv = System.getenv("VERSION_NAME")

if (versionEnv != null) {
version = versionEnv
}

version_valid = versionValidForPublishing(version)
published_version_name = version_valid ? makeName(version, minecraft_version, display_name) : "INVALID"
changelog_text = getChangelog(file(changelog_file))
}

tasks.register("publishMod") {
if (version_valid) {
dependsOn(tasks.named("modrinth"))
dependsOn(tasks.named("curseforge"))
}
}

tasks.register("printChangelog") {
println(changelog_text)
}

static String makeName(String version, String minecraftVersion, String displayName) {
String projectVersion = "v" + version.split("-build")[0].replace("-", ".")
String rawPatch = System.getenv("PATCH_NUMBER")
String patch = rawPatch === null || rawPatch.isEmpty() || rawPatch == "0" ? "" : "Patch $rawPatch"
return "$displayName $minecraftVersion $projectVersion $patch".trim()
}

static boolean versionValidForPublishing(String version) {
return !version.contains("local")
}

static String getChangelog(File changelogFile) {
String text = Files.readString(changelogFile.toPath())
String[] split = text.split("# \\d+(\\.\\d+)+?[\\w.-_]+")
if (split.length < 2)
throw new IllegalStateException("Malformed changelog")
return split[1].trim()
}

apply from: "gradle/publishing/modrinth.gradle"
apply from: "gradle/publishing/curseforge.gradle"
4 changes: 4 additions & 0 deletions gradle/publishing/publishing.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
modrinth_id = 4Q5DgkRU
curseforge_id = 833210
release_type = release
changelog_file = CHANGELOG.md
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip
7 changes: 3 additions & 4 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
pluginManagement {
repositories {
maven {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
}
maven { url = "https://maven.fabricmc.net/" }
maven { url = "https://maven.quiltmc.org/repository/release" }
mavenCentral()
gradlePluginPortal()
}
}
8 changes: 4 additions & 4 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"schemaVersion": 1,
"id": "per_aspera",
"version": "${version}",
"name": "Per Aspera",
"version": "${mod_version}",
"name": "${display_name}",
"description": "Ad Astra addon which provides some bugfixes and improvements for the Create: Astral modpack",
"authors": [
"Erdragh"
Expand All @@ -26,10 +26,10 @@
"per_aspera.mixins.json"
],
"depends": {
"fabricloader": ">=0.14.14",
"fabricloader": ">=${loader_version}",
"fabric": "*",
"minecraft": "1.18.2",
"ad_astra": ">=1.0.7"
"ad_astra": ">=1.0.9"
},
"accessWidener": "per_aspera.accesswidener"
}

0 comments on commit 85163ef

Please sign in to comment.