Skip to content

fix: workflow

fix: workflow #12

Workflow file for this run

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"]'
jobs:
build:
runs-on: ubuntu-latest
outputs:
gradle_version: ${{ steps.versions.outputs.gradle_version }}
commit_hash: ${{ steps.versions.outputs.commit_hash }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: main
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '21'
- name: Cache Gradle packages
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
gradle-${{ runner.os }}
- 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 ShadowJars
run: |
./gradlew clean build shadowJar
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/
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: build-artifacts
path: artifacts/*.jar
compression-level: 0
publish-registry:
needs: build
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"
echo "Creating release at: $RELEASE_URL"
echo "Headers:"
echo " Content-Type: application/json"
echo "Body:"
echo '{
"version": "'"${{ needs.build.outputs.gradle_version }}"'",
"manual_update": false
}'
response=$(curl -X POST \
-H "Authorization: Bearer ${{ secrets.REGISTRY_TOKEN }}" \
-H "Content-Type: application/json" \
"$RELEASE_URL" \
-d '{
"version": "'"${{ needs.build.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
run: |
# Upload Spigot Platform
SPIGOT_URL="${REGISTRY_URL}/v1/applications/${APP_ID}/releases/${{ needs.build.outputs.gradle_version }}/files"
echo "Uploading Spigot to: $SPIGOT_URL"
echo "Headers:"
echo " Content-Type: multipart/form-data"
echo "Form data:"
echo " platform: minecraft_plugin"
echo " arch: spigot"
echo " platform_versions: ${{ env.MINECRAFT_VERSIONS }}"
curl -X POST \
-H "Authorization: Bearer ${{ secrets.REGISTRY_TOKEN }}" \
-H "Content-Type: multipart/form-data" \
-F "file=@artifacts/spigot.jar" \
-F "platform=minecraft_plugin" \
-F "arch=spigot" \
-F "platform_versions=${{ env.MINECRAFT_VERSIONS }}" \
"$SPIGOT_URL"
# Upload Paper Platform (same jar as Spigot)
PAPER_URL="${REGISTRY_URL}/v1/applications/${APP_ID}/releases/${{ needs.build.outputs.gradle_version }}/files"
echo "Uploading Paper to: $PAPER_URL"
echo "Headers:"
echo " Content-Type: multipart/form-data"
echo "Form data:"
echo " platform: minecraft_plugin"
echo " arch: paper"
echo " platform_versions: ${{ env.MINECRAFT_VERSIONS }}"
curl -X POST \
-H "Authorization: Bearer ${{ secrets.REGISTRY_TOKEN }}" \
-H "Content-Type: multipart/form-data" \
-F "file=@artifacts/spigot.jar" \
-F "platform=minecraft_plugin" \
-F "arch=paper" \
-F "platform_versions=${{ env.MINECRAFT_VERSIONS }}" \
"$PAPER_URL"
# Upload BungeeCord Platform
BUNGEE_URL="${REGISTRY_URL}/v1/applications/${APP_ID}/releases/${{ needs.build.outputs.gradle_version }}/files"
echo "Uploading BungeeCord to: $BUNGEE_URL"
echo "Headers:"
echo " Content-Type: multipart/form-data"
echo "Form data:"
echo " platform: minecraft_plugin"
echo " arch: bungeecord"
echo " platform_versions: ${{ env.MINECRAFT_VERSIONS }}"
curl -X POST \
-H "Authorization: Bearer ${{ secrets.REGISTRY_TOKEN }}" \
-H "Content-Type: multipart/form-data" \
-F "file=@artifacts/bungeecord.jar" \
-F "platform=minecraft_plugin" \
-F "arch=bungeecord" \
-F "platform_versions=${{ env.MINECRAFT_VERSIONS }}" \
"$BUNGEE_URL"
# Upload Velocity Platform
VELOCITY_URL="${REGISTRY_URL}/v1/applications/${APP_ID}/releases/${{ needs.build.outputs.gradle_version }}/files"
echo "Uploading Velocity to: $VELOCITY_URL"
echo "Headers:"
echo " Content-Type: multipart/form-data"
echo "Form data:"
echo " platform: minecraft_plugin"
echo " arch: velocity"
echo " platform_versions: ${{ env.MINECRAFT_VERSIONS }}"
curl -X POST \
-H "Authorization: Bearer ${{ secrets.REGISTRY_TOKEN }}" \
-H "Content-Type: multipart/form-data" \
-F "file=@artifacts/velocity.jar" \
-F "platform=minecraft_plugin" \
-F "arch=velocity" \
-F "platform_versions=${{ env.MINECRAFT_VERSIONS }}" \
"$VELOCITY_URL"
echo "All uploads completed"
publish-maven:
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: main
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '21'
- name: Make gradlew executable
run: chmod +x ./gradlew
- name: Publish to SimpleCloud Repository
run: ./gradlew publishMavenJavaPublicationToSimplecloudRepository
env:
COMMIT_HASH: ${{ needs.build.outputs.commit_hash }}
SIMPLECLOUD_USERNAME: ${{ secrets.SIMPLECLOUD_USERNAME }}
SIMPLECLOUD_PASSWORD: ${{ secrets.SIMPLECLOUD_PASSWORD }}
publish-modrinth:
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: main
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '21'
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: build-artifacts
path: platform
- name: Make gradlew executable
run: chmod +x ./gradlew
- name: Publish to Modrinth
run: ./gradlew modrinth && ./gradlew modrinthSyncBody
env:
COMMIT_HASH: ${{ needs.build.outputs.commit_hash }}
MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}
create-github-release:
needs: [ build, publish-registry, publish-maven, publish-modrinth ]
runs-on: ubuntu-latest
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: build-artifacts
path: artifacts
- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
with:
tag_name: v${{ needs.build.outputs.gradle_version }}-dev.${{ needs.build.outputs.commit_hash }}
release_name: v${{ needs.build.outputs.gradle_version }}-dev.${{ needs.build.outputs.commit_hash }}
draft: false
prerelease: true
commitish: main
body: |
This release contains dev builds for all platform modules.
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 v${{ needs.build.outputs.gradle_version }}-dev.${{ needs.build.outputs.commit_hash }} "$jar"
fi
done
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}