Skip to content

Commit

Permalink
Update build flow
Browse files Browse the repository at this point in the history
  • Loading branch information
Vazkii committed Feb 2, 2024
1 parent 50babcc commit 4d260e5
Show file tree
Hide file tree
Showing 4 changed files with 206 additions and 0 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Java CI

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK
uses: actions/setup-java@v2
with:
distribution: 'temurin'
java-version: '17'
- name: Validate gradlew integrity
uses: gradle/wrapper-validation-action@v1
- name: Cache
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/build.gradle', '**/gradle-wrapper.properties') }}
- name: Build with Gradle
run: ./gradlew pmdMain build
- name: PMD report
uses: jwgmeligmeyling/pmd-github-action@v1
if: failure()
with:
path: '**/reports/pmd/main.xml'
- name: Stop Gradle
run: |
./gradlew --stop
- name: Calculate artifact names
id: calculate_artifact_names
run: |
VERSION=$(awk -F '=' '/^version/ { print $2; }' build.properties)
BUILD=$(awk -F '=' '/build_number/ { print $2; }' build.properties)
echo "forge=build/libs/Morphtool-${VERSION}-${BUILD}.jar" >> "$GITHUB_OUTPUT"
- name: Sign jars
env:
SIGNING_KEY: ${{ secrets.VIOLET_MOON_SIGNING_KEY }}
if: ${{ env.SIGNING_KEY != '' }}
run: |
echo "${SIGNING_KEY}" | gpg --import -
gpg --local-user "Violet Moon Signing Key" --armor \
--detach-sign ${{ steps.calculate_artifact_names.outputs.forge }}
- name: Archive Forge Artifacts
uses: actions/upload-artifact@v2
with:
name: Forge
path: |
${{ steps.calculate_artifact_names.outputs.forge }}
${{ steps.calculate_artifact_names.outputs.forge }}.asc
- name: Upload Releases
if: startsWith(github.ref, 'refs/tags/release-')
env:
GH_TOKEN: ${{ github.token }}
GIT_REF: ${{ github.ref }}
FORGE_JAR: ${{ steps.calculate_artifact_names.outputs.forge }}
CURSEFORGE_TOKEN: ${{ secrets.VAZKII_CURSEFORGE_TOKEN }}
MODRINTH_TOKEN: ${{ secrets.VAZKII_MODRINTH_TOKEN }}
run: |
scripts/upload_releases.sh
2 changes: 2 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Updated several lang files
- Added a several mod items to the default config
35 changes: 35 additions & 0 deletions push_tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import os
import re
from jproperties import Properties

def main():
build = Properties()
with open('build.properties', 'rb') as f:
build.load(f , "utf-8")

mc_version, mcv_meta = build['mc_version']
version, v_meta = build['version']
build_number, bn_meta = build['build_number']

print('MC Version:', mc_version)
print('Version:', version)
print('Build Number', build_number)

changelog = '-m "Changelog:" '
with open('changelog.txt', 'r') as f:
content = f.read()

content = content.replace('"', '\'');
changelog = changelog + re.sub(r'(- .+)\n?', '-m "\g<1>" ', content)

os.system('git tag -a release-{}-{}-{} {}'.format(mc_version, version, build_number, changelog))

build['build_number'] = str(int(build_number) + 1)
with open("build.properties", "wb") as f:
build.store(f, encoding="utf-8")

os.system('git commit -a -m build')
os.system('git push origin master release-{}-{}-{}'.format(mc_version, version, build_number))

if __name__ == '__main__':
main()
106 changes: 106 additions & 0 deletions scripts/upload_releases.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#!/usr/bin/env bash
set -euo pipefail

# Remove 'refs/tags/' from front
TAGNAME="${GIT_REF/#refs\/tags\/}"

# Remove 'release-' from front
VERSION="${TAGNAME/#release-}"
MC_VERSION=$(echo "${VERSION}" | cut -d '-' -f 1)

function release_github() {
echo >&2 'Creating GitHub Release'
local GH_RELEASE_RESPONSE
GH_RELEASE_RESPONSE="$(gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/VazkiiMods/Morphtool/releases \
-f tag_name="${TAGNAME}")"
GH_RELEASE_PAGE=$(echo "$GH_RELEASE_RESPONSE" | jq -r .html_url)

echo >&2 'Uploading Forge Jar and Signature to GitHub'
gh release upload "${TAGNAME}" "${FORGE_JAR}#Forge Jar"
gh release upload "${TAGNAME}" "${FORGE_JAR}.asc#Forge Signature"
}

