Skip to content

Commit aab9f3f

Browse files
committed
Add maven publishing
1 parent 1700779 commit aab9f3f

File tree

3 files changed

+170
-9
lines changed

3 files changed

+170
-9
lines changed

.github/workflows/release.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: release
2+
on:
3+
push:
4+
tags:
5+
- "**"
6+
workflow_dispatch:
7+
8+
jobs:
9+
publish:
10+
runs-on: ubuntu-22.04
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v2
14+
with:
15+
# Fetch all history
16+
fetch-depth: 0
17+
- name: Setup Java 21
18+
uses: actions/setup-java@v2
19+
with:
20+
distribution: 'temurin'
21+
java-version: '21'
22+
- name: Make gradle wrapper executable
23+
run: chmod +x ./gradlew
24+
- name: Maven Publish
25+
id: maven_publish
26+
env:
27+
ARCHIVE_URL: ${{ secrets.TEACON_ARCHIVE_URL }}
28+
ARCHIVE_ENDPOINT: ${{ secrets.TEACON_ARCHIVE_ENDPOINT }}
29+
ARCHIVE_ACCESS_KEY: ${{ secrets.TEACON_ARCHIVE_ACCESS_KEY }}
30+
ARCHIVE_SECRET_KEY: ${{ secrets.TEACON_ARCHIVE_SECRET_KEY }}
31+
run: ./gradlew -Dorg.gradle.s3.endpoint=$ARCHIVE_ENDPOINT publishReleasePublicationToTeaconRepository githubActionOutput
32+
- name: Generate Changelog
33+
id: changelog
34+
shell: bash
35+
env:
36+
CURRENT: ${{ github.ref }}
37+
# Special thanks to this post on Stack Overflow regarding change set between two tags:
38+
# https://stackoverflow.com/questions/12082981
39+
# Do note that actions/checkout will enter detach mode by default, so you won't have
40+
# access to HEAD ref. Use GitHub-Action-supplied `github.ref` instead.
41+
# Special thanks to this issue ticket regarding escaping newline:
42+
# https://github.com/actions/create-release/issues/25
43+
# We use Bash parameter expansion to do find-and-replace.
44+
# https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html
45+
# Also we cannot use git rev-list because it always prepend "commit <hash>"
46+
# See https://stackoverflow.com/questions/36927089/
47+
run: |
48+
current_tag=${CURRENT/refs\/tags\//}
49+
last_tag=`git describe --tags --abbrev=0 "$current_tag"^ 2>/dev/null || echo`
50+
if [ last_tag ]; then
51+
changelog=`git log --pretty="format:%H: %s" ${last_tag}..$current_tag`
52+
else
53+
changelog=`git log --pretty="format:%H: %s"`
54+
fi
55+
changelog="${changelog//'%'/'%25'}"
56+
changelog="${changelog//$'\n'/' %0A'}"
57+
echo "::set-output name=value::Change set since ${last_tag:-the beginning}: %0A%0A$changelog"
58+
- name: GitHub Release
59+
id: create_release
60+
uses: actions/create-release@v1.1.1
61+
env:
62+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
63+
with:
64+
tag_name: ${{ github.ref }}
65+
release_name: ${{ github.ref }}
66+
draft: false
67+
prerelease: false
68+
body: |
69+
${{ steps.changelog.outputs.value }}
70+
- name: GitHub Release Artifact
71+
uses: actions/upload-release-asset@v1.0.2
72+
env:
73+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
74+
with:
75+
upload_url: ${{ steps.create_release.outputs.upload_url }}
76+
asset_path: ${{ steps.maven_publish.outputs.artifact_path }}
77+
asset_name: ${{ steps.maven_publish.outputs.artifact_publish_name }}
78+
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
79+
asset_content_type: "application/java-archive"

build.gradle

Lines changed: 84 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,95 @@ tasks.withType(JavaCompile).configureEach {
6767
it.options.release = 21
6868
}
6969

70-
// Configure Maven publishing.
70+
71+
72+
7173
publishing {
7274
publications {
73-
mavenJava(MavenPublication) {
75+
// Modified by TeaCon
76+
register('release', MavenPublication) {
77+
// noinspection GroovyAssignabilityCheck
7478
from components.java
79+
version = rootProject.mod_version
80+
groupId = rootProject.maven_group
81+
artifactId = "$mod_github_repo-$rootProject.minecraft_version"
82+
pom {
83+
name = mod_github_repo
84+
url = "https://github.com/$mod_github_owner/$mod_github_repo"
85+
licenses {
86+
license {
87+
name = mod_license
88+
url = "https://github.com/$mod_github_owner/$mod_github_repo/blob/HEAD/LICENSE"
89+
}
90+
}
91+
organization {
92+
name = 'TeaConMC'
93+
url = 'https://github.com/teaconmc'
94+
}
95+
developers {
96+
for (mod_author in "$mod_authors".split(',')) {
97+
developer { id = mod_author.trim(); name = mod_author.trim() }
98+
}
99+
}
100+
issueManagement {
101+
system = 'GitHub Issues'
102+
url = "https://github.com/$mod_github_owner/$mod_github_repo/issues"
103+
}
104+
scm {
105+
url = "https://github.com/$mod_github_owner/$mod_github_repo"
106+
connection = "scm:git:git://github.com/$mod_github_owner/${mod_github_repo}.git"
107+
developerConnection = "scm:git:git@github.com:$mod_github_owner/${mod_github_repo}.git"
108+
}
109+
}
75110
}
76111
}
77-
78-
// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
79112
repositories {
80-
// Add repositories to publish to here.
81-
// Notice: This block does NOT have the same function as the block in the top level.
82-
// The repositories here will be used for publishing your artifact, not for
83-
// retrieving dependencies.
113+
// Modified by TeaCon
114+
maven {
115+
name "teacon"
116+
url "s3://maven/"
117+
credentials(AwsCredentials) {
118+
accessKey = System.env.ARCHIVE_ACCESS_KEY
119+
secretKey = System.env.ARCHIVE_SECRET_KEY
120+
}
121+
}
122+
}
123+
}
124+
125+
// Added by TeaCon
126+
tasks.withType(PublishToMavenRepository).configureEach {
127+
if (repository && repository.name == "archive") {
128+
it.onlyIf {
129+
System.env.MAVEN_USERNAME && System.env.MAVEN_PASSWORD
130+
}
84131
}
85132
}
133+
134+
abstract class TeaConDumpPathToGitHub extends DefaultTask {
135+
@Input
136+
abstract Property<String> getPublishName()
137+
@InputFile
138+
abstract RegularFileProperty getTargetFile()
139+
@TaskAction
140+
void dump() {
141+
if (System.env.GITHUB_ACTIONS) {
142+
File theFile = targetFile.getAsFile().get()
143+
144+
def outputFile = new File(System.env.GITHUB_OUTPUT)
145+
// Use the env-specific line separator for maximally possible compatibility
146+
def newLine = System.getProperty('line.separator')
147+
148+
// Write out new env variable for later usage
149+
outputFile << newLine << "artifact_name=${theFile.getName()}"
150+
outputFile << newLine << "artifact_publish_name=${publishName.get()}"
151+
outputFile << newLine << "artifact_path=${theFile.absolutePath}"
152+
}
153+
}
154+
}
155+
156+
// Added by TeaCon
157+
tasks.register("githubActionOutput", TeaConDumpPathToGitHub) { task ->
158+
task.onlyIf { System.env.GITHUB_ACTIONS }
159+
task.getTargetFile().set(jar.archiveFile)
160+
task.getPublishName().set("${jar.archiveBaseName.get()}-${version}.jar")
161+
}

gradle.properties

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ loom.platform = neoforge
44

55
# Mod properties
66
mod_version = 0.1.0
7-
maven_group = cn.zbx1425.projectme
7+
maven_group = cn.zbx1425
88
archives_name = project_me
99

1010
# Minecraft properties
@@ -13,3 +13,9 @@ minecraft_version = 1.21.1
1313
# Dependencies
1414
neoforge_version = 21.1.84
1515
yarn_mappings_patch_version = 1.21+build.4
16+
17+
# Publishing
18+
mod_license = MIT
19+
mod_authors = Zbx1425, Burning_TNT
20+
mod_github_owner = TeaConMC
21+
mod_github_repo = ProjectMe

0 commit comments

Comments
 (0)