Release and Publish #39
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release and Publish | |
| on: | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| env: | |
| APP_SLUG: cloud-api-plugin | |
| REGISTRY_URL: https://registry.simplecloud.app | |
| MINECRAFT_VERSIONS: | | |
| 1.20 | |
| 1.20.1 | |
| 1.20.2 | |
| 1.20.3 | |
| 1.20.4 | |
| 1.20.5 | |
| 1.20.6 | |
| 1.21 | |
| 1.21.1 | |
| 1.21.2 | |
| 1.21.3 | |
| 1.21.4 | |
| 1.21.5 | |
| 1.21.6 | |
| 1.21.7 | |
| 1.21.8 | |
| 1.21.9 | |
| jobs: | |
| build-and-publish: | |
| runs-on: blacksmith-4vcpu-ubuntu-2404 | |
| outputs: | |
| gradle_version: ${{ steps.versions.outputs.gradle_version }} | |
| commit_hash: ${{ steps.versions.outputs.commit_hash }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: main | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: 'temurin' | |
| java-version: '21' | |
| cache: 'gradle' | |
| - name: Setup Gradle | |
| uses: gradle/actions/setup-gradle@v3 | |
| with: | |
| cache-read-only: false | |
| - name: Make gradlew executable | |
| run: chmod +x ./gradlew | |
| - name: Get Versions | |
| id: versions | |
| run: | | |
| echo "gradle_version=$(./gradlew properties -q | grep "version:" | awk '{print $2}')" >> $GITHUB_OUTPUT | |
| echo "commit_hash=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT | |
| - name: Build and Publish All | |
| run: | | |
| # Build everything once | |
| ./gradlew clean build shadowJar \ | |
| publishMavenJavaPublicationToSimplecloudRepository \ | |
| modrinth modrinthSyncBody \ | |
| --parallel \ | |
| --build-cache \ | |
| --configuration-cache | |
| # Copy artifacts | |
| mkdir -p artifacts | |
| cp platform/spigot/build/libs/spigot.jar artifacts/ | |
| cp platform/bungeecord/build/libs/bungeecord.jar artifacts/ | |
| cp platform/velocity/build/libs/velocity.jar artifacts/ | |
| env: | |
| COMMIT_HASH: ${{ steps.versions.outputs.commit_hash }} | |
| SIMPLECLOUD_USERNAME: ${{ secrets.SIMPLECLOUD_USERNAME }} | |
| SIMPLECLOUD_PASSWORD: ${{ secrets.SIMPLECLOUD_PASSWORD }} | |
| MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }} | |
| - name: Upload artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: build-artifacts | |
| path: artifacts/*.jar | |
| compression-level: 0 | |
| publish-registry: | |
| needs: build-and-publish | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Download artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: build-artifacts | |
| path: artifacts | |
| - name: Create Registry Release | |
| id: create_registry_release | |
| run: | | |
| RELEASE_URL="${REGISTRY_URL}/v1/applications/${APP_SLUG}/releases" | |
| response=$(curl -s -X POST \ | |
| -H "Authorization: Bearer ${{ secrets.REGISTRY_TOKEN }}" \ | |
| -H "Content-Type: application/json" \ | |
| "$RELEASE_URL" \ | |
| -d '{ | |
| "version": "'"${{ needs.build-and-publish.outputs.gradle_version }}"'", | |
| "manual_update": false | |
| }') | |
| echo "Response: $response" | |
| APP_ID=$(echo $response | jq -r '.release.application_id') | |
| echo "APP_ID=$APP_ID" >> $GITHUB_ENV | |
| echo "Release created with APP_ID: $APP_ID" | |
| - name: Upload to Registry (Parallel) | |
| run: | | |
| PLATFORM_VERSIONS=$(echo "$MINECRAFT_VERSIONS" | jq -R -s 'split("\n") | map(select(length > 0))') | |
| upload_file() { | |
| local FILE=$1 | |
| local ARCH=$2 | |
| local URL="${REGISTRY_URL}/v1/applications/${APP_ID}/releases/${{ needs.build-and-publish.outputs.gradle_version }}/files" | |
| curl -s -X POST \ | |
| -H "Authorization: Bearer ${{ secrets.REGISTRY_TOKEN }}" \ | |
| -H "Content-Type: multipart/form-data" \ | |
| -F "file=@$FILE" \ | |
| -F "platform=minecraft_plugin" \ | |
| -F "arch=$ARCH" \ | |
| -F "platform_versions=$PLATFORM_VERSIONS" \ | |
| "$URL" | |
| } | |
| # Upload all platforms in parallel | |
| upload_file "artifacts/spigot.jar" "spigot" & | |
| upload_file "artifacts/spigot.jar" "paper" & | |
| upload_file "artifacts/bungeecord.jar" "bungeecord" & | |
| upload_file "artifacts/velocity.jar" "velocity" & | |
| wait | |
| echo "All uploads completed" | |
| create-github-release: | |
| needs: [ build-and-publish, publish-registry ] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: main | |
| sparse-checkout: | | |
| .github | |
| - name: Download artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: build-artifacts | |
| path: artifacts | |
| - name: Create GitHub Release | |
| id: create_release | |
| run: | | |
| RELEASE_TAG="v${{ needs.build-and-publish.outputs.gradle_version }}-dev.${{ needs.build-and-publish.outputs.commit_hash }}" | |
| RELEASE_NAME="v${{ needs.build-and-publish.outputs.gradle_version }}-dev.${{ needs.build-and-publish.outputs.commit_hash }}" | |
| RELEASE_BODY="This release contains dev builds for all platform modules." | |
| gh release create "$RELEASE_TAG" \ | |
| --title "$RELEASE_NAME" \ | |
| --notes "$RELEASE_BODY" \ | |
| --target main \ | |
| --prerelease | |
| echo "RELEASE_TAG=$RELEASE_TAG" >> $GITHUB_ENV | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Upload JARs to GitHub Release | |
| run: | | |
| for jar in $(find ./artifacts -type f -name "*.jar"); do | |
| if [[ $(basename "$jar") =~ -[0-9]+\.[0-9]+ ]]; then | |
| echo "Skipping $jar due to version number" | |
| else | |
| echo "Uploading $jar" | |
| gh release upload "$RELEASE_TAG" "$jar" | |
| fi | |
| done | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |