9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-29 03:49:21 +00:00
Files
Leaf/.github/workflows/publish-api.yml
adabugra 8ee5743e43 Integrate Download API into CI workflow (#328)
* Implement Build API integration to 1.21.4 build workflow

* Rename cd dir

* Enhance build workflow to dynamically fetch/clone repository

* Move to publish-api.yml
2025-05-20 05:32:30 +08:00

99 lines
3.5 KiB
YAML

name: Publish API
on:
push:
branches: [ "ver/1.21.4" ]
jobs:
build:
runs-on: ubuntu-latest
env:
BUILD_NUMBER: ${{ github.run_number }}
GRADLE_MEMORY: "-Xmx4g -XX:MaxMetaspaceSize=2g"
steps:
- name: Checkout repository
uses: actions/checkout@main
with:
fetch-depth: 0
- name: Set up GraalVM JDK 21
uses: graalvm/setup-graalvm@main
with:
java-version: 21
github-token: "${{ secrets.GITHUB_TOKEN }}"
cache: gradle
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Configure Git
run: |
git config --global user.email "no-reply@github.com"
git config --global user.name "Github Actions"
- name: Apply patches
run: |
PARALLELISM=$(($(nproc) * 2))
./gradlew -Dorg.gradle.jvmargs="${{ env.GRADLE_MEMORY }}" \
-Dleaf.patcher.parallelism=$PARALLELISM \
-Dleaf.patcher.incremental=true \
applyAllPatches \
--stacktrace --parallel \
--max-workers=$PARALLELISM \
--build-cache \
--no-daemon
- name: Build
run: ./gradlew createMojmapPaperclipJar --stacktrace --parallel --no-daemon
- name: Publish API
continue-on-error: true
run: |
./gradlew :leaf-api:publish
./gradlew publishDevBundlePublicationToLeafRepository -PpublishDevBundle=true
env:
REPO_USER: ${{ secrets.REPO_USER }}
REPO_PASSWORD: ${{ secrets.REPO_PASSWORD }}
- name: Calculate SHA-256
id: hash
run: |
FILE_NAME="leaf-1.21.4-${{ env.BUILD_NUMBER }}-mojmap.jar"
HASH=$(sha256sum "$FILE_NAME" | awk '{ print $1 }')
echo "sha256=$HASH" >> $GITHUB_OUTPUT
- name: Rename JAR
run: |
mv "leaf-1.21.4-${{ env.BUILD_NUMBER }}-mojmap.jar" "leaf-1.21.4-${{ env.BUILD_NUMBER }}.jar"
- name: Upload JAR to download API
uses: appleboy/scp-action@master
with:
host: ${{ secrets.API_HOST }}
username: ${{ secrets.API_USER }}
password: ${{ secrets.API_PASS }}
source: "./leaf-1.21.4-${{ env.BUILD_NUMBER }}.jar"
target: "~/api/uploads/"
- name: Insert build to download API
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.API_HOST }}
username: ${{ secrets.API_USER }}
password: ${{ secrets.API_PASS }}
script: |
BRANCH="${{ github.ref_name }}"
REPO_DIR="/root/Leaf-${BRANCH//\//-}" # Replace slashes with dashes to avoid directory issues
[ -d "$REPO_DIR/.git" ] && cd "$REPO_DIR" && git fetch origin && git checkout "$BRANCH" && git reset --hard "origin/$BRANCH" || git clone --branch "$BRANCH" --depth 1 https://github.com/Winds-Studio/Leaf "$REPO_DIR"
# Proceed to insert the build into the API
cd ~/api/cli
node insertBuild.js \
--projectName leaf \
--projectFriendlyName "Leaf" \
--version 1.21.4 \
--build-number ${{ env.BUILD_NUMBER }} \
--repositoryPath "$REPO_DIR" \
--storagePath /root/api/storage \
--download "primary:/root/api/uploads/leaf-1.21.4-${{ env.BUILD_NUMBER }}.jar:${{ steps.hash.outputs.sha256 }}" \
--buildChannel default