Skip to content

Commit

Permalink
Add release workflow.
Browse files Browse the repository at this point in the history
  • Loading branch information
burningtnt committed Dec 9, 2024
1 parent 27a395b commit 8a526a2
Show file tree
Hide file tree
Showing 3 changed files with 160 additions and 3 deletions.
79 changes: 79 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: release
on:
push:
tags:
- "**"
workflow_dispatch:

jobs:
publish:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v2
with:
# Fetch all history
fetch-depth: 0
- name: Setup Java 21
uses: actions/setup-java@v2
with:
distribution: 'temurin'
java-version: '21'
- name: Make gradle wrapper executable
run: chmod +x ./gradlew
- name: Maven Publish
id: maven_publish
env:
ARCHIVE_URL: ${{ secrets.TEACON_ARCHIVE_URL }}
ARCHIVE_ENDPOINT: ${{ secrets.TEACON_ARCHIVE_ENDPOINT }}
ARCHIVE_ACCESS_KEY: ${{ secrets.TEACON_ARCHIVE_ACCESS_KEY }}
ARCHIVE_SECRET_KEY: ${{ secrets.TEACON_ARCHIVE_SECRET_KEY }}
run: ./gradlew -Dorg.gradle.s3.endpoint=$ARCHIVE_ENDPOINT publishReleasePublicationToTeaconRepository githubActionOutput
- name: Generate Changelog
id: changelog
shell: bash
env:
CURRENT: ${{ github.ref }}
# Special thanks to this post on Stack Overflow regarding change set between two tags:
# https://stackoverflow.com/questions/12082981
# Do note that actions/checkout will enter detach mode by default, so you won't have
# access to HEAD ref. Use GitHub-Action-supplied `github.ref` instead.
# Special thanks to this issue ticket regarding escaping newline:
# https://github.com/actions/create-release/issues/25
# We use Bash parameter expansion to do find-and-replace.
# https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html
# Also we cannot use git rev-list because it always prepend "commit <hash>"
# See https://stackoverflow.com/questions/36927089/
run: |
current_tag=${CURRENT/refs\/tags\//}
last_tag=`git describe --tags --abbrev=0 "$current_tag"^ 2>/dev/null || echo`
if [ last_tag ]; then
changelog=`git log --pretty="format:%H: %s" ${last_tag}..$current_tag`
else
changelog=`git log --pretty="format:%H: %s"`
fi
changelog="${changelog//'%'/'%25'}"
changelog="${changelog//$'\n'/' %0A'}"
echo "::set-output name=value::Change set since ${last_tag:-the beginning}: %0A%0A$changelog"
- name: GitHub Release
id: create_release
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
draft: false
prerelease: false
body: |
${{ steps.changelog.outputs.value }}
- name: GitHub Release Artifact
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ steps.maven_publish.outputs.artifact_path }}
asset_name: ${{ steps.maven_publish.outputs.artifact_publish_name }}
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
asset_content_type: "application/java-archive"
77 changes: 75 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -203,17 +203,90 @@ tasks.withType(ProcessResources).configureEach {
// Example configuration to allow publishing using the maven-publish plugin
publishing {
publications {
register('mavenJava', MavenPublication) {
// Modified by TeaCon
register('release', MavenPublication) {
// noinspection GroovyAssignabilityCheck
from components.java
version = rootProject.version
groupId = "appeng"
artifactId = "$mod_github_repo-NeoForge-$rootProject.minecraft_version"
pom {
name = mod_github_repo
url = "https://github.com/$mod_github_owner/$mod_github_repo"
licenses {
license {
name = mod_license
url = "https://github.com/$mod_github_owner/$mod_github_repo/blob/HEAD/LICENSE"
}
}
organization {
name = 'TeaConMC'
url = 'https://github.com/teaconmc'
}
developers {
for (mod_author in "$mod_authors".split(',')) {
developer { id = mod_author.trim(); name = mod_author.trim() }
}
}
issueManagement {
system = 'GitHub Issues'
url = "https://github.com/$mod_github_owner/$mod_github_repo/issues"
}
scm {
url = "https://github.com/$mod_github_owner/$mod_github_repo"
connection = "scm:git:git://github.com/$mod_github_owner/${mod_github_repo}.git"
developerConnection = "scm:git:[email protected]:$mod_github_owner/${mod_github_repo}.git"
}
}
}
}
repositories {
// Modified by TeaCon
maven {
url "file://${project.projectDir}/repo"
name "teacon"
url "s3://maven/"
credentials(AwsCredentials) {
accessKey = System.env.ARCHIVE_ACCESS_KEY
secretKey = System.env.ARCHIVE_SECRET_KEY
}
}
}
}
// Added by TeaCon
tasks.withType(PublishToMavenRepository).configureEach {
if (repository && repository.name == "archive") {
it.onlyIf {
System.env.MAVEN_USERNAME && System.env.MAVEN_PASSWORD
}
}
}

abstract class TeaConDumpPathToGitHub extends DefaultTask {
@Input
abstract Property<String> getPublishName()
@InputFile
abstract RegularFileProperty getTargetFile()
@TaskAction
void dump() {
if (System.env.GITHUB_ACTIONS) {
File theFile = targetFile.getAsFile().get()
def outputFile = new File(System.env.GITHUB_OUTPUT)
// Use the env-specific line separator for maximally possible compatibility
def newLine = System.getProperty('line.separator')
// Write out new env variable for later usage
outputFile << newLine << "artifact_name=${theFile.getName()}"
outputFile << newLine << "artifact_publish_name=${publishName.get()}"
outputFile << newLine << "artifact_path=${theFile.absolutePath}"
}
}
}
// Added by TeaCon
tasks.register("githubActionOutput", TeaConDumpPathToGitHub) { task ->
task.onlyIf { System.env.GITHUB_ACTIONS }
task.getTargetFile().set(jar.archiveFile)
task.getPublishName().set("${jar.archiveBaseName.get()}-${version}.jar")
}

tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation
}
Expand Down
7 changes: 6 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ mod_version=0.6.0
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
mod_group_id=org.teacon
# The authors of the mod. This is a simple text string that is used for display purposes in the mod list.
mod_authors=TeaConMC, USS_Shenzhou, ustc-zzzz
mod_authors=TeaConMC, USS_Shenzhou, ustc-zzzz, Burning_TNT
# The description of the mod. This is a simple multiline text string that is used for display purposes in the mod list.
mod_description=Sign up, sign in, in-game guide map and more.

# Added by TeaCon: gh owner
mod_github_owner=TeaConMC
# Added by TeaCon: gh repo name
mod_github_repo=SignMeUp

0 comments on commit 8a526a2

Please sign in to comment.