Skip to content

Commit

Permalink
Merge branch 'multi-api'
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Ruf committed Dec 13, 2023
2 parents 4d831fc + e581e07 commit 2e0157d
Show file tree
Hide file tree
Showing 24 changed files with 574 additions and 124 deletions.
100 changes: 85 additions & 15 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,14 @@ on:
tags:
- '*'

env:
# For any reason, specifying this in the modrinth step does not work?
# But it is also well documented here, so this should be ok to do
MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
version: ['1.19', '1.19.1', '1.19.2', '1.19.3', '1.19.4', '1.20', '1.20.1', '1.20.2']
fail-fast: true
steps:
- name: Check tag condition
if: startsWith(github.ref, 'refs/tags/')
run: echo "Ref is a tag"

- name: Check out project
if: success()
uses: actions/checkout@v3
Expand All @@ -36,14 +31,38 @@ jobs:
if: success()
uses: gradle/gradle-build-action@v2
with:
gradle-version: 7.4.2
gradle-version: 8.3

- name: Build
if: success()
run: gradle remapJar
run: gradle remapJar -Pv=${{ matrix.version }}

- name: Upload artifact
if: success()
uses: actions/upload-artifact@v3
with:
name: build-${{ matrix.version }}
path: |
**/libs/server-portals-*.jar
release:
runs-on: ubuntu-latest
needs: build
steps:
- name: Check out metadata
uses: actions/checkout@v3
with:
sparse-checkout: |
README.md
CHANGELOG.md
LICENSE
- name: Download artifacts
if: success()
uses: actions/download-artifact@v3

- name: Release on GitHub
if: success() && startsWith(github.ref, 'refs/tags/') # Failsafe check again
- name: Release on github
if: success() # No git tag check, since action-gh-release fails if not valid
uses: softprops/action-gh-release@v1
with:
files: |
Expand All @@ -56,6 +75,57 @@ jobs:
prerelease: false
fail_on_unmatched_files: true

- name: Upload to modrinth
publish:
runs-on: ubuntu-latest
needs: release
strategy:
matrix:
version: ['1.19', '1.19.1', '1.19.2', '1.19.3', '1.19.4', '1.20', '1.20.1', '1.20.2']
fail-fast: true
steps:
- name: Check out metadata
uses: actions/checkout@v3
with:
sparse-checkout: |
CHANGELOG.md
- name: Download artifact
if: success()
uses: actions/download-artifact@v3
with:
name: build-${{ matrix.version }}

- name: Publish on modrinth
if: success() && startsWith(github.ref, 'refs/tags/') # Failsafe check
# See https://github.com/Kir-Antipov/mc-publish
uses: Kir-Antipov/[email protected]
with:
modrinth-id: server-portals
modrinth-token: ${{ secrets.MODRINTH_TOKEN }}
modrinth-featured: false
files: |
**/libs/server-portals-*.jar
name: Server Portals ${{ github.ref_name }}
version: ${{ github.ref_name }}+${{ matrix.version }}
version-type: "${{ contains(github.ref_name, 'SNAPSHOT') && 'alpha' || 'release' }}"
changelog-file: CHANGELOG.md
#loaders: fabric
game-versions: "=${{ matrix.version }}"
#dependencies:

publish_readme:
runs-on: ubuntu-latest
needs: publish
steps:
- name: Check out metadata
uses: actions/checkout@v3
with:
sparse-checkout: |
README.md
- name: Update readme
if: success()
run: gradle modrinth
run: |
readme="$(sed 's/\\/\\\\/g; s/"/\\"/g; s/$/\\n/' README.md)"
json="{ \"body\": \"$readme\" }"
echo "$json" | curl -XPATCH -H "Authorization: ${{ secrets.MODRINTH_TOKEN }}" -H "Content-type: application/json" -d @- 'https://api.modrinth.com/v2/project/server-portals'
23 changes: 23 additions & 0 deletions .github/workflows/remove-old-artifacts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://github.com/marketplace/actions/remove-artifacts
name: Remove old artifacts

on:
schedule:
# Every day at 1am
- cron: '0 1 * * *'

jobs:
remove-old-artifacts:
runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- name: Remove old artifacts
uses: c-hive/gha-remove-artifacts@v1
with:
# '<number> <unit>', e.g. 5 days, 2 years, 90 seconds, parsed by Moment.js
age: '2 days'

