Skip to content

Commit 6edf91c

Browse files
committed
Added both-arch macOS builds to Github CI.
1 parent 7860329 commit 6edf91c

File tree

5 files changed

+292
-47
lines changed

5 files changed

+292
-47
lines changed

.github/workflows/gradle.yml

Lines changed: 162 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,56 +3,51 @@ name: Java CI
33
on: [push]
44

55
jobs:
6-
build:
6+
prepare:
7+
runs-on: ubuntu-latest
8+
outputs:
9+
DIFF_COMMITS: ${{ steps.prepare_ch.outputs.DIFF_COMMITS }}
10+
11+
steps:
12+
- name: Clone
13+
uses: actions/checkout@v1
714

8-
runs-on: windows-latest
15+
- name: Prepare commits diff content
16+
id: prepare_ch
17+
run: |
18+
cur_branch="${{ github.ref_name }}"
19+
git checkout $cur_branch
20+
git remote add upstream https://github.com/chatty/chatty
21+
git fetch --all
22+
git branch $cur_branch --set-upstream-to upstream/master
23+
status_output=$(git rev-list --count upstream/master..origin/${cur_branch})
24+
echo "DIFF_COMMITS=$status_output" >> $GITHUB_OUTPUT
925
26+
build:
27+
needs: prepare
28+
runs-on: windows-latest
1029
defaults:
1130
run:
1231
shell: cmd
32+
33+
outputs:
34+
new_tag_text: ${{ steps.set_version.outputs.NEW_TAG_TEXT }}
1335

1436
steps:
15-
- name: Clone.
37+
- name: Clone
1638
uses: actions/checkout@v1
1739

