Skip to content

Commit

Permalink
Github workflow fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Swedz committed Sep 17, 2024
1 parent 07f2443 commit afa2233
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 18 deletions.
29 changes: 11 additions & 18 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@ jobs:
deploy:
runs-on: ubuntu-latest
steps:
# Set up Github actions, JDK & Gradle
- uses: actions/checkout@v2
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: 21
cache: gradle
distribution: temurin
- name: Grant execute permission for gradlew
run: chmod +x gradlew

# Load the variables needed
- name: Load gradle.properties into the environment
Expand All @@ -31,16 +40,8 @@ jobs:
run: |
echo "MOD_VERSION=$(echo "$GITHUB_RELEASE_TAG_NAME" | sed -E 's/-[^-]+$//')" >> $GITHUB_ENV
echo "RELEASE_TYPE=$(echo "$GITHUB_RELEASE_TAG_NAME" | grep -oE '(alpha|beta)' || echo "release")" >> $GITHUB_ENV
{
echo "MOD_CHANGELOG_TRIMMED_DISCORD<<EOF"
echo "$(echo "$MOD_CHANGELOG" | sed '/## What'"'"'s Changed/d' | sed 's/## New Contributors/**New Contributors**/g' | sed -E 's/@([a-zA-Z0-9_]+)/`\@\1`/g' | sed -E 's|https://github.com/([^ ]+)/pull/([0-9]+)|[#\2](https://github.com/\1/pull/\2)|g' | sed -E 's|\*\*Full Changelog\*\*: (https://github.com/[^ ]+/compare/[^\s]+)|[Full Changelog](\1)|g' | sed -E ':a;N;$!ba;s/\r{0,1}\n/\\n/g' | sed 's/\\n\\n/\\n/g')"
echo "EOF"
} >> $GITHUB_ENV
{
echo "MOD_CHANGELOG_TRIMMED_PUBLISH<<EOF"
echo "$(echo "$MOD_CHANGELOG" | sed -E 's/@([a-zA-Z0-9_]+)/`\@\1`/g' | sed -E 's|https://github.com/([^ ]+)/pull/([0-9]+)|[#\2](https://github.com/\1/pull/\2)|g' | sed -E 's|\*\*Full Changelog\*\*: (https://github.com/[^ ]+/compare/[^\s]+)|[Full Changelog](\1)|g')"
echo "EOF"
} >> $GITHUB_ENV
- name: Build changelog
run: ./gradlew buildChangelog
- name: Finalize variables
run: |
echo "MOD_VERSION_SHORT=${MOD_VERSION%%-*}" >> $GITHUB_ENV
Expand All @@ -53,14 +54,6 @@ jobs:
cat prepared_discord_message.json
# Build the mod and publish it to ModMaven, CurseForge, and Modrinth
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: 21
cache: gradle
distribution: temurin
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build
- name: Publish to ModMaven
Expand Down
56 changes: 56 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,62 @@ task sourceJar(type: Jar) {
from "LICENSE"
}

static def trimChangelog(String changelog, int maxLength, boolean discordFormat) {
if(discordFormat) {
changelog = changelog.replaceAll(/## What's Changed\n/, '')

changelog = changelog.replaceAll(/## New Contributors/, '**New Contributors**')
}

changelog = changelog.replaceAll(/@([a-zA-Z0-9_]+)/, '`@$1`')

changelog = changelog.replaceAll(/https:\/\/github.com\/([^ ]+)\/pull\/([0-9]+)/, '[#\$2](https://github.com/\$1/pull/\$2)')

changelog = changelog.replaceAll(/\*\*Full Changelog\*\*: (https:\/\/github.com\/[^ ]+\/compare\/[^\s]+)/, '[Full Changelog](\$1)')

if(discordFormat) {
changelog = changelog.replaceAll(/\r?\n/, '\\\\n')
changelog = changelog.replaceAll(/\\\\n\\\\n/, '\\\\n')
}

if(maxLength > 0) {
def changelogLines = changelog.split('\\\\n')
def lastLine = changelogLines[-1]
def trimmedChangelog = []
def currentLength = lastLine.length()

for (int i = 0; i < changelogLines.size() - 1; i++) {
def line = changelogLines[i]
if (currentLength + line.length() + 2 + 5 > maxLength) {
trimmedChangelog << '...'
break
}
trimmedChangelog << line
currentLength += line.length() + 2
}

trimmedChangelog << lastLine

return trimmedChangelog.join('\\n')
} else {
return changelog
}
}

tasks.register('buildChangelog') {
doLast {
def githubEnvFile = new File(System.getenv("GITHUB_ENV"))

def changelog = System.getenv("MOD_CHANGELOG")

def changelogTrimmedDiscord = trimChangelog(changelog, 1024, true)
githubEnvFile.append("MOD_CHANGELOG_TRIMMED_DISCORD=${changelogTrimmedDiscord}\n")

def changelogTrimmedPublish = trimChangelog(changelog, 0, false)
githubEnvFile.append("MOD_CHANGELOG_TRIMMED_PUBLISH=${changelogTrimmedPublish}\n")
}
}

publishing {
publications {
mavenJava(MavenPublication) {
Expand Down

0 comments on commit afa2233

Please sign in to comment.