Skip to content

Commit 100ccad

Browse files
committed
refactor: building
We use our own file server for our CCBlueX/mcef fork. The script generates binaries for every platform and includes hashes with the ZIP which will be uploaded to our LiquidBounce API.
1 parent a7b6934 commit 100ccad

2 files changed

Lines changed: 131 additions & 55 deletions

File tree

.github/workflows/build-jcef.yml

Lines changed: 104 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,107 +2,156 @@ name: Build java-cef
22

33
on:
44
push:
5-
branches:
6-
- master
75
workflow_dispatch:
86

97
jobs:
108
java-cef-linux:
11-
runs-on: [ubuntu-20.04]
9+
runs-on: [ubuntu-24.04]
1210
strategy:
1311
matrix:
1412
platform: [amd64, arm64]
1513
steps:
16-
- name: Upload mask
17-
run: echo "::add-mask::${{ secrets.UPLOAD_URL }}"
1814
- uses: actions/checkout@v4
19-
- name: Setup JDK
20-
uses: actions/setup-java@v4
21-
with:
22-
java-version: '8'
23-
distribution: 'temurin'
2415
- name: Install deps and build
2516
run: |
2617
sudo apt update
27-
sudo apt install build-essential g++ cmake ninja-build python3 libgtk2.0-dev s3cmd -y
18+
sudo apt install build-essential g++ cmake ninja-build openjdk-17-jdk python3 libgtk2.0-dev -y
2819
mkdir jcef_build && cd jcef_build
29-
cmake -G "Ninja" -DPROJECT_ARCH=${{ matrix.platform }} -DCMAKE_BUILD_TYPE=Release ..
20+
if [ "${{ matrix.platform }}" = "amd64" ]; then
21+
cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Release ..
22+
else
23+
cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Release -DCMAKE_SYSTEM_PROCESSOR=aarch64 ..
24+
fi
3025
ninja -j4
3126
mv native/Release linux_${{ matrix.platform }}
3227
strip linux_${{ matrix.platform }}/libcef.so
33-
tar -czf linux_${{ matrix.platform }}.tar.gz linux_${{ matrix.platform }}
28+
python3 ../.github/workflows/scripts/generate_hash.py linux_${{ matrix.platform }}
29+
mv linux_${{ matrix.platform }}/.hash ./
30+
tar -czf linux_${{ matrix.platform }}.tar.gz linux_${{ matrix.platform }} .hash
3431
sha256sum linux_${{ matrix.platform }}.tar.gz > linux_${{ matrix.platform }}.tar.gz.sha256
35-
- name: Copy s3cfg
36-
run: echo "${{ secrets.S3_CFG }}" > ~/.s3cfg
37-
- name: Upload java-cef build
38-
run: |
39-
s3cmd put -P /home/runner/work/java-cef/java-cef/jcef_build/linux_${{ matrix.platform }}.tar.gz s3://mcef-us-1/java-cef-builds/${{ github.sha }}/linux_${{ matrix.platform }}.tar.gz
40-
s3cmd put -P /home/runner/work/java-cef/java-cef/jcef_build/linux_${{ matrix.platform }}.tar.gz.sha256 s3://mcef-us-1/java-cef-builds/${{ github.sha }}/linux_${{ matrix.platform }}.tar.gz.sha256
32+
- uses: actions/upload-artifact@v4
33+
if: ${{ github.ref == 'refs/heads/main' }}
34+
with:
35+
name: 'linux_${{ matrix.platform }}'
36+
path: |
37+
jcef_build/linux_${{ matrix.platform }}.tar.gz
38+
jcef_build/linux_${{ matrix.platform }}.tar.gz.sha256
39+
if-no-files-found: error
40+
4141
java-cef-windows:
4242
runs-on: [windows-2022]
4343
strategy:
4444
matrix:
4545
platform: [amd64, arm64]
4646
steps:
47-
- name: Upload mask
48-
run: echo "::add-mask::${{ secrets.UPLOAD_URL }}"
4947
- uses: actions/checkout@v4
50-
- name: Setup JDK
51-
uses: actions/setup-java@v4
52-
with:
53-
java-version: '8'
54-
distribution: 'temurin'
5548
- uses: ilammy/msvc-dev-cmd@v1
56-
- name: Install s3cmd
57-
run: |
58-
pip install python-dateutil
59-
Invoke-WebRequest -Uri "https://github.com/s3tools/s3cmd/archive/master.zip" -OutFile "D:\s3cmd.zip"
60-
Expand-Archive -Path "D:\s3cmd.zip" -DestinationPath "D:\s3cmd"
6149
- name: Build
6250
run: |
6351
mkdir jcef_build && cd jcef_build
64-
cmake -G "Ninja" -DPROJECT_ARCH=${{ matrix.platform }} -DCMAKE_BUILD_TYPE=Release ..
52+
if ("${{ matrix.platform }}" -eq "amd64") {
53+
cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Release ..
54+
} else {
55+
cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Release -A ARM64 ..
56+
}
6557
ninja -j4
6658
cd native
6759
ren Release windows_${{ matrix.platform }}
6860
cd ..
6961
move native/windows_${{ matrix.platform }} windows_${{ matrix.platform }}
70-
tar -czf windows_${{ matrix.platform }}.tar.gz windows_${{ matrix.platform }}
62+
python3 ../.github/workflows/scripts/generate_hash.py windows_${{ matrix.platform }}
63+
mv windows_${{ matrix.platform }}/.hash ./
64+
tar -czf windows_${{ matrix.platform }}.tar.gz windows_${{ matrix.platform }} .hash
7165
Get-FileHash -Algorithm SHA256 -Path "windows_${{ matrix.platform }}.tar.gz" | Out-File "windows_${{ matrix.platform }}.tar.gz.sha256"
72-
- name: Copy s3cfg
73-
run: echo "${{ secrets.S3_CFG }}" > "$HOME\AppData\Roaming\s3cmd.ini"
74-
- name: Upload java-cef build
75-
run: |
76-
python D:\s3cmd\s3cmd-master\s3cmd put -P D:\a\java-cef\java-cef\jcef_build\windows_${{ matrix.platform }}.tar.gz s3://mcef-us-1/java-cef-builds/${{ github.sha }}/windows_${{ matrix.platform }}.tar.gz
77-
python D:\s3cmd\s3cmd-master\s3cmd put -P D:\a\java-cef\java-cef\jcef_build\windows_${{ matrix.platform }}.tar.gz.sha256 s3://mcef-us-1/java-cef-builds/${{ github.sha }}/windows_${{ matrix.platform }}.tar.gz.sha256
66+
- uses: actions/upload-artifact@v4
67+
if: ${{ github.ref == 'refs/heads/main' }}
68+
with:
69+
name: 'windows_${{ matrix.platform }}'
70+
path: |
71+
jcef_build/windows_${{ matrix.platform }}.tar.gz
72+
jcef_build/windows_${{ matrix.platform }}.tar.gz.sha256
73+
if-no-files-found: error
74+
7875
java-cef-macos:
79-
runs-on: [macos-12]
76+
runs-on: [macos-13]
8077
strategy:
8178
matrix:
8279
platform: [amd64, arm64]
8380
steps:
84-
- name: Upload mask
85-
run: echo "::add-mask::${{ secrets.UPLOAD_URL }}"
8681
- uses: actions/checkout@v4
87-
- name: Setup JDK
88-
uses: actions/setup-java@v4
82+
- name: Set up Python 3.9
83+
uses: actions/setup-python@v4
8984
with:
90-
java-version: '8'
91-
distribution: 'temurin'
85+
python-version: '3.9'
9286
- run: |
9387
brew install ninja
9488
brew install coreutils
95-
brew install s3cmd
96-
sudo xcode-select --switch /Applications/Xcode_13.1.app
89+
sudo xcode-select -s /Applications/Xcode.app
9790
mkdir jcef_build && cd jcef_build
98-
cmake -G "Ninja" -DPROJECT_ARCH=${{ matrix.platform }} -DCMAKE_BUILD_TYPE=Release ..
91+
if [ "${{ matrix.platform }}" = "amd64" ]; then
92+
cmake -G "Ninja" -DPROJECT_ARCH=x86_64 -DCMAKE_BUILD_TYPE=Release ..
93+
else
94+
cmake -G "Ninja" -DPROJECT_ARCH=arm64 -DCMAKE_BUILD_TYPE=Release ..
95+
fi
9996
ninja -j4
10097
mv native/Release macos_${{ matrix.platform }}
101-
tar -czf macos_${{ matrix.platform }}.tar.gz macos_${{ matrix.platform }}
98+
python3 ../.github/workflows/scripts/generate_hash.py macos_${{ matrix.platform }}
99+
mv macos_${{ matrix.platform }}/.hash ./
100+
tar -czf macos_${{ matrix.platform }}.tar.gz macos_${{ matrix.platform }} .hash
102101
sha256sum macos_${{ matrix.platform }}.tar.gz > macos_${{ matrix.platform }}.tar.gz.sha256
103-
- name: Copy s3cfg
104-
run: echo "${{ secrets.S3_CFG }}" > ~/.s3cfg
105-
- name: Upload java-cef build
102+
- uses: actions/upload-artifact@v4
103+
if: ${{ github.ref == 'refs/heads/main' }}
104+
with:
105+
name: 'macos_${{ matrix.platform }}'
106+
path: |
107+
jcef_build/macos_${{ matrix.platform }}.tar.gz
108+
jcef_build/macos_${{ matrix.platform }}.tar.gz.sha256
109+
if-no-files-found: error
110+
check-secret:
111+
runs-on: ubuntu-24.04
112+
if: github.ref == 'refs/heads/main'
113+
steps:
114+
- name: Check secret
115+
env:
116+
API_TOKEN: ${{ secrets.API_TOKEN }}
117+
run: |
118+
if [ -z "$API_TOKEN" ]; then
119+
echo "API_TOKEN is not set. Upload will not proceed."
120+
exit 1
121+
fi
122+
echo "API_TOKEN is set. Upload can proceed."
123+
124+
upload-to-api:
125+
needs: [java-cef-linux, java-cef-windows, java-cef-macos, check-secret]
126+
runs-on: ubuntu-24.04
127+
if: github.ref == 'refs/heads/main'
128+
strategy:
129+
matrix:
130+
platform: [linux_amd64, linux_arm64, windows_amd64, windows_arm64, macos_amd64, macos_arm64]
131+
steps:
132+
- name: Download artifact
133+
uses: actions/download-artifact@v4
134+
with:
135+
name: ${{ matrix.platform }}
136+
- name: Upload to LiquidBounce API
137+
env:
138+
API_TOKEN: ${{ secrets.API_TOKEN }}
106139
run: |
107-
s3cmd put -P /Users/runner/work/java-cef/java-cef/jcef_build/macos_${{ matrix.platform }}.tar.gz s3://mcef-us-1/java-cef-builds/${{ github.sha }}/macos_${{ matrix.platform }}.tar.gz
108-
s3cmd put -P /Users/runner/work/java-cef/java-cef/jcef_build/macos_${{ matrix.platform }}.tar.gz.sha256 s3://mcef-us-1/java-cef-builds/${{ github.sha }}/macos_${{ matrix.platform }}.tar.gz.sha256
140+
PLATFORM="${{ matrix.platform }}"
141+
142+
response=$(curl -w "\n%{http_code}" -X POST \
143+
-H "Authorization: Bearer $API_TOKEN" \
144+
-H "Content-Type: application/gzip" \
145+
--data-binary "@${PLATFORM}.tar.gz" \
146+
"http://nossl.api.liquidbounce.net/api/v3/resource/mcef-cef/${{ github.sha }}/${PLATFORM}")
147+
148+
status_code=$(echo "$response" | tail -n1)
149+
response_body=$(echo "$response" | sed '$d')
150+
151+
echo "Status code: $status_code"
152+
echo "Response body: $response_body"
153+
154+
if [ "$status_code" -lt 200 ] || [ "$status_code" -ge 300 ]; then
155+
echo "Upload failed with status code $status_code"
156+
exit 1
157+
fi
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from pathlib import Path
2+
import json
3+
import hashlib
4+
5+
def calculate_hash(filepath):
6+
sha256_hash = hashlib.sha256()
7+
with filepath.open('rb') as f:
8+
for byte_block in iter(lambda: f.read(4096), b""):
9+
sha256_hash.update(byte_block)
10+
return sha256_hash.hexdigest()
11+
12+
def generate_hash_file(directory):
13+
directory = Path(directory)
14+
hashes = {}
15+
16+
for filepath in directory.rglob('*'):
17+
if not filepath.is_file() or filepath.name == '.hash':
18+
continue
19+
relpath = (directory / filepath.relative_to(directory)).as_posix()
20+
hashes[relpath] = calculate_hash(filepath)
21+
22+
with (directory / '.hash').open('w') as f:
23+
json.dump(hashes, f, indent=2, sort_keys=True)
24+
25+
if __name__ == '__main__':
26+
import sys
27+
generate_hash_file(sys.argv[1])

0 commit comments

Comments
 (0)