compile & release script feature
This commit is contained in:
+110
-126
@@ -18,30 +18,28 @@ set "GRADLE_HOME=%LOCAL_GRADLE_DIR%\gradle-%GRADLE_VERSION%"
|
||||
set "GRADLE_BIN=%GRADLE_HOME%\bin\gradle.bat"
|
||||
set "GIT_ONLY=0"
|
||||
|
||||
REM Values below are read from gradle.properties. Do not hardcode release versions here.
|
||||
set "MOD_VERSION="
|
||||
set "MINECRAFT_VERSION="
|
||||
set "MAVEN_GROUP="
|
||||
set "ARCHIVES_BASE_NAME="
|
||||
|
||||
if not exist "%GRADLE_PROPERTIES%" (
|
||||
echo [ERROR] gradle.properties tidak ditemukan.
|
||||
goto :failed
|
||||
call :finish 1
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
for /f "usebackq tokens=1,* delims==" %%A in ("%GRADLE_PROPERTIES%") do (
|
||||
if "%%A"=="mod_version" set "MOD_VERSION=%%B"
|
||||
if "%%A"=="minecraft_version" set "MINECRAFT_VERSION=%%B"
|
||||
if "%%A"=="maven_group" set "MAVEN_GROUP=%%B"
|
||||
if "%%A"=="archives_base_name" set "ARCHIVES_BASE_NAME=%%B"
|
||||
)
|
||||
|
||||
if not defined MOD_VERSION (
|
||||
echo [ERROR] mod_version tidak ditemukan atau kosong di gradle.properties.
|
||||
goto :failed
|
||||
call :finish 1
|
||||
exit /b 1
|
||||
)
|
||||
if not defined MINECRAFT_VERSION set "MINECRAFT_VERSION=26.2"
|
||||
if not defined MAVEN_GROUP set "MAVEN_GROUP=me.xjqsh"
|
||||
if not defined ARCHIVES_BASE_NAME set "ARCHIVES_BASE_NAME=lrarmor"
|
||||
|
||||
set "JAR_PATH=%CD%\build\libs\%ARCHIVES_BASE_NAME%-%MOD_VERSION%.jar"
|
||||
@@ -49,8 +47,8 @@ set "SOURCES_JAR_PATH=%CD%\build\libs\%ARCHIVES_BASE_NAME%-%MOD_VERSION%-sources
|
||||
|
||||
call :banner
|
||||
|
||||
REM If the exact release JAR already exists, offer rebuild or Git-only.
|
||||
REM --build-only always rebuilds and never enters Git integration.
|
||||
REM Jika JAR versi persis sudah ada, user boleh compile ulang atau Git-only.
|
||||
REM --build-only selalu melakukan build dan tidak menjalankan Git integration.
|
||||
if "%BUILD_ONLY%"=="0" if exist "%JAR_PATH%" (
|
||||
echo.
|
||||
echo [INFO] JAR untuk v%MOD_VERSION% sudah tersedia:
|
||||
@@ -59,104 +57,100 @@ if "%BUILD_ONLY%"=="0" if exist "%JAR_PATH%" (
|
||||
choice /C CG /N /M "[C] Compile ulang / [G] Git saja: "
|
||||
if errorlevel 2 (
|
||||
set "GIT_ONLY=1"
|
||||
goto :git_integration
|
||||
goto git_integration
|
||||
)
|
||||
)
|
||||
|
||||
REM If JAR is absent, empty build/libs, or version differs from gradle.properties,
|
||||
REM compilation proceeds automatically.
|
||||
where java.exe >nul 2>&1
|
||||
if errorlevel 1 (
|
||||
echo [ERROR] Java tidak ditemukan di PATH.
|
||||
echo Install JDK 25, buka terminal baru, lalu jalankan script lagi.
|
||||
goto :failed
|
||||
echo [INFO] Install JDK 25, buka terminal baru, lalu jalankan script lagi.
|
||||
call :finish 1
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
for /f "delims=" %%J in ('where java.exe 2^>nul') do (
|
||||
set "JAVA_PATH=%%J"
|
||||
goto :java_path_found
|
||||
)
|
||||
|
||||
:java_path_found
|
||||
set "JAVA_PATH="
|
||||
for /f "delims=" %%J in ('where java.exe 2^>nul') do if not defined JAVA_PATH set "JAVA_PATH=%%J"
|
||||
echo [INFO] Java executable: %JAVA_PATH%
|
||||
|
||||
set "JAVA_VERSION="
|
||||
for /f "tokens=2" %%V in ('java --version 2^>^&1 ^| findstr /R /C:"^openjdk " /C:"^java "') do (
|
||||
if not defined JAVA_VERSION set "JAVA_VERSION=%%V"
|
||||
)
|
||||
|
||||
for /f "tokens=2" %%V in ('java --version 2^>^&1 ^| findstr /R /C:"^openjdk " /C:"^java "') do if not defined JAVA_VERSION set "JAVA_VERSION=%%V"
|
||||
if not defined JAVA_VERSION (
|
||||
echo [ERROR] Tidak dapat membaca versi Java.
|
||||
goto :failed
|
||||
call :finish 1
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
for /f "tokens=1 delims=." %%M in ("%JAVA_VERSION%") do set "JAVA_MAJOR=%%M"
|
||||
|
||||
if not "%JAVA_MAJOR%"=="25" (
|
||||
echo [ERROR] Java 25 diperlukan.
|
||||
echo [INFO] Java yang terdeteksi: %JAVA_VERSION%
|
||||
goto :failed
|
||||
echo [ERROR] Java 25 diperlukan. Terdeteksi: %JAVA_VERSION%
|
||||
call :finish 1
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo [OK] Java 25 terdeteksi.
|
||||
|
||||
if exist "%GRADLE_BIN%" goto :gradle_ready
|
||||
if not exist "%GRADLE_BIN%" (
|
||||
echo [INFO] Gradle %GRADLE_VERSION% belum tersedia.
|
||||
echo [INFO] Mengunduh distribusi resmi...
|
||||
if not exist "%LOCAL_GRADLE_DIR%" mkdir "%LOCAL_GRADLE_DIR%"
|
||||
set "GRADLE_ZIP=%LOCAL_GRADLE_DIR%\gradle-%GRADLE_VERSION%-bin.zip"
|
||||
set "GRADLE_URL=https://services.gradle.org/distributions/gradle-%GRADLE_VERSION%-bin.zip"
|
||||
|
||||
echo [INFO] Gradle %GRADLE_VERSION% belum tersedia.
|
||||
echo [INFO] Mengunduh distribusi resmi...
|
||||
where curl.exe >nul 2>&1
|
||||
if errorlevel 1 (
|
||||
echo [ERROR] curl.exe tidak ditemukan.
|
||||
call :finish 1
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
if not exist "%LOCAL_GRADLE_DIR%" mkdir "%LOCAL_GRADLE_DIR%"
|
||||
curl.exe -L --fail --progress-bar "!GRADLE_URL!" -o "!GRADLE_ZIP!"
|
||||
if errorlevel 1 (
|
||||
echo [ERROR] Gagal mengunduh Gradle %GRADLE_VERSION%.
|
||||
call :finish 1
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
set "GRADLE_ZIP=%LOCAL_GRADLE_DIR%\gradle-%GRADLE_VERSION%-bin.zip"
|
||||
set "GRADLE_URL=https://services.gradle.org/distributions/gradle-%GRADLE_VERSION%-bin.zip"
|
||||
|
||||
where curl.exe >nul 2>&1
|
||||
if errorlevel 1 (
|
||||
echo [ERROR] curl.exe tidak ditemukan.
|
||||
goto :failed
|
||||
echo [INFO] Mengekstrak Gradle %GRADLE_VERSION%...
|
||||
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Expand-Archive -LiteralPath '!GRADLE_ZIP!' -DestinationPath '%LOCAL_GRADLE_DIR%' -Force"
|
||||
if errorlevel 1 (
|
||||
echo [ERROR] Gagal mengekstrak Gradle.
|
||||
call :finish 1
|
||||
exit /b 1
|
||||
)
|
||||
del /q "!GRADLE_ZIP!" >nul 2>&1
|
||||
)
|
||||
|
||||
curl.exe -L --fail --progress-bar "%GRADLE_URL%" -o "%GRADLE_ZIP%"
|
||||
if errorlevel 1 (
|
||||
echo [ERROR] Gagal mengunduh Gradle %GRADLE_VERSION%.
|
||||
goto :failed
|
||||
)
|
||||
|
||||
echo [INFO] Mengekstrak Gradle %GRADLE_VERSION%...
|
||||
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Expand-Archive -LiteralPath '%GRADLE_ZIP%' -DestinationPath '%LOCAL_GRADLE_DIR%' -Force"
|
||||
if errorlevel 1 (
|
||||
echo [ERROR] Gagal mengekstrak Gradle.
|
||||
goto :failed
|
||||
)
|
||||
|
||||
del /q "%GRADLE_ZIP%" >nul 2>&1
|
||||
|
||||
if not exist "%GRADLE_BIN%" (
|
||||
echo [ERROR] Gradle berhasil diekstrak tetapi executable tidak ditemukan.
|
||||
goto :failed
|
||||
echo [ERROR] Gradle executable tidak ditemukan: %GRADLE_BIN%
|
||||
call :finish 1
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
:gradle_ready
|
||||
echo [OK] Gradle %GRADLE_VERSION% tersedia.
|
||||
echo [INFO] Menjalankan clean build LesRaisinsArmor v%MOD_VERSION%...
|
||||
echo.
|
||||
|
||||
call "%GRADLE_BIN%" clean build --no-daemon
|
||||
if errorlevel 1 goto :build_failed
|
||||
if errorlevel 1 (
|
||||
echo.
|
||||
echo ============================================
|
||||
echo BUILD FAILED
|
||||
echo ============================================
|
||||
echo [ERROR] Build gagal. Git Integration tidak dijalankan.
|
||||
if "%BUILD_ONLY%"=="1" exit /b 1
|
||||
call :finish 1
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo.
|
||||
echo ============================================
|
||||
echo BUILD SUCCESS
|
||||
echo ============================================
|
||||
|
||||
if exist "%JAR_PATH%" (
|
||||
echo JAR:
|
||||
echo %JAR_PATH%
|
||||
) else (
|
||||
echo [WARN] Build berhasil, tetapi JAR utama tidak ditemukan pada:
|
||||
echo [WARN] Build berhasil, tetapi JAR utama tidak ditemukan:
|
||||
echo %JAR_PATH%
|
||||
)
|
||||
|
||||
if exist "%SOURCES_JAR_PATH%" (
|
||||
echo SOURCES JAR:
|
||||
echo %SOURCES_JAR_PATH%
|
||||
@@ -166,8 +160,14 @@ if "%BUILD_ONLY%"=="1" exit /b 0
|
||||
|
||||
echo.
|
||||
choice /C YN /N /M "Commit dan push perubahan ke Git? [Y/N]: "
|
||||
if errorlevel 2 goto :skip_git
|
||||
if errorlevel 1 goto :git_integration
|
||||
if errorlevel 2 (
|
||||
echo.
|
||||
echo [INFO] Git commit/push dilewati.
|
||||
call :finish 0
|
||||
exit /b 0
|
||||
)
|
||||
|
||||
goto git_integration
|
||||
|
||||
:git_integration
|
||||
echo.
|
||||
@@ -179,35 +179,37 @@ if "%GIT_ONLY%"=="1" echo [INFO] Mode Git-only: build dilewati karena JAR v%MOD_
|
||||
where git.exe >nul 2>&1
|
||||
if errorlevel 1 (
|
||||
echo [ERROR] Git tidak ditemukan di PATH.
|
||||
goto :git_failed
|
||||
call :git_fail_message
|
||||
call :finish 2
|
||||
exit /b 2
|
||||
)
|
||||
|
||||
git rev-parse --is-inside-work-tree >nul 2>&1
|
||||
if errorlevel 1 (
|
||||
echo [ERROR] Folder ini belum menjadi Git repository.
|
||||
echo.
|
||||
echo Jalankan terlebih dahulu:
|
||||
echo git init
|
||||
echo git branch -M main
|
||||
echo git remote add origin ^<URL-GIT^>
|
||||
echo.
|
||||
goto :git_failed
|
||||
call :git_fail_message
|
||||
call :finish 2
|
||||
exit /b 2
|
||||
)
|
||||
|
||||
set "CURRENT_BRANCH="
|
||||
for /f "delims=" %%B in ('git branch --show-current') do set "CURRENT_BRANCH=%%B"
|
||||
if not defined CURRENT_BRANCH (
|
||||
echo [ERROR] Tidak dapat menentukan branch Git aktif.
|
||||
goto :git_failed
|
||||
call :git_fail_message
|
||||
call :finish 2
|
||||
exit /b 2
|
||||
)
|
||||
|
||||
git remote get-url origin >nul 2>&1
|
||||
if errorlevel 1 (
|
||||
echo [ERROR] Remote Git 'origin' belum dikonfigurasi.
|
||||
echo [INFO] Commit lokal tetap aman.
|
||||
goto :git_failed
|
||||
call :git_fail_message
|
||||
call :finish 2
|
||||
exit /b 2
|
||||
)
|
||||
|
||||
set "ORIGIN_URL="
|
||||
for /f "delims=" %%R in ('git remote get-url origin') do set "ORIGIN_URL=%%R"
|
||||
echo [INFO] Branch : !CURRENT_BRANCH!
|
||||
echo [INFO] Origin : !ORIGIN_URL!
|
||||
@@ -221,7 +223,6 @@ if defined HAS_CHANGES (
|
||||
echo Perubahan ditemukan:
|
||||
git status --short
|
||||
echo.
|
||||
|
||||
call :suggest_commit_message
|
||||
echo [SUGGEST] Commit message: !SUGGESTED_COMMIT!
|
||||
echo [INFO] Tekan Enter untuk memakai saran tersebut, atau ketik pesan sendiri.
|
||||
@@ -234,14 +235,18 @@ if defined HAS_CHANGES (
|
||||
git add -A
|
||||
if errorlevel 1 (
|
||||
echo [ERROR] git add gagal.
|
||||
goto :git_failed
|
||||
call :git_fail_message
|
||||
call :finish 2
|
||||
exit /b 2
|
||||
)
|
||||
|
||||
echo [INFO] Membuat commit...
|
||||
git commit -m "!COMMIT_MESSAGE!"
|
||||
if errorlevel 1 (
|
||||
echo [ERROR] git commit gagal.
|
||||
goto :git_failed
|
||||
call :git_fail_message
|
||||
call :finish 2
|
||||
exit /b 2
|
||||
)
|
||||
) else (
|
||||
echo [INFO] Tidak ada perubahan source yang perlu di-commit.
|
||||
@@ -249,11 +254,17 @@ if defined HAS_CHANGES (
|
||||
)
|
||||
|
||||
call :push_branch_with_retry
|
||||
if errorlevel 1 goto :git_failed
|
||||
if errorlevel 1 (
|
||||
call :git_fail_message
|
||||
call :finish 2
|
||||
exit /b 2
|
||||
)
|
||||
|
||||
echo.
|
||||
echo [SUCCESS] Push ke Git berhasil.
|
||||
goto :success
|
||||
REM Jangan GOTO label akhir; selesai langsung agar tidak terkena masalah label parsing.
|
||||
call :finish 0
|
||||
exit /b 0
|
||||
|
||||
:banner
|
||||
echo ============================================
|
||||
@@ -271,10 +282,9 @@ set "HAS_DOC_CHANGE="
|
||||
for /f "delims=" %%F in ('git status --porcelain') do (
|
||||
set "LINE=%%F"
|
||||
echo !LINE! | findstr /I /C:"src/" >nul && set "HAS_SRC_CHANGE=1"
|
||||
echo !LINE! | findstr /I /C:"compile.bat" /C:"compile.sh" /C:"run-client.bat" /C:"run-server.bat" >nul && set "HAS_SCRIPT_CHANGE=1"
|
||||
echo !LINE! | findstr /I /C:"compile.bat" /C:"compile.sh" /C:"release.bat" /C:"run-client.bat" /C:"run-server.bat" >nul && set "HAS_SCRIPT_CHANGE=1"
|
||||
echo !LINE! | findstr /I /C:"README" /C:"LICENSE" /C:"PORT-CHANGELOG" >nul && set "HAS_DOC_CHANGE=1"
|
||||
)
|
||||
|
||||
if defined HAS_SRC_CHANGE set "SUGGESTED_COMMIT=Port LesRaisinsArmor v%MOD_VERSION%"
|
||||
if not defined HAS_SRC_CHANGE if defined HAS_SCRIPT_CHANGE set "SUGGESTED_COMMIT=Update build scripts for v%MOD_VERSION%"
|
||||
if not defined HAS_SRC_CHANGE if not defined HAS_SCRIPT_CHANGE if defined HAS_DOC_CHANGE set "SUGGESTED_COMMIT=Update documentation for v%MOD_VERSION%"
|
||||
@@ -282,10 +292,8 @@ exit /b 0
|
||||
|
||||
:push_branch_with_retry
|
||||
set /a PUSH_ROUND=1
|
||||
|
||||
:push_round_start
|
||||
set /a PUSH_ATTEMPT=1
|
||||
|
||||
:push_attempt_start
|
||||
echo.
|
||||
echo [INFO] Push attempt !PUSH_ATTEMPT!/3 ^(round !PUSH_ROUND!^) ke origin/!CURRENT_BRANCH!...
|
||||
@@ -297,7 +305,7 @@ if !PUSH_ATTEMPT! LSS 3 (
|
||||
set /a PUSH_ATTEMPT+=1
|
||||
echo [INFO] Mencoba lagi dalam 2 detik...
|
||||
timeout /t 2 /nobreak >nul
|
||||
goto :push_attempt_start
|
||||
goto push_attempt_start
|
||||
)
|
||||
|
||||
echo.
|
||||
@@ -308,56 +316,32 @@ echo [INFO] Commit lokal tetap aman dan tidak perlu compile ulang.
|
||||
choice /C YN /N /M "Coba push 3x lagi? [Y/N]: "
|
||||
if errorlevel 2 exit /b 1
|
||||
set /a PUSH_ROUND+=1
|
||||
goto :push_round_start
|
||||
goto push_round_start
|
||||
|
||||
:skip_git
|
||||
echo.
|
||||
echo [INFO] Git commit/push dilewati.
|
||||
goto :success
|
||||
|
||||
:success
|
||||
echo.
|
||||
echo ============================================
|
||||
echo LesRaisinsArmor v%MOD_VERSION% selesai.
|
||||
echo ============================================
|
||||
echo.
|
||||
pause
|
||||
exit /b 0
|
||||
|
||||
:build_failed
|
||||
echo.
|
||||
echo ============================================
|
||||
echo BUILD FAILED
|
||||
echo ============================================
|
||||
echo.
|
||||
echo [ERROR] Build gagal.
|
||||
echo [INFO] Git Integration tidak dijalankan.
|
||||
echo.
|
||||
if "%BUILD_ONLY%"=="1" exit /b 1
|
||||
pause
|
||||
exit /b 1
|
||||
|
||||
:git_failed
|
||||
:git_fail_message
|
||||
echo.
|
||||
echo ============================================
|
||||
echo GIT FAILED
|
||||
echo ============================================
|
||||
echo.
|
||||
if "%GIT_ONLY%"=="1" (
|
||||
echo [INFO] Build tidak dijalankan; JAR v%MOD_VERSION% yang sudah ada tetap aman.
|
||||
) else (
|
||||
echo [INFO] Build LesRaisinsArmor tetap berhasil jika tahap build sebelumnya sukses.
|
||||
echo [INFO] Build tetap aman jika tahap build sebelumnya sukses.
|
||||
)
|
||||
echo [INFO] Commit lokal tetap tersimpan.
|
||||
echo [INFO] Jalankan compile.bat lagi; jika JAR versi sama terdeteksi, pilih G untuk Git-only.
|
||||
echo.
|
||||
pause
|
||||
exit /b 2
|
||||
exit /b 0
|
||||
|
||||
:failed
|
||||
:finish
|
||||
set "FINISH_CODE=%~1"
|
||||
echo.
|
||||
echo Proses gagal.
|
||||
echo ============================================
|
||||
if "%FINISH_CODE%"=="0" (
|
||||
echo LesRaisinsArmor v%MOD_VERSION% selesai.
|
||||
) else (
|
||||
echo LesRaisinsArmor v%MOD_VERSION% selesai dengan error %FINISH_CODE%.
|
||||
)
|
||||
echo ============================================
|
||||
echo.
|
||||
if "%BUILD_ONLY%"=="1" exit /b 1
|
||||
pause
|
||||
exit /b 1
|
||||
if "%BUILD_ONLY%"=="0" pause
|
||||
exit /b 0
|
||||
|
||||
Reference in New Issue
Block a user