Skip to content

Commit

Permalink
Merge branch 'master' into 24w46a
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander01998 committed Nov 20, 2024
2 parents 5788240 + 475c392 commit bef90c6
Show file tree
Hide file tree
Showing 4 changed files with 179 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/dependency_graph.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ name: Update Gradle Dependency Graph

on:
push:
branches:
# Submitting dependency graph reports on non-default branches does nothing
- "master"
tags-ignore:
- "**"
paths:
- "gradle**"
- "*.gradle"
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@ name: Java CI with Gradle

on:
push:
branches:
- "**"
tags-ignore:
- "**"
paths:
- "**.java"
- "**.json"
- "**.yml"
- "gradle**"
- "*.gradle"
pull_request:
paths:
- "**.java"
- "**.json"
- "**.yml"
- "gradle**"
- "*.gradle"
workflow_dispatch:
Expand Down
90 changes: 90 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Publish Release

on:
workflow_dispatch:
inputs:
close_milestone:
description: "Close milestone"
required: true
type: boolean
default: true
upload_backups:
description: "Upload to backups server"
required: true
type: boolean
default: true
publish_github:
description: "Publish to GitHub"
required: true
type: boolean
default: true
update_website:
description: "Update WurstClient.net post (only works if there already is one)"
required: true
type: boolean
default: false

jobs:
publish:
runs-on: ubuntu-latest
env:
WI_BACKUPS_API_KEY: ${{ secrets.WI_BACKUPS_API_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:

- uses: actions/checkout@v4
with:
# Include all tags in case the new tag already exists.
fetch-tags: true

- name: Set up Java 21
uses: actions/setup-java@v4
with:
java-version: "21"
distribution: "microsoft"

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4

- name: Build
run: ./gradlew build --stacktrace --warning-mode=fail

- name: Create and push tag
run: |
MOD_VERSION=$(grep "mod_version" gradle.properties | cut -d'=' -f2 | tr -d ' ')
git config --global user.name "Wurst-Bot"
git config --global user.email "[email protected]"
git tag $MOD_VERSION
git push origin $MOD_VERSION
- name: Close milestone
if: ${{ inputs.close_milestone }}
run: ./gradlew closeMilestone --stacktrace

- name: Upload backups
if: ${{ inputs.upload_backups }}
run: ./gradlew uploadBackups --stacktrace

- name: Publish to GitHub
if: ${{ inputs.publish_github }}
env:
GITHUB_TOKEN: ${{ secrets.OLD_MCX_PUBLISH_TOKEN }}
run: ./gradlew github --stacktrace

- name: Trigger website update
if: ${{ inputs.update_website }}
env:
GH_TOKEN: ${{ secrets.WURSTCLIENT_NET_PUBLISH_TOKEN }}
run: |
MOD_VERSION=$(grep "mod_version" gradle.properties | cut -d'=' -f2 | tr -d ' ')
WURST_VERSION=$(echo $MOD_VERSION | sed 's/^v//' | sed 's/-MC.*$//')
MC_VERSION=$(grep "minecraft_version" gradle.properties | cut -d'=' -f2 | tr -d ' ')
FAPI_VERSION=$(grep "fabric_version" gradle.properties | cut -d'=' -f2 | tr -d ' ')
gh workflow run add_wurst_port.yml \
-R Wurst-Imperium/WurstClient.net \
-f wurst_version="$WURST_VERSION" \
-f mc_version="$MC_VERSION" \
-f fapi_version="$FAPI_VERSION"
80 changes: 78 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ java {

jar {
from("LICENSE") {
rename {"${it}_${project.base.archivesName.get()}"}
rename {"${it}_${base.archivesName.get()}"}
}
}

Expand All @@ -151,6 +151,15 @@ test {
useJUnitPlatform()
}

def getGhVersion() {
return "v" + version.substring(0, version.indexOf("-MC"))
}

def getChangelogUrl() {
def versionSlug = version.substring(0, version.indexOf("-MC")).replace(".", "-")
return "https://www.wurstclient.net/updates/wurst-${versionSlug}/"
}

import org.kohsuke.github.GHReleaseBuilder
import org.kohsuke.github.GitHub

Expand All @@ -162,7 +171,7 @@ task github(dependsOn: build) {
doLast {
def github = GitHub.connectUsingOAuth(ENV.GITHUB_TOKEN as String)
def repository = github.getRepository("Wurst-Imperium/Wurst-MCX2")
def ghVersion = version.substring(0, version.indexOf("-"))
def ghVersion = getGhVersion()

def ghRelease = repository.getReleaseByTagName(ghVersion as String)
if(ghRelease == null) {
Expand All @@ -175,3 +184,70 @@ task github(dependsOn: build) {
ghRelease.uploadAsset(remapSourcesJar.archiveFile.get().getAsFile(), "application/java-archive")
}
}

import java.time.LocalDate
import org.kohsuke.github.GHIssueState
import org.kohsuke.github.GHMilestoneState
import java.time.ZoneId

task closeMilestone {
onlyIf {
ENV.GITHUB_TOKEN
}

doLast {
def github = GitHub.connectUsingOAuth(ENV.GITHUB_TOKEN as String)
def repository = github.getRepository("Wurst-Imperium/Wurst7")
def ghVersion = getGhVersion()

// Weird API design: listMilestones() requires GHIssueState while everything else uses GHMilestoneState.
def milestone = repository.listMilestones(GHIssueState.ALL).find { it.title == ghVersion }
if (milestone == null) {
milestone = repository.createMilestone(ghVersion, "")
}

if (milestone.getState() != GHMilestoneState.CLOSED) {
milestone.setDueOn(Date.from(LocalDate.now().atStartOfDay(ZoneId.systemDefault()).toInstant()))
milestone.setDescription(getChangelogUrl())
milestone.close()
}
}
}

task uploadBackups {
dependsOn build

onlyIf {
ENV.WI_BACKUPS_API_KEY
}

doLast {
def shortVersion = getGhVersion().substring(1)
def backupUrl = "https://api.wurstclient.net/artifact-backups/Wurst/${shortVersion}"

def connection = new URL(backupUrl).openConnection() as HttpURLConnection
def boundary = UUID.randomUUID().toString()
connection.setRequestMethod("POST")
connection.setRequestProperty("X-API-Key", ENV.WI_BACKUPS_API_KEY)
connection.setRequestProperty("Accept", "application/json")
connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=$boundary")
connection.doOutput = true

def output = connection.outputStream
[remapJar, remapSourcesJar].each { jarTask ->
def file = jarTask.archiveFile.get().asFile
output << "--${boundary}\r\n"
output << "Content-Disposition: form-data; name=\"files\"; filename=\"${file.name}\"\r\n"
output << "Content-Type: application/java-archive\r\n\r\n"
file.withInputStream { input ->
output << input
}
output << "\r\n"
}
output << "--${boundary}--\r\n"
output.flush()

if(connection.responseCode != 200)
throw new GradleException("Failed to upload backups: ${connection.responseCode} ${connection.responseMessage}")
}
}

0 comments on commit bef90c6

Please sign in to comment.