Skip to content

Commit c234fca

Browse files
ci: Optimize packaging workflow with multi-OS support, JRE bundling, and start scripts (#241)
* Initial plan * Optimize packaging workflow with multi-OS support, JRE bundling, and start scripts - Add scripts/jre.sh, jre.ps1, jre_mac.sh for custom JRE creation via jlink (Java 17) - Add platform-specific start scripts (linux, mac, win) - Update package.yml with multi-OS matrix, Maven caching, version resolution, staging directory, JRE bundling, and per-platform artifact uploads Co-authored-by: unknowIfGuestInDream <57802425+unknowIfGuestInDream@users.noreply.github.com> * Fix spelling in Windows batch start scripts Co-authored-by: unknowIfGuestInDream <57802425+unknowIfGuestInDream@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: unknowIfGuestInDream <57802425+unknowIfGuestInDream@users.noreply.github.com>
1 parent 1d441dd commit c234fca

9 files changed

Lines changed: 249 additions & 16 deletions

File tree

.github/workflows/package.yml

Lines changed: 101 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,106 @@ permissions:
88

99
jobs:
1010
package:
11-
runs-on: ubuntu-latest
11+
name: Package on ${{ matrix.os }}
12+
strategy:
13+
matrix:
14+
os: [ ubuntu-latest, windows-latest, macos-latest ]
15+
runs-on: ${{ matrix.os }}
1216

1317
steps:
14-
- uses: actions/checkout@v6
15-
- name: Set up JDK 17
16-
uses: actions/setup-java@v5
17-
with:
18-
java-version: '17'
19-
distribution: 'temurin'
20-
cache: maven
21-
- name: Build with Maven
22-
run: mvn -B package --file pom.xml '-Dmaven.test.skip=true'
23-
- name: Upload artifact
24-
uses: actions/upload-artifact@v4
25-
with:
26-
name: genCode
27-
path: target/genCode.jar
28-
retention-days: 1
18+
- name: Checkout
19+
uses: actions/checkout@v6
20+
21+
- name: Setup JDK
22+
uses: actions/setup-java@v5
23+
with:
24+
distribution: temurin
25+
java-version: 17
26+
27+
- name: Cache Maven packages
28+
uses: actions/cache@v5
29+
with:
30+
path: ~/.m2/repository
31+
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
32+
restore-keys: |
33+
${{ runner.os }}-maven-
34+
35+
- name: Build with Maven
36+
shell: bash
37+
run: mvn -B clean package --no-transfer-progress -DskipTests
38+
39+
- name: Resolve version & stage files (Windows)
40+
if: runner.os == 'Windows'
41+
shell: pwsh
42+
run: |
43+
$versionOutput = & mvn -q -DforceStdout 'help:evaluate' -Dexpression='project.version' 2>$null
44+
$version = $versionOutput.Trim()
45+
if (-not $version) { throw 'Failed to extract version from Maven' }
46+
Add-Content -Path $env:GITHUB_ENV -Value "APP_VERSION=$version" -Encoding utf8
47+
48+
$stagingDir = 'staging'
49+
if (-not (Test-Path $stagingDir)) { New-Item -ItemType Directory -Path $stagingDir | Out-Null }
50+
51+
Copy-Item -Path 'target\genCode.jar' -Destination $stagingDir
52+
Copy-Item -Path 'README.md' -Destination $stagingDir
53+
Copy-Item -Path 'LICENSE' -Destination $stagingDir
54+
Copy-Item -Path 'scripts\win\*' -Destination $stagingDir -Recurse
55+
56+
- name: Download JRE (Windows)
57+
if: runner.os == 'Windows'
58+
shell: pwsh
59+
run: |
60+
Push-Location staging
61+
& ..\scripts\jre.ps1
62+
Pop-Location
63+
64+
- name: Resolve version & stage files (Linux)
65+
if: runner.os == 'Linux'
66+
shell: bash
67+
run: |
68+
version=$(mvn -q -DforceStdout 'help:evaluate' -Dexpression=project.version 2>/dev/null)
69+
version=$(echo "$version" | tr -d '\r')
70+
if [ -z "$version" ]; then echo "Failed to extract version from Maven" >&2; exit 1; fi
71+
echo "APP_VERSION=$version" >> $GITHUB_ENV
72+
73+
mkdir -p staging
74+
cp target/genCode.jar staging/
75+
cp README.md LICENSE staging/
76+
cp scripts/linux/* staging/
77+
78+
- name: Download JRE (Linux)
79+
if: runner.os == 'Linux'
80+
shell: bash
81+
run: |
82+
cd staging
83+
bash ../scripts/jre.sh
84+
cd ..
85+
86+
- name: Resolve version & stage files (macOS)
87+
if: runner.os == 'macOS'
88+
shell: bash
89+
run: |
90+
version=$(mvn -q -DforceStdout 'help:evaluate' -Dexpression=project.version 2>/dev/null)
91+
version=$(echo "$version" | tr -d '\r')
92+
if [ -z "$version" ]; then echo "Failed to extract version from Maven" >&2; exit 1; fi
93+
echo "APP_VERSION=$version" >> $GITHUB_ENV
94+
95+
mkdir -p staging
96+
cp target/genCode.jar staging/
97+
cp README.md LICENSE staging/
98+
cp scripts/mac/* staging/
99+
100+
- name: Download JRE (macOS)
101+
if: runner.os == 'macOS'
102+
shell: bash
103+
run: |
104+
cd staging
105+
bash ../scripts/jre_mac.sh
106+
cd ..
107+
108+
- name: Upload packaged artifact
109+
uses: actions/upload-artifact@v4
110+
with:
111+
name: genCode-${{ matrix.os }}
112+
path: staging/
113+
retention-days: 7

scripts/jre.ps1

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# see https://api.adoptium.net/q/swagger-ui/#/Binary/getBinaryByVersion
2+
$winApi = 'https://api.adoptium.net/v3/binary/version/jdk-17.0.14%2B7/windows/x64/jdk/hotspot/normal/eclipse?project=jdk'
3+
Invoke-WebRequest -Uri $winApi -OutFile 'jdk.zip'
4+
Expand-Archive -Path 'jdk.zip' -DestinationPath '.' -Force
5+
6+
# Create a custom minimal runtime using jlink instead of shipping the full JDK
7+
& '.\jdk-17.0.14+7\bin\jlink.exe' `
8+
--add-modules java.se,jdk.unsupported,jdk.zipfs,jdk.management,jdk.crypto.ec,jdk.localedata,jdk.charsets `
9+
--strip-debug --no-man-pages --no-header-files `
10+
--compress=2 `
11+
--output jre
12+
13+
if ($LASTEXITCODE -ne 0) {
14+
throw 'jlink failed to create custom runtime'
15+
}
16+
17+
Remove-Item -Path 'jdk-17.0.14+7' -Recurse -Force
18+
Remove-Item -Path 'jdk.zip' -Force

scripts/jre.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
# see https://api.adoptium.net/q/swagger-ui/#/Binary/getBinaryByVersion
4+
linuxApi='https://api.adoptium.net/v3/binary/version/jdk-17.0.14%2B7/linux/x64/jdk/hotspot/normal/eclipse?project=jdk'
5+
wget -c ${linuxApi} --no-check-certificate -O jdk.tar.gz
6+
tar -xzf jdk.tar.gz
7+
8+
# Create a custom minimal runtime using jlink instead of shipping the full JDK
9+
jdk-17.0.14+7/bin/jlink \
10+
--add-modules java.se,jdk.unsupported,jdk.zipfs,jdk.management,jdk.crypto.ec,jdk.localedata,jdk.charsets \
11+
--strip-debug --no-man-pages --no-header-files \
12+
--compress=2 \
13+
--output jre
14+
15+
if [ $? -ne 0 ]; then
16+
echo "jlink failed to create custom runtime" >&2
17+
exit 1
18+
fi
19+
20+
rm -rf jdk-17.0.14+7 jdk.tar.gz

scripts/jre_mac.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
# see https://api.adoptium.net/q/swagger-ui/#/Binary/getBinaryByVersion
4+
macApi='https://api.adoptium.net/v3/binary/version/jdk-17.0.14%2B7/mac/aarch64/jdk/hotspot/normal/eclipse?project=jdk'
5+
curl -L -o jdk.tar.gz "${macApi}"
6+
tar -xzf jdk.tar.gz
7+
8+
# Create a custom minimal runtime using jlink instead of shipping the full JDK
9+
jdk-17.0.14+7/Contents/Home/bin/jlink \
10+
--add-modules java.se,jdk.unsupported,jdk.zipfs,jdk.management,jdk.crypto.ec,jdk.localedata,jdk.charsets \
11+
--strip-debug --no-man-pages --no-header-files \
12+
--compress=2 \
13+
--output jre
14+
15+
if [ $? -ne 0 ]; then
16+
echo "jlink failed to create custom runtime" >&2
17+
exit 1
18+
fi
19+
20+
rm -rf jdk-17.0.14+7 jdk.tar.gz

scripts/linux/start.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
APP_NAME=genCode.jar
4+
5+
tpid=$(ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}')
6+
if [ ${tpid} ]; then
7+
echo 'Stop Process...'
8+
kill -2 $tpid
9+
fi
10+
11+
tpid=$(ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}')
12+
if [ ${tpid} ]; then
13+
echo 'Stop Process...'
14+
kill -2 $tpid
15+
else
16+
echo 'Stop Process Successfully!'
17+
echo 'start Process...'
18+
if [ -f "./jre/bin/java" ];then
19+
nohup jre/bin/java -jar $APP_NAME > nohup.out &
20+
else
21+
nohup java -jar $APP_NAME > nohup.out &
22+
fi
23+
fi

scripts/mac/start.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
APP_NAME=genCode.jar
4+
5+
tpid=$(ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}')
6+
if [ ${tpid} ]; then
7+
echo 'Stop Process...'
8+
kill -2 $tpid
9+
fi
10+
11+
tpid=$(ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}')
12+
if [ ${tpid} ]; then
13+
echo 'Stop Process...'
14+
kill -2 $tpid
15+
else
16+
echo 'Stop Process Successfully!'
17+
echo 'start Process...'
18+
if [ -f "./jre/bin/java" ];then
19+
nohup jre/bin/java -jar $APP_NAME > nohup.out &
20+
else
21+
nohup java -jar $APP_NAME > nohup.out &
22+
fi
23+
fi

scripts/win/console.bat

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@echo off
2+
set check_flag=true
3+
set java_path=.\jre\bin\java.exe
4+
if exist .\jre\bin\java.exe (
5+
%java_path% -version
6+
) else (
7+
if "true" == "%check_flag%" (
8+
java -version
9+
)
10+
if not %errorlevel% == 0 (
11+
echo Cannot run Java. Please check it.
12+
echo %errorlevel%
13+
pause
14+
goto END
15+
)
16+
set java_path=java
17+
)
18+
:START
19+
%java_path% -jar genCode.jar
20+
21+
:END

scripts/win/start.bat

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@echo off
2+
set check_flag=true
3+
set java_path=.\jre\bin\javaw.exe
4+
if exist .\jre\bin\javaw.exe (
5+
%java_path% -version
6+
) else (
7+
if "true" == "%check_flag%" (
8+
java -version
9+
)
10+
if not %errorlevel% == 0 (
11+
echo Cannot run Java. Please check it.
12+
echo %errorlevel%
13+
pause
14+
goto END
15+
)
16+
set java_path=javaw
17+
)
18+
:START
19+
cmd /c start /b %java_path% -jar genCode.jar
20+
21+
:END

scripts/win/start.vbs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Set shell = Wscript.createobject("wscript.shell")
2+
a = shell.run ("start.bat",0)

0 commit comments

Comments
 (0)