function release_modrinth() {
echo >&2 'Uploading Forge Jar to Modrinth'
local MODRINTH_FORGE_SPEC
MODRINTH_FORGE_SPEC=$(cat <<EOF
{
"dependencies": [],
"version_type": "release",
"loaders": ["forge"],
"featured": false,
"project_id": "rtbzFq0N",
"file_parts": [
"jar"
],
"primary_file": "jar"
}
EOF
)

MODRINTH_FORGE_SPEC=$(echo "${MODRINTH_FORGE_SPEC}" | \
jq --arg name "${VERSION}" \
--arg mcver "${MC_VERSION}" \
--arg changelog "${GH_RELEASE_PAGE}" \
'.name=$ARGS.named.name | .version_number=$ARGS.named.name | .game_versions=[$ARGS.named.mcver] | .changelog=$ARGS.named.changelog')
curl 'https://api.modrinth.com/v2/version' \
-H "Authorization: $MODRINTH_TOKEN" \
-F "data=$MODRINTH_FORGE_SPEC" \
-F "jar=@${FORGE_JAR}" # TODO modrinth doesn't allow asc files. Remember to readd "signature" to the spec when reenabling this. \ -F "signature=@${FORGE_JAR}.asc"
}

function release_curseforge() {
# Java versions, Loaders, and Environment tags are actually "game versions" (lmfao), as are real game versions.

# Hardcoded from https://minecraft.curseforge.com/api/game/version-types (which is undocumented, btw)
# I'm not betting on these changing any time soon, so hardcoding is ok
local CURSEFORGE_JAVA_VERSION=8326 # Java 17
local CURSEFORGE_FORGE_VERSION=7498
local CURSEFORGE_CLIENT_VERSION=9638
local CURSEFORGE_SERVER_VERSION=9639
# For the Minecraft one, don't hardcode so we don't have to remember to come change this every time.
# Each game version seems to be duplicated three times:
# Once with type ID 1 (unused?), once with its major-version-specific type ID, and once with the type ID for "Addons" 615
# We want the second one. Just dirtily pluck it out based on this.
local CURSEFORGE_GAME_VERSION
CURSEFORGE_GAME_VERSION=$(curl https://minecraft.curseforge.com/api/game/versions \
-H 'Accept: application/json' \
-H "X-Api-Token: ${CURSEFORGE_TOKEN}" | \
jq --arg mcver "${MC_VERSION}" \
'map(select(.name == $ARGS.named.mcver and .gameVersionTypeID != 1 and .gameVersionTypeID != 615)) | first | .id')

echo >&2 'Uploading Forge Jar to CurseForge'
local CURSEFORGE_FORGE_SPEC
CURSEFORGE_FORGE_SPEC=$(cat <<EOF
{
"changelogType": "text",
"releaseType": "release"
}
EOF
)

local CURSEFORGE_FORGE_GAMEVERS="[\
$CURSEFORGE_JAVA_VERSION,\
$CURSEFORGE_CLIENT_VERSION,\
$CURSEFORGE_SERVER_VERSION,\
$CURSEFORGE_FORGE_VERSION,\
$CURSEFORGE_GAME_VERSION]"

CURSEFORGE_FORGE_SPEC=$(echo "$CURSEFORGE_FORGE_SPEC" | \
jq --arg changelog "$GH_RELEASE_PAGE" \
--argjson gamevers "$CURSEFORGE_FORGE_GAMEVERS" \
'.gameVersions=$ARGS.named.gamevers | .changelog=$ARGS.named.changelog')
curl 'https://minecraft.curseforge.com/api/projects/245287/upload-file' \
-H "X-Api-Token: $CURSEFORGE_TOKEN" \
-F "metadata=$CURSEFORGE_FORGE_SPEC" \
-F "file=@$FORGE_JAR"
# TODO: Upload the asc as an 'Additional file'
}

release_github
release_modrinth
release_curseforge

0 comments on commit 4d260e5

Please sign in to comment.