Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto update meta about new fapi versions #1249

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ jobs:
steps:
- uses: actions/checkout@v1
- uses: gradle/wrapper-validation-action@v1
- run: ./gradlew checkVersion build publish curseforge github --stacktrace
- run: ./gradlew checkVersion build publish curseforge github updateVersionMap --stacktrace
env:
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.GH_API_KEY }}
GRGIT_USER: ${{ secrets.GH_USER }}
GRGIT_PASS: ${{ secrets.GH_PASS }}
60 changes: 60 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ logger.lifecycle("Building Fabric: " + version)
import org.apache.commons.codec.digest.DigestUtils
import net.fabricmc.loom.task.RunClientTask
import net.fabricmc.loom.task.RunServerTask
import org.ajoberstar.grgit.Grgit

def getSubprojectVersion(project, version) {
if (grgit == null) {
Expand Down Expand Up @@ -389,6 +390,65 @@ task checkVersion {
}
}

// Authentication is provided by GRGIT_PASS and GRGIT_USER enviro. variables.
// GRGIT_PASS can be authentication token
// See https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token#using-a-token-on-the-command-line
task updateVersionMap() {
onlyIf {
ENV.GRGIT_PASS
}
dexman545 marked this conversation as resolved.
Show resolved Hide resolved
doLast {
Grgit repo
if (!buildDir.toPath().resolve('fabric-api-version-map').toFile().exists()) {
//noinspection GroovyAccessibility, GroovyAssignabilityCheck
repo = grgit.clone {
dir = buildDir.toPath().resolve('fabric-api-version-map').toFile()
uri = "https://github.com/dexman545/fabric-api-version-map.git" //TODO use official repo
} as Grgit
} else {
//noinspection GroovyAccessibility, GroovyAssignabilityCheck
repo = grgit.open {
dir = buildDir.toPath().resolve('fabric-api-version-map').toFile()
} as Grgit
}

def propFile = file("${buildDir}/fabric-api-version-map/apiVersions.properties")
def mc2Api = new Properties()
if (!propFile.exists()) return
propFile.withReader {mc2Api.load(it)}
String list = mc2Api.getProperty(Globals.mcVersion, "")
String separator = list.isEmpty() ? " " : ", "
mc2Api.setProperty(Globals.mcVersion, list + separator + version)

// Do not use Properties#store as it shuffles the file
boolean hasVersion = false
List<String> outLines = new ArrayList<>()
propFile.eachLine {
String[] parsed = it.split("=")
if (parsed[0].trim() == Globals.mcVersion) {
hasVersion = true
it = Globals.mcVersion + " = " + list + separator + version
}
outLines.add(it)
}

propFile.withWriter {
if (!hasVersion) { // Add new versions to top of file
it.write(Globals.mcVersion + " = " + list + separator + version)
it.newLine()
}
for (String ln : outLines) {
it.write(ln)
it.newLine()
}
}
repo.commit(message: 'Automated update', all: true)
repo.push()
repo.close()
buildDir.toPath().resolve('fabric-api-version-map').toFile().deleteDir() // Clean it up
}
}

github.mustRunAfter checkVersion
publish.mustRunAfter checkVersion
project.tasks.curseforge.mustRunAfter checkVersion