From 5c1b28d1bd1dbefbd8ec14a2f195a13f0b39a492 Mon Sep 17 00:00:00 2001 From: P3pp3rF1y Date: Mon, 16 Sep 2024 00:10:38 +0200 Subject: [PATCH] =?UTF-8?q?chore:=20=F0=9F=94=A7=20auto=20curseforge=20upl?= =?UTF-8?q?oad?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/gradle.yml | 26 ++++++--- build.gradle | 106 +++++++++++++++++++++++++++++++++++ gradle.properties | 5 ++ 3 files changed, 129 insertions(+), 8 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 695e0024..a9d4db9a 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -8,9 +8,9 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v4 - name: Set up JDK 17 - uses: actions/setup-java@v2 + uses: actions/setup-java@v4 with: java-version: 17 distribution: zulu @@ -19,7 +19,7 @@ jobs: env: USERNAME: ${{ secrets.USERNAME }} READ_PACKAGES_TOKEN: ${{ secrets.READ_PACKAGES_TOKEN }} - uses: nick-invision/retry@v2 + uses: nick-invision/retry@v3 with: timeout_minutes: 10 max_attempts: 3 @@ -29,10 +29,22 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: ./gradlew build publish - name: Cleanup old artifacts - uses: actions/delete-package-versions@v3 + uses: actions/delete-package-versions@v5 with: package-name: 'sophisticatedbackpacks.sophisticatedbackpacks' + package-type: 'maven' min-versions-to-keep: 10 + - name: Publish to CurseForge + env: + CURSEFORGE_TOKEN: ${{ secrets.CURSEFORGE_TOKEN }} + run: | + BRANCH_NAME=${GITHUB_REF##*/} + if [[ "$BRANCH_NAME" =~ ^[0-9]+\.[0-9]+\.([0-9]+|x)$ ]]; then + ./gradlew curseforge + else + echo "Branch name does not match the pattern: $BRANCH_NAME. Skipping CurseForge upload." + exit 0 + fi - name: Code Quality env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -43,7 +55,7 @@ jobs: echo "VERSION_NAME=$(${{github.workspace}}/gradlew -q printVersionName | awk -F "version:" '{printf $2}')" >> $GITHUB_OUTPUT id: version - name : Compile version message - uses: actions/github-script@v6 + uses: actions/github-script@v7 with: script: | const gh = ${{ toJSON(github) }}; @@ -64,11 +76,9 @@ jobs: core.setOutput('EMBED_DESCRIPTION', description); id: embed - name: Send Discord Notification - uses: tsickert/discord-webhook@v5.3.0 + uses: tsickert/discord-webhook@v6.0.0 with: webhook-url: ${{ secrets.DISCORD_WEBHOOK }} - embeds: ${{steps.embed.outputs.EMBEDS}} - content: null embed-title: "${{steps.embed.outputs.EMBED_TITLE}}" embed-url: "${{steps.embed.outputs.EMBED_URL}}" embed-description: "${{steps.embed.outputs.EMBED_DESCRIPTION}}" diff --git a/build.gradle b/build.gradle index c9db4f26..4cf821e6 100644 --- a/build.gradle +++ b/build.gradle @@ -4,6 +4,7 @@ plugins { id "maven-publish" id 'net.neoforged.gradle' version '[6.0.18,6.2)' id 'org.parchmentmc.librarian.forgegradle' version '1.+' + id "net.darkhax.curseforgegradle" version "1.1.15" } idea { @@ -207,6 +208,111 @@ sonarqube { } } +task generateChangelog { + def changelog = new StringBuilder() + + // Function to remove characters with Unicode code points 129 or higher + def removeHighUnicodeChars = { text -> + text.replaceAll(/[\u0081-\uFFFF]/, '') + } + + // Function to format commit messages with nesting + def formatMultilineMessage = { message -> + // Split message by lines, trim whitespace, and create formatted list + def lines = message.split('\n') + def formattedMessage = lines[0].trim() // First line as top-level list item + if (lines.size() > 1) { + formattedMessage += "\n" + lines[1..-1].collect { line -> + // Trim the line and remove leading dash if present + def trimmedLine = line.trim() + if (trimmedLine.startsWith('-')) { + trimmedLine = trimmedLine.substring(1).trim() + } + " - ${trimmedLine}" // Nested list for additional lines + }.join('\n') + } + return formattedMessage + } + + // Function to remove [DEV] section from commit message + def removeDevSection = { message -> + def devIndex = message.indexOf('[DEV]') + if (devIndex != -1) { + return message.substring(0, devIndex).trim() + } + return message + } + + // Get the latest commit hash + def latestCommitHash = "git rev-parse HEAD".execute().text.trim() + + // Check if the latest commit is a merge commit + def parentCommits = "git rev-list --parents -n 1 ${latestCommitHash}".execute().text.split() + + def commitMessages = [] + if (parentCommits.size() > 2) { // Merge commit has more than 2 parents + def firstParent = parentCommits[1] + def secondParent = parentCommits[2] + def gitLogCommand = [ + "bash", "-c", "git log --pretty=format:%B ${firstParent}..${secondParent}" + ] + commitMessages = gitLogCommand.execute().text.split('\n\n') // Split by two newlines for each commit + } else { + // Single commit log + commitMessages = "git log -1 --pretty=%B".execute().text.split('\n\n') // Split by two newlines for each commit + } + + def features = [] + def fixes = [] + + commitMessages.each { commitMessage -> + commitMessage = removeHighUnicodeChars(commitMessage) // Remove high Unicode characters + commitMessage = removeDevSection(commitMessage) // Remove [DEV] section + + if (commitMessage.startsWith('feat: ')) { + features.add(commitMessage.replaceFirst('feat: ', '').trim()) + } else if (commitMessage.startsWith('fix: ')) { + fixes.add(commitMessage.replaceFirst('fix: ', '').trim()) + } + } + + if (features) { + changelog.append("### Features\n") + features.each { feature -> changelog.append("- ${formatMultilineMessage(feature)}\n") } + } + + if (fixes) { + changelog.append("### Fixes\n") + fixes.each { fix -> changelog.append("- ${formatMultilineMessage(fix)}\n") } + } + + // Store the changelog in a project property or an environment variable + project.ext.changelog = changelog.toString() + println(changelog.toString()) +} + +task curseforge(type: net.darkhax.curseforgegradle.TaskPublishCurseForge) { + dependsOn 'generateChangelog' + + debugMode = true + apiToken = System.getenv("CURSEFORGE_TOkEN") + def mainFile = upload(project.curseforge_id, file("${project.buildDir}/libs/${archivesBaseName}-${version}.jar")) + mainFile.changelogType = 'markdown' + mainFile.changelog = project.ext.changelog + mainFile.addModLoader('NeoForge') + mainFile.addModLoader('Forge') + mainFile.releaseType = "${release_type}" + "${release_versions}".split(',').each { + mainFile.addGameVersion("${it}") + } + mainFile + mainFile.addRequirement('sophisticated-core') + mainFile.addOptional('jei') + mainFile.addOptional('curios') + mainFile.addOptional('crafting-tweaks') + onlyIf { !project.ext.changelog.isEmpty() } +} + task printVersionName { println "version:" + project.version } diff --git a/gradle.properties b/gradle.properties index 1c192ac3..9a8db184 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,6 +14,11 @@ neo_version=47.1.5 neo_version_range=[47.1,) loader_version_range=[47,) +#publish +curseforge_id=422301 +release_type=release +release_versions=1.20.1 + #deps jei_mc_version=1.20.1-forge jei_version=15.3.0.4