Skip to content

Commit 6d7a7ad

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 6d7a7ad

2 files changed

Lines changed: 118 additions & 52 deletions

File tree

.github/workflows/build-jcef.yml

Lines changed: 91 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,62 +2,48 @@ 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
2920
cmake -G "Ninja" -DPROJECT_ARCH=${{ matrix.platform }} -DCMAKE_BUILD_TYPE=Release ..
3021
ninja -j4
3122
mv native/Release linux_${{ matrix.platform }}
3223
strip linux_${{ matrix.platform }}/libcef.so
33-
tar -czf linux_${{ matrix.platform }}.tar.gz linux_${{ matrix.platform }}
24+
python3 ../.github/workflows/scripts/generate_hash.py linux_${{ matrix.platform }}
25+
mv linux_${{ matrix.platform }}/.hash ./
26+
tar -czf linux_${{ matrix.platform }}.tar.gz linux_${{ matrix.platform }} .hash
3427
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
28+
- uses: actions/upload-artifact@v4
29+
if: ${{ github.ref == 'refs/heads/main' }}
30+
with:
31+
name: 'linux_${{ matrix.platform }}'
32+
path: |
33+
jcef_build/linux_${{ matrix.platform }}.tar.gz
34+
jcef_build/linux_${{ matrix.platform }}.tar.gz.sha256
35+
if-no-files-found: error
36+
4137
java-cef-windows:
4238
runs-on: [windows-2022]
4339
strategy:
4440
matrix:
4541
platform: [amd64, arm64]
4642
steps:
47-
- name: Upload mask
48-
run: echo "::add-mask::${{ secrets.UPLOAD_URL }}"
4943
- uses: actions/checkout@v4
50-
- name: Setup JDK
51-
uses: actions/setup-java@v4
52-
with:
53-
java-version: '8'
54-
distribution: 'temurin'
5544
- 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"
45+
with:
46+
arch: ${{ matrix.platform == 'arm64' && 'amd64_arm64' || 'amd64' }}
6147
- name: Build
6248
run: |
6349
mkdir jcef_build && cd jcef_build
@@ -67,42 +53,95 @@ jobs:
6753
ren Release windows_${{ matrix.platform }}
6854
cd ..
6955
move native/windows_${{ matrix.platform }} windows_${{ matrix.platform }}
70-
tar -czf windows_${{ matrix.platform }}.tar.gz windows_${{ matrix.platform }}
56+
python3 ../.github/workflows/scripts/generate_hash.py windows_${{ matrix.platform }}
57+
mv windows_${{ matrix.platform }}/.hash ./
58+
tar -czf windows_${{ matrix.platform }}.tar.gz windows_${{ matrix.platform }} .hash
7159
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
60+
- uses: actions/upload-artifact@v4
61+
if: ${{ github.ref == 'refs/heads/main' }}
62+
with:
63+
name: 'windows_${{ matrix.platform }}'
64+
path: |
65+
jcef_build/windows_${{ matrix.platform }}.tar.gz
66+
jcef_build/windows_${{ matrix.platform }}.tar.gz.sha256
67+
if-no-files-found: error
68+
7869
java-cef-macos:
79-
runs-on: [macos-12]
70+
runs-on: [macos-13]
8071
strategy:
8172
matrix:
8273
platform: [amd64, arm64]
8374
steps:
84-
- name: Upload mask
85-
run: echo "::add-mask::${{ secrets.UPLOAD_URL }}"
8675
- uses: actions/checkout@v4
87-
- name: Setup JDK
88-
uses: actions/setup-java@v4
76+
- name: Set up Python 3.9
77+
uses: actions/setup-python@v4
8978
with:
90-
java-version: '8'
91-
distribution: 'temurin'
79+
python-version: '3.9'
9280
- run: |
9381
brew install ninja
9482
brew install coreutils
95-
brew install s3cmd
96-
sudo xcode-select --switch /Applications/Xcode_13.1.app
83+
sudo xcode-select -s /Applications/Xcode.app
9784
mkdir jcef_build && cd jcef_build
9885
cmake -G "Ninja" -DPROJECT_ARCH=${{ matrix.platform }} -DCMAKE_BUILD_TYPE=Release ..
9986
ninja -j4
10087
mv native/Release macos_${{ matrix.platform }}
101-
tar -czf macos_${{ matrix.platform }}.tar.gz macos_${{ matrix.platform }}
88+
python3 ../.github/workflows/scripts/generate_hash.py macos_${{ matrix.platform }}
89+
mv macos_${{ matrix.platform }}/.hash ./
90+
tar -czf macos_${{ matrix.platform }}.tar.gz macos_${{ matrix.platform }} .hash
10291
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
92+
- uses: actions/upload-artifact@v4
93+
if: ${{ github.ref == 'refs/heads/main' }}
94+
with:
95+
name: 'macos_${{ matrix.platform }}'
96+
path: |
97+
jcef_build/macos_${{ matrix.platform }}.tar.gz
98+
jcef_build/macos_${{ matrix.platform }}.tar.gz.sha256
99+
if-no-files-found: error
100+
check-secret:
101+
runs-on: ubuntu-24.04
102+
if: github.ref == 'refs/heads/main'
103+
steps:
104+
- name: Check secret
105+
env:
106+
API_TOKEN: ${{ secrets.API_TOKEN }}
107+
run: |
108+
if [ -z "$API_TOKEN" ]; then
109+
echo "API_TOKEN is not set. Upload will not proceed."
110+
exit 1
111+
fi
112+
echo "API_TOKEN is set. Upload can proceed."
113+
114+
upload-to-api:
115+
needs: [java-cef-linux, java-cef-windows, java-cef-macos, check-secret]
116+
runs-on: ubuntu-24.04
117+
if: github.ref == 'refs/heads/main'
118+
strategy:
119+
matrix:
120+
platform: [linux_amd64, linux_arm64, windows_amd64, windows_arm64, macos_amd64, macos_arm64]
121+
steps:
122+
- name: Download artifact
123+
uses: actions/download-artifact@v4
124+
with:
125+
name: ${{ matrix.platform }}
126+
- name: Upload to LiquidBounce API
127+
env:
128+
API_TOKEN: ${{ secrets.API_TOKEN }}
106129
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
130+
PLATFORM="${{ matrix.platform }}"
131+
132+
response=$(curl -w "\n%{http_code}" -X POST \
133+
-H "Authorization: Bearer $API_TOKEN" \
134+
-H "Content-Type: application/gzip" \
135+
--data-binary "@${PLATFORM}.tar.gz" \
136+
"http://nossl.api.liquidbounce.net/api/v3/resource/mcef-cef/${{ github.sha }}/${PLATFORM}")
137+
138+
status_code=$(echo "$response" | tail -n1)
139+
response_body=$(echo "$response" | sed '$d')
140+
141+
echo "Status code: $status_code"
142+
echo "Response body: $response_body"
143+
144+
if [ "$status_code" -lt 200 ] || [ "$status_code" -ge 300 ]; then
145+
echo "Upload failed with status code $status_code"
146+
exit 1
147+
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)