From 8e94ba160425e26e8a03ecd2f5db257fc6d8fb69 Mon Sep 17 00:00:00 2001 From: Jack Grzechowiak Date: Sun, 14 Apr 2024 09:23:52 -0400 Subject: [PATCH] Attempting to add GH actions --- .github/workflows/release.yml | 55 +++++++++++++++++ build.gradle | 109 +++++++++++++++++++++++++++++++++- gradle.properties | 31 ++++++---- 3 files changed, 183 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..cca07b2 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,55 @@ +name: Release +on: + workflow_dispatch: + inputs: + previousVersion: + description: 'Previous Version (Do not include v prefix, must be same as the last version tag! Example: 1.4.1)' + required: true + version: + description: 'Version (Do not include v prefix! Example: 1.4.2)' + required: true +jobs: + release: + strategy: + matrix: + java: [17] + os: [ubuntu-22.04] + runs-on: ${{ matrix.os }} + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Create version tag + uses: actions/github-script@v6 + with: + script: | + github.rest.git.createRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: "refs/tags/v${{ github.event.inputs.version }}", + sha: context.sha + }) + - name: Fetch tags + run: git fetch --tags + - name: Validate Gradle wrapper + uses: gradle/wrapper-validation-action@v1 + - name: Setup JDK ${{ matrix.java }} + uses: actions/setup-java@v3 + with: + distribution: zulu + java-version: ${{ matrix.java }} + - name: Make Grade wrapper executable + if: ${{ runner.os != 'Windows' }} + run: chmod +x ./gradlew + - name: Build + run: ./gradlew generateChangelog build githubRelease modrinth --stacktrace -PlastTag="v${{ github.event.inputs.previousVersion }}" -PcurrentTag="v${{ github.event.inputs.version }}" + env: + GITHUB_TOKEN: ${{ secrets.GH_API_KEY }} + MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }} + - name: Capture build artifacts + if: ${{ runner.os == 'Linux' && matrix.java == '17' }} + uses: actions/upload-artifact@v3 + with: + name: Artifacts + path: build/libs/ \ No newline at end of file diff --git a/build.gradle b/build.gradle index dfb7368..139520e 100644 --- a/build.gradle +++ b/build.gradle @@ -1,11 +1,17 @@ plugins { id 'fabric-loom' version '1.5-SNAPSHOT' id 'maven-publish' + id 'com.modrinth.minotaur' version '2.+' + id 'org.ajoberstar.grgit' version '5.2.2' + id 'com.github.breadmoirai.github-release' version '2.5.2' } version = project.mod_version group = project.maven_group +ext.releaseChangelog = "No Changelog Available" +ext.releaseType = project.default_release_type + base { archivesName = project.archives_base_name } @@ -85,7 +91,7 @@ java { jar { from("LICENSE") { - rename { "${it}_${project.archivesBaseName}"} + rename { "${it}_${project.archives_base_name}"} } } @@ -109,3 +115,104 @@ publishing { loom { accessWidenerPath = file("src/main/resources/blockgamejournal.accesswidener") } + +def lastTag = project.hasProperty("lastTag") ? project.lastTag : null +def currentTag = project.hasProperty("currentTag") ? project.currentTag : "HEAD" + +githubRelease { + setToken(System.getenv("GITHUB_TOKEN").toString()) + setOwner(project.github_owner) + setRepo(project.github_repo) + setTagName(currentTag) + setTargetCommitish(getBranch()) + setReleaseName("v$version for $project.minecraft_version") + setGenerateReleaseNotes(true) + setBody(releaseChangelog) + setPrerelease(releaseType != "release") + setReleaseAssets(file("${project.buildDir}/libs/${archives_base_name}-${version}.jar")) +} + +String getBranch() { + def ENV = System.getenv() + if (ENV.GITHUB_REF) { + def branch = ENV.GITHUB_REF + return branch.substring(branch.lastIndexOf('/') + 1) + } + + if (grgit == null) { + return "unknown" + } + + def branch = grgit.branch.current().name + return branch.substring(branch.lastIndexOf('/') + 1) +} + +tasks.register('generateChangelog') { + def changes = StringBuilder.getDeclaredConstructor().newInstance(); + if (!project.hasProperty("lastTag") || !project.hasProperty("currentTag")) { + println "Missing lastTag or currentTag property, skipping changelog generation" + return; + } + + def commits = "git log --max-count=${project.changelog_max_commit_search} --pretty=format:\"%b\" $lastTag..$currentTag".execute() + println "Last version: $lastTag" + println "Current version: $currentTag" + + if (currentTag.contains("-alpha")) { + releaseType = "alpha" + } else if (currentTag.contains("-beta") || currentTag.contains("-rc") || currentTag.contains("-pre")) { + releaseType = "beta" + } else { + releaseType = "release" + } + println "Release type: $releaseType" + + commits.in.eachLine { line -> + def processedLine = line.toString() + if (processedLine.startsWith("\"")) { + processedLine = processedLine.substring(1) + } + if (processedLine.endsWith("\"")) { + processedLine = processedLine.substring(0, processedLine.length() - 1) + } + println "Reading line: $processedLine" + + if (processedLine.startsWith("- ")) { + println "Adding changelog line:" + println " $processedLine" + if (changes.length() == 0) { + changes << processedLine + } else { + changes << "\n$processedLine" + } + } + } + + commits.err.eachLine { line -> println line } + commits.waitFor() + + println "Changelog:" + releaseChangelog = changes.toString() + if (releaseChangelog.isEmpty()) { + releaseChangelog = "No Changelog Available" + } + println releaseChangelog +} + +modrinth { + token = System.getenv("MODRINTH_TOKEN") + projectId = project.modrinth_id + versionNumber = "$version" + versionName = "v$version for $project.minecraft_version" + changelog = releaseChangelog + uploadFile = file("${project.buildDir}/libs/${archives_base_name}-${version}.jar") + versionType = releaseType + gameVersions = ["1.20.2"] + loaders = ["fabric"] + dependencies { + required.project "fabric-api" + required.project "cloth-config" + optional.project "modmenu" + optional.project "emi" + } +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 35c4121..50b5b3e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,19 +1,28 @@ -# Done to increase the memory available to gradle. org.gradle.jvmargs=-Xmx1G -# Fabric Properties +maven_group=dev.bnjc +archives_base_name=blockgame-journal + +# Fabric/Dependency Metadata # check these on https://modmuss50.me/fabric.html minecraft_version=1.20.2 yarn_mappings=1.20.2+build.4 loader_version=0.15.7 - -# Mod Properties -mod_version = 0.1.0 -maven_group = dev.bnjc -archives_base_name = blockgame-journal - -# Dependencies -# check this on https://modmuss50.me/fabric.html fabric_version=0.91.6+1.20.2 cloth_config_version=12.0.119 -mod_menu_version=8.0.1 \ No newline at end of file +mod_menu_version=8.0.1 + +# Project Metadata +mod_version=0.1.0-alpha +default_release_type=release +github_owner=blackjack26 +github_repo=blockgame-journal +github_url=https://github.com/blackjack26/blockgame-journal + +# Modrinth Metadata +modrinth_slug=blockgame-journal +modrinth_id=L5NYZWmU + +# Changelog Options +changelog_hide_unimportant_commits=true +changelog_max_commit_search=200 \ No newline at end of file