Skip to content

Commit

Permalink
Attempting to add GH actions
Browse files Browse the repository at this point in the history
  • Loading branch information
blackjack26 committed Apr 14, 2024
1 parent dd8ba73 commit 8e94ba1
Show file tree
Hide file tree
Showing 3 changed files with 183 additions and 12 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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/
109 changes: 108 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -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
}
Expand Down Expand Up @@ -85,7 +91,7 @@ java {

jar {
from("LICENSE") {
rename { "${it}_${project.archivesBaseName}"}
rename { "${it}_${project.archives_base_name}"}
}
}

Expand All @@ -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"
}
}
31 changes: 20 additions & 11 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -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
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

0 comments on commit 8e94ba1

Please sign in to comment.