-
-
Notifications
You must be signed in to change notification settings - Fork 0
61 lines (51 loc) · 1.41 KB
/
build.yml
File metadata and controls
61 lines (51 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
---
name: Build
on:
push:
pull_request:
branches: [main]
workflow_dispatch:
workflow_call:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Set up JDK
uses: actions/setup-java@v5
with:
java-version: "21"
distribution: "temurin"
architecture: x64
- name: Detect Main Class
id: detect-main
run: |
MAIN_FILE=$(grep -rl "public class Main" src | head -n1)
if [ -z "$MAIN_FILE" ]; then
echo "[ERROR]: Main.java not found"
exit 1
fi
PKG=$(grep "package " "$MAIN_FILE" | awk '{print $2}' | tr -d ';')
if [ -n "$PKG" ]; then
MAIN_CLASS="$PKG.Main"
else
MAIN_CLASS="Main"
fi
echo "MAIN_CLASS=$MAIN_CLASS" >> $GITHUB_ENV
- name: Build JAR
run: |
javac -d bin -cp "lib/*" $(find src -name "*.java");
jar --create --file dist/app.jar --main-class="${MAIN_CLASS}" -C bin/ .
- name: Upload JAR
uses: actions/upload-artifact@v4
with:
name: app-jar-${{ github.sha }}
path: dist/app.jar
retention-days: 7
if-no-files-found: error