Skip to content

Commit

Permalink
feat: improve relevant scripts (#888)
Browse files Browse the repository at this point in the history
  • Loading branch information
qianmoQ authored Dec 9, 2024
2 parents 9d11c52 + 82299a9 commit cce6b86
Show file tree
Hide file tree
Showing 8 changed files with 298 additions and 8 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/bofore_checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:
runs-on: ubuntu-latest
needs:
- before_checker_loading
if: ${{ github.event_name == 'push' && contains(github.event.head_commit.modified, 'core/datacap-ui/') ||
github.event_name == 'pull_request' && contains(join(github.event.pull_request.changed_files.*.filename, ' '), 'core/datacap-ui/') }}
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -31,6 +33,8 @@ jobs:
runs-on: ubuntu-latest
needs:
- before_checker_ui
if: ${{ github.event_name == 'push' && contains(join(github.event.commits.*.modified, ' '), '.java') || contains(join(github.event.commits.*.modified, ' '), '.kt') ||
github.event_name == 'pull_request' && contains(join(github.event.pull_request.changed_files.*.filename, ' '), '.java') || contains(join(github.event.pull_request.changed_files.*.filename, ' '), '.kt') }}
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -46,6 +50,8 @@ jobs:
runs-on: ubuntu-latest
needs:
- before_checker_ui
if: ${{ github.event_name == 'push' && contains(join(github.event.commits.*.modified, ' '), '.java') || contains(join(github.event.commits.*.modified, ' '), '.kt') ||
github.event_name == 'pull_request' && contains(join(github.event.pull_request.changed_files.*.filename, ' '), '.java') || contains(join(github.event.pull_request.changed_files.*.filename, ' '), '.kt') }}
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -71,22 +77,18 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Maven Checker Style
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'

- name: Add hosts
run: |
echo "156.238.128.11 cdn.north.devlive.org" | sudo tee -a /etc/hosts
echo "156.238.128.17 cdn.north.devlive.org" | sudo tee -a /etc/hosts
echo "156.238.128.19 cdn.north.devlive.org" | sudo tee -a /etc/hosts
echo "156.238.128.23 cdn.north.devlive.org" | sudo tee -a /etc/hosts
- run: chmod 755 ./mvnw

- name: Debug Environment Variables
env:
QINIU_ACCESS: ${{ secrets.QINIU_ACCESS }}
Expand All @@ -96,7 +98,6 @@ jobs:
run: |
echo "QINIU_ENDPOINT is set: ${{ secrets.QINIU_ENDPOINT != '' }}"
echo "QINIU_ENDPOINT length: ${#QINIU_ENDPOINT}"
- name: Run Tests
if: ${{ env.QINIU_ENDPOINT != '' }}
env:
Expand All @@ -123,7 +124,6 @@ jobs:
-Dcos.access="$COS_ACCESS" -Dcos.secret="$COS_SECRET" -Dcos.bucket="$COS_BUCKET" -Dcos.endpoint="$COS_ENDPOINT" \
-Ds3.access="$S3_ACCESS" -Ds3.secret="$S3_SECRET" -Ds3.bucket="$S3_BUCKET" -Ds3.endpoint="$S3_ENDPOINT"
before_checker_package:
runs-on: ubuntu-latest
needs:
Expand All @@ -137,4 +137,4 @@ jobs:
java-version: '11'
distribution: 'temurin'
- run: chmod 755 ./mvnw
- run: ./mvnw -T 1C clean install package -Dspotbugs.skip -Dgpg.skip -Dcheckstyle.skip -DskipTests=true
- run: ./mvnw -T 1C clean install package -Dspotbugs.skip -Dgpg.skip -Dcheckstyle.skip -DskipTests=true
74 changes: 74 additions & 0 deletions configure/etc/bin/debug.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
@echo off
setlocal EnableDelayedExpansion

set "HOME=%CD%"
if not defined JAVA_HOME set "JAVA_HOME=C:\Program Files\Java\jdk"
set "APPLICATION_NAME=io.edurt.datacap.server.DataCap"
set "APPLICATION_PID="

call :check_java_version
call :job_before_echo_basic
call :job_runner_checker_server
call :job_runner_debug_server
exit /b

:check_java_version
for /f "tokens=3" %%i in ('"%JAVA_HOME%\bin\java" -version 2^>^&1 ^| findstr "version"') do (
set java_version=%%i
)
set java_version=!java_version:"=!
for /f "tokens=1 delims=." %%a in ("!java_version!") do set major_version=%%a
if not "!major_version!"=="1" if not "!major_version!"=="11" (
echo Error: Java version [ !java_version! ] is not supported. Please use Java 1.8 or 11.
exit /b 1
)
exit /b 0

:get_jvm_conf
for /f "tokens=* delims=" %%a in ('findstr /v "^#" "%HOME%\configure\jvm.conf"') do set "JVM_CONF=!JVM_CONF! %%a"
exit /b

:job_before_echo_basic
echo.
echo Job before echo basic
echo ============================================
echo Runtime home ^| %HOME%
echo Runtime java home ^| %JAVA_HOME%
echo Runtime application name ^| %APPLICATION_NAME%
echo ============================================
echo.
exit /b

:job_before_apply_server
for /f "tokens=2" %%a in ('wmic process where "commandline like '%%%APPLICATION_NAME%%%'" get processid /format:value') do (
set "APPLICATION_PID=%%a"
)
exit /b

:job_runner_checker_server
echo.
echo Job runner check server
echo ============================================
call :job_before_apply_server
echo Runtime process ^| %APPLICATION_PID%
if "%APPLICATION_PID%"=="" (
echo Server status ^| stopped
echo ============================================
echo.
) else (
echo Server status ^| running
echo ============================================
echo.
exit 1
)
exit /b

:job_runner_debug_server
echo.
echo Job runner server
echo ============================================
echo Server starting ^| %APPLICATION_NAME%
cd /d "%HOME%"
call :get_jvm_conf
"%JAVA_HOME%\bin\java" -cp "%HOME%\lib\*" %JVM_CONF% "%APPLICATION_NAME%" --spring.config.location="%HOME%\configure\"
exit /b
80 changes: 80 additions & 0 deletions configure/etc/bin/install-plugin.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
@echo off
setlocal EnableDelayedExpansion
set "HOME=%cd%"
set "VERSION=2024.4.0"
set "CDN_CENTER=https://repo1.maven.org/maven2/io/edurt/datacap"

:: 检查并创建临时目录
:: Check and create temporary directory
set "TEMP_DIR=%HOME%\temp"
if not exist "%TEMP_DIR%" mkdir "%TEMP_DIR%"
echo ========== Starting installation ==========
echo Version: %VERSION%
echo CDN Center: %CDN_CENTER%
if not exist "%HOME%\plugins" (
mkdir "%HOME%\plugins"
echo Created plugins directory
)

:: 使用更通用的下载方法
:: Use more universal download method
set "DOWNLOAD_COMMAND="
where powershell >nul 2>nul
if %errorlevel% equ 0 (
set "DOWNLOAD_COMMAND=powershell"
) else (
where curl >nul 2>nul
if %errorlevel% equ 0 (
set "DOWNLOAD_COMMAND=curl -L -o"
) else (
where wget >nul 2>nul
if %errorlevel% equ 0 (
set "DOWNLOAD_COMMAND=wget -O"
) else (
echo Error: Neither PowerShell, curl, nor wget found.
exit /b 1
)
)
)

:: 使用更通用的解压方法
:: Use more universal unzip method
set "UNZIP_COMMAND="
where tar >nul 2>nul
if %errorlevel% equ 0 (
set "UNZIP_COMMAND=tar -xzf"
) else (
where 7z >nul 2>nul
if %errorlevel% equ 0 (
set "UNZIP_COMMAND=7z x"
) else (
echo Error: Neither tar nor 7z found.
exit /b 1
)
)

for /f "usebackq tokens=*" %%A in (`type "%HOME%\configure\plugin.conf"`) do (
set "line=%%A"
if not "!line!"=="" if not "!line:~0,2!"=="--" (
set "DOWNLOAD_URL=%CDN_CENTER%/!line!/%VERSION%/!line!-%VERSION%-bin.tar.gz"
set "TEMP_FILE=%TEMP_DIR%\!line!-%VERSION%-bin.tar.gz"

echo Downloading: !line!
if "!DOWNLOAD_COMMAND!"=="powershell" (
powershell -NoProfile -ExecutionPolicy Bypass -Command "$ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest -Uri '!DOWNLOAD_URL!' -OutFile '!TEMP_FILE!'"
) else (
%DOWNLOAD_COMMAND% "!TEMP_FILE!" "!DOWNLOAD_URL!"
)
if !errorlevel! equ 0 (
echo Extracting: !line!
%UNZIP_COMMAND% "!TEMP_FILE!" -C "%HOME%\plugins"
del "!TEMP_FILE!"
)
)
)

:: 清理临时目录
:: Clean up temporary directory
rd /s /q "%TEMP_DIR%" 2>nul
echo ========== Installation complete ==========
endlocal
2 changes: 1 addition & 1 deletion configure/etc/bin/install-plugin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ process_section() {

if [ $IN_SECTION -eq 1 ] && [ ! -z "$line" ] && [[ ! "$line" =~ ^--.*$ ]]; then
COMPONENT_NAME="$line"
DOWNLOAD_URL="${CDN_CENTER}/${COMPONENT_NAME}/${VERSION}/${COMPONENT_NAME}-bin.tar.gz"
DOWNLOAD_URL="${CDN_CENTER}/${COMPONENT_NAME}/${VERSION}/${COMPONENT_NAME}-${VERSION}-bin.tar.gz"
echo "Installing from: $DOWNLOAD_URL"
install_package "$DOWNLOAD_URL" "${HOME}/plugins"
fi
Expand Down
5 changes: 5 additions & 0 deletions configure/etc/bin/restart.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@echo off
set "HOME=%CD%"

call "%HOME%\bin\shutdown.bat"
call "%HOME%\bin\startup.bat"
45 changes: 45 additions & 0 deletions configure/etc/bin/shutdown.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
@echo off
set "HOME=%CD%"
set "APPLICATION_NAME=io.edurt.datacap.server.DataCap"
set "APPLICATION_PID="

call :job_before_echo_basic
call :job_runner_stop_server
exit /b

:job_before_echo_basic
echo.
echo Job before echo basic
echo ============================================
echo Runtime home | %HOME%
echo Runtime application name | %APPLICATION_NAME%
echo ============================================
echo.
exit /b

:job_before_apply_server
for /f "tokens=1" %%a in ('tasklist /fi "imagename eq java.exe" /v ^| findstr /i "%APPLICATION_NAME%"') do (
set "APPLICATION_PID=%%a"
)
exit /b

:job_runner_stop_server
echo.
echo Job runner check server
echo ============================================
call :job_before_apply_server
echo Runtime process | %APPLICATION_PID%
if "%APPLICATION_PID%"=="" (
echo Server status | stopped
echo ============================================
echo.
exit 1
) else (
echo Server stopping | %APPLICATION_NAME%
taskkill /F /PID %APPLICATION_PID%
if exist "%HOME%\pid" rd /s /q "%HOME%\pid"
echo Server stopped successfully |
echo ============================================
echo.
)
exit /b
85 changes: 85 additions & 0 deletions configure/etc/bin/startup.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
@echo off
setlocal

set "HOME=%CD%"
if not defined JAVA_HOME set "JAVA_HOME=C:\Program Files\Java\jdk"
set "APPLICATION_NAME=io.edurt.datacap.server.DataCap"
set "APPLICATION_PID="

call :check_java_version
call :job_before_echo_basic
call :job_runner_checker_server
call :job_runner_start_server
exit /b

:check_java_version
for /f "tokens=3" %%i in ('"%JAVA_HOME%\bin\java" -version 2^>^&1 ^| findstr "version"') do (
set java_version=%%i
)
set java_version=%java_version:"=%
for /f "tokens=1 delims=." %%a in ("%java_version%") do set major_version=%%a
if not "%major_version%"=="1" if not "%major_version%"=="11" (
echo Error: Java version [ %java_version% ] is not supported. Please use Java 1.8 or 11.
exit /b 1
)
exit /b 0

:get_jvm_conf
set "JVM_CONF="
for /f "tokens=* delims=" %%a in ('findstr /v "^#" "%HOME%\configure\jvm.conf"') do set "JVM_CONF=%JVM_CONF% %%a"
exit /b

:job_before_echo_basic
echo.
echo Job before echo basic
echo ============================================
echo Runtime home | %HOME%
echo Runtime java home | %JAVA_HOME%
echo Runtime application name | %APPLICATION_NAME%
echo ============================================
echo.
exit /b

:job_before_apply_server
for /f "tokens=1" %%a in ('tasklist /fi "imagename eq java.exe" /v ^| findstr /i "%APPLICATION_NAME%"') do (
set "APPLICATION_PID=%%a"
)
exit /b

:job_runner_checker_server
echo.
echo Job runner check server
echo ============================================
call :job_before_apply_server
echo Runtime process | %APPLICATION_PID%
if "%APPLICATION_PID%"=="" (
echo Server status | stopped
echo ============================================
echo.
) else (
echo Server status | running
echo ============================================
echo.
exit 1
)
exit /b

:job_runner_start_server
echo.
echo Job runner server
echo ============================================
echo Server starting | %APPLICATION_NAME%
cd /d "%HOME%"
call :get_jvm_conf
start /B "" "%JAVA_HOME%\bin\javaw" -cp "%HOME%\lib\*" %JVM_CONF% "%APPLICATION_NAME%" --spring.config.location="%HOME%\configure\" > nul 2>&1
timeout /t 5 > nul
call :job_before_apply_server
if "%APPLICATION_PID%"=="" (
echo Server start failed |
) else (
echo %APPLICATION_PID% > pid
echo Server start successful |
)
echo ============================================
echo.
exit /b
1 change: 1 addition & 0 deletions configure/publish/publish-newVersion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ job_runner_apply() {

echo "Apply new version for plugin ..."
perl -pi -e 's/VERSION=.*/VERSION='"$VERSION"'/g' configure/etc/bin/install-plugin.sh
perl -pi -e 's/VERSION=.*/VERSION='"$VERSION"'/g' configure/etc/bin/install-plugin.bat

echo "Apply new version for metadata ..."
# Update version and URL in metadata.json using perl
Expand Down

0 comments on commit cce6b86

Please sign in to comment.