From 4d260e5ddea9eb18a4b6e9169749ef0fd7c2f6ab Mon Sep 17 00:00:00 2001 From: Vasco Lavos Date: Fri, 2 Feb 2024 20:11:05 +0000 Subject: [PATCH] Update build flow --- .github/workflows/gradle.yml | 63 +++++++++++++++++++++ changelog.txt | 2 + push_tag.py | 35 ++++++++++++ scripts/upload_releases.sh | 106 +++++++++++++++++++++++++++++++++++ 4 files changed, 206 insertions(+) create mode 100644 .github/workflows/gradle.yml create mode 100644 changelog.txt create mode 100644 push_tag.py create mode 100644 scripts/upload_releases.sh diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml new file mode 100644 index 0000000..46f8b4c --- /dev/null +++ b/.github/workflows/gradle.yml @@ -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 diff --git a/changelog.txt b/changelog.txt new file mode 100644 index 0000000..7c657d5 --- /dev/null +++ b/changelog.txt @@ -0,0 +1,2 @@ +- Updated several lang files +- Added a several mod items to the default config \ No newline at end of file diff --git a/push_tag.py b/push_tag.py new file mode 100644 index 0000000..6675f61 --- /dev/null +++ b/push_tag.py @@ -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() \ No newline at end of file diff --git a/scripts/upload_releases.sh b/scripts/upload_releases.sh new file mode 100644 index 0000000..5ce11e1 --- /dev/null +++ b/scripts/upload_releases.sh @@ -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 <&2 'Uploading Forge Jar to CurseForge' + local CURSEFORGE_FORGE_SPEC + CURSEFORGE_FORGE_SPEC=$(cat <