# Optional inputs
# skip-tags: true
# skip-recent: 5
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Initial project creation
Support for MC 1.19 - 1.20.2
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ because of that with [Polymer](https://polymer.pb4.eu/).

## Usage instructions

**NOTE: The server must get restarted to load these changes!**
<span style="color:darkred;font-weight:bold">
NOTE: The server must get restarted to load these changes!<br>
So after every change of the portals, restart the server (unfortunately)!
</span>

---
List configured portals:
Expand Down
34 changes: 34 additions & 0 deletions build.allprojects.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
allprojects {
// This can get extracted into a root build.gradle if needed
ext {
getLatestTag = {
new ByteArrayOutputStream().withStream { os ->
exec {
executable = "git"
args = ["describe", "--tags", "--abbrev=0"]
standardOutput = os
}
return os.toString().trim()
}
}

getCurrentCommitCount = {
new ByteArrayOutputStream().withStream { os ->
exec {
executable = "git"
args = ["rev-list", "--all", "--count"]
standardOutput = os
}
return os.toString().trim()
}
}
}

try {
project.version = "${project.getLatestTag()}.${project.getCurrentCommitCount()}"
} catch (Exception ignored) {
println('Either git is not set up properly, or there is no tag yet in the repository. Falling back to version \'0\'')
project.version = '0'
}
project.group = 'michiruf'
}
104 changes: 37 additions & 67 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,92 +1,63 @@
import de.michiruf.gradle.findversion.FindVersion

plugins {
id 'fabric-loom' version '1.0-SNAPSHOT'
id 'com.modrinth.minotaur' version '2.+'
id 'java'
id 'fabric-loom' version '1.4-SNAPSHOT'
}

allprojects {
// This can get extracted into a root build.gradle if needed
ext {
getLatestTag = {
new ByteArrayOutputStream().withStream { os ->
exec {
executable = "git"
args = ["describe", "--tags", "--abbrev=0"]
standardOutput = os
}
return os.toString().trim()
}
}
apply from: 'build.allprojects.gradle'
apply from: 'build.versions.gradle'

getCurrentCommitCount = {
new ByteArrayOutputStream().withStream { os ->
exec {
executable = "git"
args = ["rev-list", "--all", "--count"]
standardOutput = os
}
return os.toString().trim()
}
}
}
def minecraftVersion = project.minecraftVersion as String ?: '1.20.2'
def minecraftVersionDefinitions = ext.minecraftVersionDefinitions
def minecraftVersionDefinition = minecraftVersionDefinitions[minecraftVersion]
project.version = "${project.version}+${minecraftVersion}"

try {
project.version = "${project.ext.getLatestTag()}-${project.ext.getCurrentCommitCount()}"
} catch (Exception ignored) {
println('Either git is not set up properly, or there is no tag yet in the repository. Falling back to version \'0\'')
project.version = '0'
}
project.group = 'michiruf'
sourceSets {
main.java.srcDirs = [
'src/main/java',
"src/registry/${FindVersion.findClosestLowerOrEqualVersionInDirectory(file('src/registry'), minecraftVersion)}",
"src/message/${FindVersion.findClosestLowerOrEqualVersionInDirectory(file('src/message'), minecraftVersion)}",
"src/customportalapi-polymer/${FindVersion.findClosestLowerOrEqualVersionInDirectory(file('src/customportalapi-polymer'), minecraftVersion)}"
]
}

repositories {
mavenCentral()
maven { url 'https://maven.wispforest.io' } // Owo config
maven { url 'https://maven.kyrptonaught.dev' } // Custom portal api
maven { url 'https://maven.nucleoid.xyz' } // Custom portal api transitive
maven { url 'https://maven.nucleoid.xyz' } // Custom portal api transitive (polymer)
maven { url 'https://api.modrinth.com/maven' } // Custom portal api transitive (sodium)
}

dependencies {
// To change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

// Fabric API
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
// Minecraft and fabric
minecraft "com.mojang:minecraft:${minecraftVersion}"
mappings "net.fabricmc:yarn:${minecraftVersionDefinition['mappings']}:v2"
modImplementation "net.fabricmc:fabric-loader:${minecraftVersionDefinition['fabric']}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${minecraftVersionDefinition['fabricApi']}"

// Owo config
annotationProcessor modImplementation('io.wispforest:owo-lib:0.9.2+1.19')
modImplementation annotationProcessor("io.wispforest:owo-lib:${minecraftVersionDefinition['owo']}") { exclude group: 'net.fabricmc.fabric-api' }
// We could include owo-sentinel for auto download, see https://github.com/wisp-forest/owo-lib

// Custom portal api
modImplementation(include('net.kyrptonaught:customportalapi:0.0.1-beta54-1.19'))
modImplementation(include('net.kyrptonaught:cpa-polymer:1.0.0-1.19'))
modImplementation(include('eu.pb4:polymer:0.2.18+1.19.2'))
modImplementation include("net.kyrptonaught:customportalapi:${minecraftVersionDefinition['customportalapi']}") { exclude group: 'net.fabricmc.fabric-api' }
modImplementation include("eu.pb4:${minecraftVersionDefinition['polymer']}") { exclude group: 'net.fabricmc.fabric-api' }
}

modrinth {
projectId = 'server-portals'
versionNumber = project.version
versionType = project.version.contains('SNAPSHOT') ? 'alpha' : 'release'
gameVersions = ['1.19.2']
loaders = ['fabric']
dependencies {
required.project 'fabric-api'
required.project 'owo-lib'
}
uploadFile = remapJar
syncBodyFrom = rootProject.file("README.md").text

// Use the environment variable `$MODRINTH_TOKEN` for the token
// token = 'mySecretToken'
}
tasks.modrinth.dependsOn(tasks.modrinthSyncBody)

processResources {
inputs.property 'version', project.version
var replaceProperties = [
version : project.version,
minecraft: minecraftVersion,
mappings : minecraftVersionDefinition['mappings'],
fabric : minecraftVersionDefinition['fabric'],
fabricApi: minecraftVersionDefinition['fabricApi']
]
inputs.properties replaceProperties
filteringCharset 'UTF-8'

filesMatching('fabric.mod.json') {
expand 'version': project.version
expand replaceProperties
}
}

Expand All @@ -107,7 +78,6 @@ java {
if (JavaVersion.current() < javaVersion) {
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
}
archivesBaseName = project.archives_base_name
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
Expand Down
Loading

0 comments on commit 2e0157d

Please sign in to comment.