From 98e1fdecebdf82cecae6086859023c9dfd53c511 Mon Sep 17 00:00:00 2001 From: Faumaray Date: Mon, 20 Oct 2025 22:07:58 +0300 Subject: [PATCH] Jenkins file Signed-off-by: Faumaray --- Jenkinsfile | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..90426f9 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,106 @@ +pipeline { + agent any + + parameters { + string(name: 'TAG_NAME', defaultValue: 'latest', description: 'Tag name for Gitea release') + string(name: 'RELEASE_NAME', defaultValue: 'latest', description: 'Release name for Gitea release') + } + + stages { + stage('Build-Linux') { + tools { jdk 'JDK21' } + steps { + sh ''' + java -version + echo $JAVA_HOME + rm -rf build/linux + mkdir -p build/linux + cmake -B build/linux -DCMAKE_BUILD_TYPE=Release + cmake --build build/linux + ''' + } + } + + stage('Build-Windows') { + tools { jdk 'JDK21-WIN' } + steps { + sh ''' + java -version + echo $JAVA_HOME + rm -rf build/windows + mkdir -p build/windows + cmake -B build/windows -DCMAKE_TOOLCHAIN_FILE=mingw.cmake -DCMAKE_BUILD_TYPE=Release + cmake --build build/windows + ''' + } + } + + stage('Package-Artifacts') { + steps { + sh ''' + rm -rf dist + mkdir -p dist/native/windows dist/native/linux + + # collect libs + find build/linux -type f -name "*.vlmod" -exec cp {} dist/native/linux/ \\; + find build/windows -type f -name "*.vlmod" -exec cp {} dist/native/windows/ \\; + + cd dist + zip -r ../VoidLoaderApi.zip native + ''' + } + post { + success { + archiveArtifacts artifacts: 'VoidLoaderApi.zip', fingerprint: true + } + } + } + + stage('Publish-To-Gitea') { + steps { + withCredentials([string(credentialsId: 'GITEA_TOKEN', variable: 'GITEA_TOKEN')]) { + sh ''' + set -e + GITEA_URL="https://git.faumaray.ru" + REPO="VoidLoader/VoidLoaderApi" + TAG="${TAG_NAME:-latest}" + RELEASE="${RELEASE_NAME:-latest}" + + echo "📦 Preparing release: $RELEASE ($TAG)" + + # Ensure release exists + curl -s -X POST -H "Authorization: token $GITEA_TOKEN" \ + -H "Content-Type: application/json" \ + -d "{\\"tag_name\\": \\"$TAG\\", \\"name\\": \\"$RELEASE\\"}" \ + "$GITEA_URL/api/v1/repos/$REPO/releases" >/dev/null || true + + # Get release ID + RELEASE_ID=$(curl -s -H "Authorization: token $GITEA_TOKEN" \ + "$GITEA_URL/api/v1/repos/$REPO/releases/tags/$TAG" | jq -r '.id') + echo "✅ Release ID = $RELEASE_ID" + + # Delete any existing asset with same name + ASSET_ID=$(curl -s -H "Authorization: token $GITEA_TOKEN" \ + "$GITEA_URL/api/v1/repos/$REPO/releases/$RELEASE_ID/assets" | \ + jq -r '.[] | select(.name=="VoidLoaderApi.zip") | .id') + + if [ -n "$ASSET_ID" ] && [ "$ASSET_ID" != "null" ]; then + echo "🗑 Removing old asset (ID $ASSET_ID)" + curl -s -X DELETE -H "Authorization: token $GITEA_TOKEN" \ + "$GITEA_URL/api/v1/repos/$REPO/releases/$RELEASE_ID/assets/$ASSET_ID" >/dev/null || true + fi + + + # Upload new artifact + echo "⬆️ Uploading new VoidLoaderApi.zip ..." + curl -s -X POST -H "Authorization: token $GITEA_TOKEN" \ + -F "attachment=@VoidLoaderApi.zip" \ + "$GITEA_URL/api/v1/repos/$REPO/releases/$RELEASE_ID/assets" >/dev/null + + echo "🎉 Upload complete: $GITEA_URL/VoidLoader/VoidLoaderApi/releases/tag/$TAG" + ''' + } + } + } + } +}