From 0c6b21948667d88fdb8a94e59d9c08a18f846e18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Becker?= Date: Wed, 14 Jan 2026 15:24:45 +0100 Subject: [PATCH] feat: publish to Modtale --- .github/workflows/modtale-publish.yml | 86 +++++++++++++++++++++++++++ .github/workflows/plugin-ci.yml | 49 +++++++++++++++ 2 files changed, 135 insertions(+) create mode 100644 .github/workflows/modtale-publish.yml diff --git a/.github/workflows/modtale-publish.yml b/.github/workflows/modtale-publish.yml new file mode 100644 index 0000000..3e4fe15 --- /dev/null +++ b/.github/workflows/modtale-publish.yml @@ -0,0 +1,86 @@ +name: Modtale Publish (Reusable) + +on: + workflow_call: + inputs: + artifact-name: + description: "Name of the artifact to download (from a previous job)" + type: string + default: "build-artifacts" + artifact-id: + description: "The artifact ID (jar name prefix)" + type: string + required: true + channel: + description: "The Modtale channel (RELEASE|BETA|ALPHA)" + type: string + default: "RELEASE" + version: + description: "The version to publish" + type: string + required: true + game-versions: + description: "Hytale game versions (comma-separated)" + type: string + default: "1.0.0" + changelog: + description: "Changelog for this version" + type: string + default: "Automated Build & Release from GitHub" + secrets: + MODTALE_API_KEY: + description: "Modtale API key for authentication" + required: true + MODTALE_PROJECT_ID: + description: "Modtale project ID" + required: true + +jobs: + publish-modtale: + runs-on: ubuntu-latest + steps: + - name: Download Build Artifacts + uses: actions/download-artifact@v7 + with: + name: ${{ inputs.artifact-name }} + + - name: Upload to Modtale + env: + MODTALE_API_KEY: ${{ secrets.MODTALE_API_KEY }} + MODTALE_PROJECT_ID: ${{ secrets.MODTALE_PROJECT_ID }} + run: | + # Find the built jar (exclude sources/javadoc jars if present) + JAR_PATH=$(find . -name "${{ inputs.artifact-id }}-${{ inputs.version }}.jar" -print | head -n 1) + + if [[ -z "$JAR_PATH" ]]; then + echo "ERROR: Could not find jar file matching ${{ inputs.artifact-id }}-${{ inputs.version }}.jar" + echo "Available files:" + find . -name "*.jar" -print + exit 1 + fi + + echo "Found Jar: $JAR_PATH" + echo "Publishing Version: ${{ inputs.version }}" + echo "Game Versions: ${{ inputs.game-versions }}" + + RESPONSE=$(curl -s -w "\n%{http_code}" -X POST "https://api.modtale.net/api/v1/projects/$MODTALE_PROJECT_ID/versions" \ + -H "X-MODTALE-KEY: $MODTALE_API_KEY" \ + -F "file=@$JAR_PATH" \ + -F "channel=${{ inputs.channel }}" \ + -F "versionNumber=${{ inputs.version }}" \ + -F "gameVersions=${{ inputs.game-versions }}" \ + -F "changelog=${{ inputs.changelog }}") + + HTTP_CODE=$(echo "$RESPONSE" | tail -n 1) + BODY=$(echo "$RESPONSE" | sed '$d') + + echo "Response: $BODY" + echo "HTTP Status: $HTTP_CODE" + + if [[ "$HTTP_CODE" -ge 200 && "$HTTP_CODE" -lt 300 ]]; then + echo "Successfully published to Modtale!" + else + echo "ERROR: Failed to publish to Modtale (HTTP $HTTP_CODE)" + exit 1 + fi + diff --git a/.github/workflows/plugin-ci.yml b/.github/workflows/plugin-ci.yml index 983bd9b..9640e39 100644 --- a/.github/workflows/plugin-ci.yml +++ b/.github/workflows/plugin-ci.yml @@ -47,6 +47,12 @@ on: GCS_BUCKET: description: "GCS bucket for artifact upload" required: false + MODTALE_API_KEY: + description: "Modtale API key for authentication" + required: false + MODTALE_PROJECT_ID: + description: "Modtale project ID" + required: false outputs: version: description: "The resolved version" @@ -310,3 +316,46 @@ jobs: -DaltDeploymentRepository=publish-repo::${{ secrets.MAVEN_PUBLISH_URL }} -DskipTests + fetch-release-notes: + needs: [build, publish] + if: ${{ needs.build.outputs.is_release == 'true' && needs.build.result == 'success' && needs.publish.result == 'success' }} + runs-on: ubuntu-latest + outputs: + changelog: ${{ steps.get-notes.outputs.changelog }} + steps: + - name: Fetch GitHub Release Notes + id: get-notes + env: + GH_TOKEN: ${{ github.token }} + run: | + TAG_NAME="${{ needs.build.outputs.tag_name }}" + echo "Fetching release notes for tag: $TAG_NAME" + + RELEASE_BODY=$(gh api repos/${{ github.repository }}/releases/tags/$TAG_NAME --jq '.body // empty' 2>/dev/null || echo "") + + if [[ -n "$RELEASE_BODY" ]]; then + echo "Found GitHub release notes" + # Use EOF delimiter to handle multi-line output + { + echo 'changelog<> $GITHUB_OUTPUT + else + echo "No GitHub release notes found, using default" + echo "changelog=Automated Build & Release from GitHub" >> $GITHUB_OUTPUT + fi + + publish-modtale: + needs: [build, publish, fetch-release-notes] + if: ${{ needs.build.outputs.is_release == 'true' && secrets.MODTALE_API_KEY != '' && secrets.MODTALE_PROJECT_ID != '' }} + uses: ./.github/workflows/modtale-publish.yml + with: + artifact-id: ${{ needs.build.outputs.artifact_id }} + version: ${{ needs.build.outputs.version }} + channel: ${{ (needs.build.outputs.is_prerelease == 'true') && 'BETA' || 'RELEASE' }} + changelog: ${{ needs.fetch-release-notes.outputs.changelog }} + secrets: + MODTALE_API_KEY: ${{ secrets.MODTALE_API_KEY }} + MODTALE_PROJECT_ID: ${{ secrets.MODTALE_PROJECT_ID }} +