1840
- uses: actions/setup-java@main
19-
name: Install Java 17.
41+
name: Install Java 17
2042
with:
2143
distribution: 'adopt'
2244
java-version: '17'
23-
- name: Set up version of Chatty.
24-
run: |
25-
git checkout master
26-
git remote add upstream https://github.com/chatty/chatty
27-
git fetch --all
28-
git branch master --set-upstream-to upstream/master
29-
git status
30-
git status > ch.txt
31-
python version.py
32-
- name: Latest chatty tag.
33-
shell: bash
34-
run: |
35-
curl \
36-
-H "Accept: application/vnd.github.v3+json" \
37-
https://api.github.com/repos/chatty/chatty/releases > latest_chatty.json
38-
- name: Parse JSON.
39-
shell: python
45+
46+
- name: Run version.py
4047
run: |
41-
import json
42-
import os
43-
def writeEnv(key, value):
44-
open(os.environ['GITHUB_ENV'], "a").write(key + '=' + value + '\n');
45-
with open('latest_chatty.json') as json_data:
46-
data = json.load(json_data)[0];
47-
tag_name = str(data['tag_name']);
48-
writeEnv('CHATTY_TAG', tag_name);
49-
tag_text = tag_name.replace('-b', ' Beta ').replace('v', '');
50-
writeEnv('CHATTY_TAG_TEXT', tag_text);
51-
print(tag_name);
52-
print(tag_text);
53-
with open('final_version.txt') as ver_data:
54-
writeEnv('NEW_TAG_TEXT', str(ver_data.read()));
55-
- name: Build with Gradle.
48+
python version.py "${{ needs.prepare.outputs.DIFF_COMMITS }}"
49+
50+
- name: Build with Gradle
5651
run: |
5752
gradlew build ^
5853
&& gradlew release ^
@@ -61,13 +56,139 @@ jobs:
6156
-PjpackagePath="%java_home%\bin\jpackage.exe" ^
6257
-PinnosetupPath="%programfiles(x86)%\Inno Setup 6\ISCC.exe" ^
6358
-PmtPath="%programfiles(x86)%\Windows Kits\10\bin\10.0.22000.0\x64\mt.exe"
64-
- name: Draft release.
59+
60+
- name: Upload Windows Artifacts
61+
uses: actions/upload-artifact@v4.6.2
62+
with:
63+
name: windows-artifacts
64+
path: build/releases/*
65+
66+
- name: Get new tag text
67+
id: set_version
68+
run: |
69+
set /p new_tag_text=<final_version.txt
70+
echo "NEW_TAG_TEXT=%new_tag_text%" >> $GITHUB_OUTPUT
71+
72+
build_mac_arm:
73+
needs: prepare
74+
runs-on: macos-latest
75+
defaults:
76+
run:
77+
shell: bash
78+
79+
steps:
80+
- name: Clone
81+
uses: actions/checkout@v1
82+
83+
- name: Set up JDK (ARM64)
84+
uses: actions/setup-java@v3
85+
with:
86+
distribution: 'temurin'
87+
java-version: '17'
88+
architecture: arm64
89+
90+
- name: Run version.py
91+
run: |
92+
python version.py "${{ needs.prepare.outputs.DIFF_COMMITS }}"
93+
94+
- name: Build with Gradle (ARM64)
95+
run: |
96+
./gradlew build && \
97+
./gradlew release && \
98+
./gradlew releaseMacDmgArm -PjpackagePath=`which jpackage`
99+
100+
- name: Upload Mac ARM Artifacts
101+
uses: actions/upload-artifact@v4.6.2
102+
with:
103+
name: mac-arm-artifacts
104+
path: build/jpackage-mac/*
105+
106+
build_mac_intel:
107+
needs: prepare
108+
runs-on: macos-latest
109+
defaults:
110+
run:
111+
shell: bash
112+
113+
steps:
114+
- name: Clone
115+
uses: actions/checkout@v1
116+
117+
- name: Set up JDK (x64)
118+
uses: actions/setup-java@v3
119+
with:
120+
distribution: 'temurin'
121+
java-version: '17'
122+
architecture: x64
123+
124+
- name: Run version.py
125+
run: |
126+
python version.py "${{ needs.prepare.outputs.DIFF_COMMITS }}"
127+
128+
- name: Build with Gradle (x64)
129+
run: |
130+
./gradlew build && \
131+
./gradlew release && \
132+
./gradlew releaseMacDmgIntel -PjpackagePath=`which jpackage`
133+
134+
- name: Upload Mac Intel Artifacts
135+
uses: actions/upload-artifact@v4.6.2
136+
with:
137+
name: mac-intel-artifacts
138+
path: build/jpackage-mac/*
139+
140+
create_release:
141+
needs: [build, build_mac_arm, build_mac_intel]
142+
runs-on: ubuntu-latest
143+
144+
steps:
145+
- name: Download Windows Artifacts
146+
uses: actions/download-artifact@v4.3.0
147+
with:
148+
name: windows-artifacts
149+
path: artifacts/windows
150+
151+
- name: Download Mac ARM Artifacts
152+
uses: actions/download-artifact@v4.3.0
153+
with:
154+
name: mac-arm-artifacts
155+
path: artifacts/mac-arm
156+
157+
- name: Download Mac Intel Artifacts
158+
uses: actions/download-artifact@v4.3.0
159+
with:
160+
name: mac-intel-artifacts
161+
path: artifacts/mac-intel
162+
163+
- name: Fetch latest Chatty tag
164+
id: fetch_tag
165+
run: |
166+
curl \
167+
-H "Accept: application/vnd.github.v3+json" \
168+
https://api.github.com/repos/chatty/chatty/releases > latest_chatty.json
169+
tag_name=$(jq -r '.[0].tag_name' latest_chatty.json)
170+
tag_text=$(echo $tag_name | sed 's/-b/ Beta /' | sed 's/v//')
171+
echo "CHATTY_TAG=$tag_name" >> $GITHUB_ENV
172+
echo "CHATTY_TAG_TEXT=$tag_text" >> $GITHUB_ENV
173+
174+
# Create release body content
175+
release_body="
176+
- Updated version to official [$tag_text](https://github.com/chatty/chatty/releases/tag/$tag_name)."
177+
echo "$release_body" > release_body.md
178+
echo "RELEASE_BODY<<EOF" >> $GITHUB_ENV
179+
echo "$release_body" >> $GITHUB_ENV
180+
echo "EOF" >> $GITHUB_ENV
181+
182+
- name: Create Release
65183
uses: softprops/action-gh-release@v0.1.15
66184
with:
67185
draft: true
68-
files: build/releases/*
69-
tag_name: v${{ env.NEW_TAG_TEXT }}
70-
name: "Chatty Fork ${{ env.NEW_TAG_TEXT }}"
71-
body: "- Updated version to official [${{ env.CHATTY_TAG_TEXT }}](https://github.com/chatty/chatty/releases/tag/${{ env.CHATTY_TAG }})."
186+
files: |
187+
artifacts/windows/*
188+
artifacts/mac-arm/*
189+
artifacts/mac-intel/*
190+
tag_name: v${{ needs.build.outputs.new_tag_text }}
191+
name: "Chatty Fork ${{ needs.build.outputs.new_tag_text }}"
192+
body: ${{ env.RELEASE_BODY }}
72193
env:
73194
GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }}

assets-bundle/Chatty.icns

348 KB
Binary file not shown.

build.gradle

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,124 @@ task releaseWinSetups(group: 'build') {
315315
dependsOn releaseWindows, innosetup, innosetupStandalone, build
316316
}
317317

318+
//--------
319+
// macOS
320+
//--------
321+
322+
def macBundleTarget = new File(buildDir, 'jpackage-mac')
323+
324+
def prepareMacVersionAndInput(macBundleTarget) {
325+
delete macBundleTarget
326+
copy {
327+
from tasks.shadowJar.archivePath
328+
into new File(macBundleTarget, 'input')
329+
}
330+
331+
def rawVersion = project.version.replaceAll(/[^0-9.]/, '')
332+
def versionWithoutLeadingZero = rawVersion.startsWith('0.') ? rawVersion.substring(2) : rawVersion
333+
334+
return versionWithoutLeadingZero
335+
}
336+
337+
def buildMacJpackageCommand(arch, macVersion, macBundleTarget, bundleType = 'app-image') {
338+
def jpackageExec = project.hasProperty('jpackagePath') ? jpackagePath : 'jpackage'
339+
def archName = arch == 'arm64' ? 'arm64' : 'x64'
340+
def identifierSuffix = arch == 'arm64' ? 'arm64' : 'x64'
341+
342+
def command = [jpackageExec,
343+
'--type', bundleType,
344+
'--name', "Chatty-${archName}",
345+
'--input', new File(macBundleTarget, 'input'),
346+
'--main-jar', 'Chatty.jar',
347+
'--main-class', 'chatty.Chatty',
348+
'--dest', macBundleTarget,
349+
'--description', "Chatty - Twitch Chat Client (${arch == 'arm64' ? 'ARM64' : 'Intel'})",
350+
'--java-options', '-Xmx600M',
351+
'--icon', 'assets-bundle/Chatty.icns',
352+
'--app-version', macVersion,
353+
'--vendor', 'Chatty',
354+
'--mac-package-identifier', "chatty.client.${identifierSuffix}"]
355+
356+
if (bundleType == 'dmg') {
357+
command << '--mac-package-name' << "Chatty-${archName}"
358+
}
359+
360+
return command
361+
}
362+
363+
task jpackageMacArm(type: Exec, group: 'build') {
364+
dependsOn shadowJar
365+
366+
doFirst {
367+
def macVersion = prepareMacVersionAndInput(macBundleTarget)
368+
commandLine buildMacJpackageCommand('arm64', macVersion, macBundleTarget, 'app-image')
369+
}
370+
}
371+
372+
task jpackageMacIntel(type: Exec, group: 'build') {
373+
dependsOn shadowJar
374+
375+
doFirst {
376+
def macVersion = prepareMacVersionAndInput(macBundleTarget)
377+
commandLine buildMacJpackageCommand('x64', macVersion, macBundleTarget, 'app-image')
378+
}
379+
}
380+
381+
task dmgMacArm(type: Exec, group: 'build') {
382+
dependsOn shadowJar
383+
384+
doFirst {
385+
def macVersion = prepareMacVersionAndInput(macBundleTarget)
386+
commandLine buildMacJpackageCommand('arm64', macVersion, macBundleTarget, 'dmg')
387+
}
388+
}
389+
390+
task dmgMacIntel(type: Exec, group: 'build') {
391+
dependsOn shadowJar
392+
393+
doFirst {
394+
def macVersion = prepareMacVersionAndInput(macBundleTarget)
395+
commandLine buildMacJpackageCommand('x64', macVersion, macBundleTarget, 'dmg')
396+
}
397+
}
398+
399+
// Задачи для упаковки app-image в zip (локальные тесты)
400+
task packageAppArm(type: Zip) {
401+
dependsOn jpackageMacArm
402+
from("${macBundleTarget}/Chatty-arm64.app")
403+
archiveFileName = "Chatty_${version}_mac_arm64.app.zip"
404+
destinationDirectory = releasesDir
405+
}
406+
407+
task packageAppIntel(type: Zip) {
408+
dependsOn jpackageMacIntel
409+
from("${macBundleTarget}/Chatty-x64.app")
410+
archiveFileName = "Chatty_${version}_mac_x64.app.zip"
411+
destinationDirectory = releasesDir
412+
}
413+
414+
task releaseMacDmgArm(type: Copy) {
415+
dependsOn dmgMacArm
416+
from("${macBundleTarget}") {
417+
include "Chatty-arm64-${version}.dmg"
418+
rename "Chatty-arm64-${version}.dmg", "Chatty_${version}_mac_arm64.dmg"
419+
}
420+
into releasesDir
421+
}
422+
423+
task releaseMacDmgIntel(type: Copy) {
424+
dependsOn dmgMacIntel
425+
from("${macBundleTarget}") {
426+
include "Chatty-x64-${version}.dmg"
427+
rename "Chatty-x64-${version}.dmg", "Chatty_${version}_mac_x64.dmg"
428+
}
429+
into releasesDir
430+
}
431+
432+
task releaseMacSetups(group: 'build') {
433+
dependsOn packageAppArm, packageAppIntel, releaseMacDmgArm, releaseMacDmgIntel
434+
}
435+
318436
//---------
319437
// Checksum
320438
//---------
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

version.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import re
2+
import sys
23

3-
file = open('ch.txt','r');
4-
str = file.readlines()[1];
5-
sub = str[45:48];
6-
print(sub);
4+
# Check if at least one argument is provided
5+
if len(sys.argv) > 1:
6+
first_argument = sys.argv[1]
7+
print(f"First argument: {first_argument}")
8+
else:
9+
print("No arguments provided.")
710

811
partVersion = '0.28.0';
9-
finalVersion = f"{partVersion}.{sub}";
12+
finalVersion = f"{partVersion}.{first_argument}";
1013

1114
path = "src/chatty/Chatty.java";
1215
chatty = open(path, 'r');
@@ -27,3 +30,6 @@
2730
chatty.close();
2831

2932
open('final_version.txt', 'w').write(finalVersion);
33+
34+
#alias b='./gradlew build && ./gradlew packageAppArm'
35+
#alias o='open ./build/jpackage-mac/Chatty-arm64.app'

0 commit comments

Comments
 (0)