Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions .github/workflows/build-packages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: Build Native Packages

# ─── Triggers ──────────────────────────────────────────────────────────────
# • Automatic : every push of a version tag (e.g. v0.1.3)
# • Manual : "Run workflow" button in the Actions tab
on:
push:
tags:
- 'v*'
workflow_dispatch:

# Allow the release job to create/update GitHub Releases
permissions:
contents: write

# ─── Jobs ──────────────────────────────────────────────────────────────────
jobs:

# ══════════════════════════════════════════════════════════════════════════
# Build a native installer on each target OS
# ══════════════════════════════════════════════════════════════════════════
package:
name: Package – ${{ matrix.label }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false # let all three platforms build even if one fails
matrix:
include:
- os: ubuntu-latest
label: Linux (DEB)
- os: macos-latest
label: macOS (DMG)
- os: windows-latest
label: Windows (EXE)

steps:

# ── 1. Checkout with full history ────────────────────────────────────
# git-commit-id-maven-plugin needs the full git log to resolve
# ${git.commit.id.abbrev} used in the fat-JAR name.
- name: Checkout (full history)
uses: actions/checkout@v4
with:
fetch-depth: 0

# ── 2. JDK 24 (Azul Zulu) ────────────────────────────────────────────
- name: Set up JDK 24 (Zulu)
uses: actions/setup-java@v4
with:
java-version: '24'
distribution: 'zulu'
cache: maven # cache ~/.m2 between runs

# ── 3. Linux: ensure DEB packaging toolchain is present ──────────────
# jpackage --type deb requires fakeroot + dpkg (pre-installed on
# ubuntu-latest but explicit install guarantees availability).
- name: Install DEB packaging tools
if: runner.os == 'Linux'
run: sudo apt-get install -y fakeroot

# ── 4. Build fat JAR + native installer ──────────────────────────────
# The active OS profile (linux / mac / win) is detected automatically
# by Maven via <os><family> activation in pom.xml.
# --batch-mode suppresses interactive prompts and colorises output for CI.
- name: Build and package
run: mvn package -Ppackage --batch-mode

# ── 5. Upload installer as workflow artifact ──────────────────────────
# Artifact is available in the Actions run page for 90 days.
# The release job below will also attach it to the GitHub Release.
- name: Upload installer artifact
uses: actions/upload-artifact@v4
with:
name: installer-${{ runner.os }}
path: target/dist/
if-no-files-found: error

# ══════════════════════════════════════════════════════════════════════════
# Publish a GitHub Release with all three installers (tag pushes only)
# ══════════════════════════════════════════════════════════════════════════
release:
name: Publish GitHub Release
needs: package # wait for all three builds
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v') # skip on workflow_dispatch

steps:

# ── Download every installer artifact into dist/ ─────────────────────
- name: Download all installers
uses: actions/download-artifact@v4
with:
path: dist/
merge-multiple: true # flatten sub-dirs into dist/

# ── Create (or update) the GitHub Release ────────────────────────────
# Attach DEB + DMG + EXE to the release.
# Release notes are auto-generated from merged PRs / commits.
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
files: dist/**
generate_release_notes: true
77 changes: 77 additions & 0 deletions build
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,83 @@ WIN_INSTALL_EOF2
echo -e " ${GREEN}Windows installer created.${NC}"

elif [[ "$TARGET_OS" == "mac" ]]; then
if [[ "$TARGET_OS" == "$HOST_OS" ]] && command -v jpackage &>/dev/null; then
# ── Native macOS DMG via jpackage ─────────────────────────────────
echo "Creating macOS DMG with jpackage..."

# Input directory: main JAR + non-JavaFX libs only.
# JavaFX modules are bundled into the app image via --module-path / --add-modules.
local JPACKAGE_INPUT="${TARGET}/jpackage-input"
rm -rf "${JPACKAGE_INPUT}"
mkdir -p "${JPACKAGE_INPUT}"
cp "${BUILD}/${project_name}-${project_version}-${GIT_COMMIT_ID:0:12}.jar" "${JPACKAGE_INPUT}/"
if [[ -d "libs/common" ]] && ls libs/common/*.jar &>/dev/null 2>&1; then
cp libs/common/*.jar "${JPACKAGE_INPUT}/" 2>/dev/null || true
echo " Copied common libs into jpackage input."
fi

# Icon resolution: prefer .icns, convert from PNG with sips+iconutil if needed
local ICON_ICNS="${SRC}/main/resources/images/icons/marknote.icns"
local ICON_PNG="${SRC}/main/resources/images/icons/marknote-128.png"
local JPACKAGE_ICON_OPT=()
local ICON_TMPDIR=""
if [[ -f "${ICON_ICNS}" ]]; then
JPACKAGE_ICON_OPT=(--icon "${ICON_ICNS}")
elif [[ -f "${ICON_PNG}" ]] && command -v sips &>/dev/null && command -v iconutil &>/dev/null; then
echo " Converting PNG icon to .icns..."
ICON_TMPDIR=$(mktemp -d)
local ICONSET_DIR="${ICON_TMPDIR}/marknote.iconset"
mkdir -p "${ICONSET_DIR}"
for sz in 16 32 64 128 256 512; do
sips -z ${sz} ${sz} "${ICON_PNG}" --out "${ICONSET_DIR}/icon_${sz}x${sz}.png" 2>/dev/null || true
done
for sz in 16 32 128 256; do
local dbl=$(( sz * 2 ))
sips -z ${dbl} ${dbl} "${ICON_PNG}" --out "${ICONSET_DIR}/icon_${sz}x${sz}@2x.png" 2>/dev/null || true
done
local GENERATED_ICNS="${ICON_TMPDIR}/marknote.icns"
iconutil -c icns "${ICONSET_DIR}" -o "${GENERATED_ICNS}" 2>/dev/null || true
[[ -f "${GENERATED_ICNS}" ]] && JPACKAGE_ICON_OPT=(--icon "${GENERATED_ICNS}")
fi

mkdir -p "${TARGET}/dist"
jpackage \
--type dmg \
--name "${project_name}" \
--app-version "${project_version}" \
--vendor "${vendor_name}" \
--description "Markdown Note Editor" \
--input "${JPACKAGE_INPUT}" \
--main-jar "${project_name}-${project_version}-${GIT_COMMIT_ID:0:12}.jar" \
--main-class "${main_class}" \
--module-path "${TARGET}/jfx-libs" \
--add-modules "${JFX_MODULES}" \
--java-options "-Djava.net.preferIPv6Addresses=true" \
--dest "${TARGET}/dist" \
--mac-package-identifier "com.snapgames.marknote" \
--mac-package-name "${project_name}" \
"${JPACKAGE_ICON_OPT[@]}"

[[ -n "${ICON_TMPDIR}" ]] && rm -rf "${ICON_TMPDIR}"

local DMG_FILE
DMG_FILE=$(ls "${TARGET}/dist/${project_name}"*.dmg 2>/dev/null | head -1)
if [[ -f "${DMG_FILE}" ]]; then
echo -e "${GREEN}macOS DMG created: ${DMG_FILE}${NC}"
echo "Package size: $(du -sh "${DMG_FILE}" | cut -f1)"
else
echo -e "${YELLOW}Warning: DMG not found – check ${TARGET}/dist/${NC}"
ls -lh "${TARGET}/dist/" 2>/dev/null || true
fi
echo "done."
return 0
fi
# ── Fallback: .app bundle + install.sh ────────────────────────────────
if [[ "$HOST_OS" != "mac" ]]; then
echo -e " ${YELLOW}Cross-platform build: jpackage DMG requires a macOS host – falling back to .app bundle + install.sh.${NC}"
else
echo -e " ${YELLOW}jpackage not found in PATH – falling back to .app bundle + install.sh.${NC}"
fi
#----- macOS installer: create .app bundle in ~/Applications -----
cat > "${DIST_DIR}/install.sh" << 'MAC_INSTALL_EOF'
#!/bin/bash
Expand Down
Loading
Loading