diff --git a/.github/workflows/Release.yml b/.github/workflows/Release.yml index 9c3590c..465466b 100644 --- a/.github/workflows/Release.yml +++ b/.github/workflows/Release.yml @@ -8,95 +8,41 @@ permissions: packages: write jobs: - macutil_build: - runs-on: ubuntu-latest + macos-app: + uses: ./.github/workflows/macos-app.yml + publish: + needs: macos-app + runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 - - name: Setup .NET - uses: actions/setup-dotnet@v4 - with: - dotnet-version: '9.0.x' - - - name: Cache .NET packages - uses: actions/cache@v4 - with: - path: ~/.nuget/packages - key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} - restore-keys: ${{ runner.os }}-nuget- - - - name: Restore dependencies - run: dotnet restore MacUtilGUI/MacUtilGUI.fsproj - - - name: Build and publish macOS x64 + - name: Read version + id: version run: | - dotnet publish MacUtilGUI/MacUtilGUI.fsproj \ - --configuration Release \ - --runtime osx-x64 \ - --self-contained true \ - --output ./build/osx-x64 \ - /p:PublishSingleFile=true \ - /p:IncludeNativeLibrariesForSelfExtract=true + set -euo pipefail + bash scripts/check-version.sh + version=$(sed -n 's/.*\([^<]*\)<\/CFBundleVersion>.*/\1/p' MacUtilGUI/MacUtilGUI.fsproj | head -n 1) + echo "version=$version" >> "$GITHUB_OUTPUT" - - name: Build and publish macOS ARM64 - run: | - dotnet publish MacUtilGUI/MacUtilGUI.fsproj \ - --configuration Release \ - --runtime osx-arm64 \ - --self-contained true \ - --output ./build/osx-arm64 \ - /p:PublishSingleFile=true \ - /p:IncludeNativeLibrariesForSelfExtract=true - - - name: Rename binaries - run: | - mv ./build/osx-x64/MacUtilGUI ./build/osx-x64/macutil-macos-x64 - mv ./build/osx-arm64/MacUtilGUI ./build/osx-arm64/macutil-macos-arm64 - - - name: Extract Version - id: extract_version - run: | - # Fetch all tags - git fetch --tags - - # Get the latest tag, default to 0.0.0 if no tags exist - latest_tag=$(git tag --sort=-version:refname | head -n1) - if [ -z "$latest_tag" ]; then - latest_tag="0.0.0" - fi - - # Parse the latest tag (assuming format X.Y.Z) - IFS='.' read -ra VERSION_PARTS <<< "$latest_tag" - major=${VERSION_PARTS[0]:-0} - minor=${VERSION_PARTS[1]:-0} - patch=${VERSION_PARTS[2]:-0} - - # Increment minor version by 0.1 (increment minor, reset patch to 0) - new_minor=$((minor + 1)) - version="${major}.${new_minor}.0" - - echo "Previous version: $latest_tag" - echo "New version: $version" - echo "version=$version" >> $GITHUB_ENV - shell: bash + - name: Download macOS artifacts + uses: actions/download-artifact@v4 + with: + path: ./artifacts + pattern: MacUtil-* + merge-multiple: true - - name: Create and Upload Release - id: create_release + - name: Create release uses: softprops/action-gh-release@v2 with: - tag_name: ${{ env.version }} - name: Pre-Release ${{ env.version }} - body: | - ![GitHub Downloads (specific asset, specific tag)](https://img.shields.io/github/downloads/ChrisTitusTech/macutil/${{ env.version }}/macutil-macos-x64) - ![GitHub Downloads (specific asset, specific tag)](https://img.shields.io/github/downloads/ChrisTitusTech/macutil/${{ env.version }}/macutil-macos-arm64) - - append_body: true + tag_name: ${{ steps.version.outputs.version }} + name: Pre-Release ${{ steps.version.outputs.version }} generate_release_notes: true + fail_on_unmatched_files: true files: | - ./build/osx-x64/macutil-macos-x64 - ./build/osx-arm64/macutil-macos-arm64 + ./artifacts/MacUtil-Universal.zip + ./artifacts/MacUtil-macos-x64.zip + ./artifacts/MacUtil-macos-arm64.zip prerelease: true env: - version: ${{ env.version }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/macos-app.yml b/.github/workflows/macos-app.yml new file mode 100644 index 0000000..8f29319 --- /dev/null +++ b/.github/workflows/macos-app.yml @@ -0,0 +1,200 @@ +name: macOS App + +on: + workflow_call: + workflow_dispatch: + push: + branches: ["main"] + paths: + - "MacUtilGUI/**" + - "config/**" + - "scripts/check-version.sh" + - ".github/workflows/macos-app.yml" + - ".github/workflows/Release.yml" + pull_request: + branches: ["main"] + paths: + - "MacUtilGUI/**" + - "config/**" + - "scripts/check-version.sh" + - ".github/workflows/macos-app.yml" + - ".github/workflows/Release.yml" + +permissions: + contents: read + +jobs: + macos-13: + name: macos-13 + runs-on: macos-13 + timeout-minutes: 30 + steps: + - uses: actions/checkout@v5 + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: "9.0.x" + + - name: Cache .NET packages + uses: actions/cache@v4 + with: + path: ~/.nuget/packages + key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} + restore-keys: ${{ runner.os }}-nuget- + + - name: Check version lock + run: bash scripts/check-version.sh + + - name: Publish osx-x64 + run: | + set -euo pipefail + dotnet publish MacUtilGUI/MacUtilGUI.fsproj \ + --configuration Release \ + --runtime osx-x64 \ + --self-contained true \ + --output ./build/osx-x64 \ + /p:PublishSingleFile=true \ + /p:IncludeNativeLibrariesForSelfExtract=true + file ./build/osx-x64/MacUtilGUI + lipo -info ./build/osx-x64/MacUtilGUI + + - name: Smoke osx-x64 + run: | + set -euo pipefail + chmod +x ./build/osx-x64/MacUtilGUI + ./build/osx-x64/MacUtilGUI > /tmp/macutil-smoke.log 2>&1 & + pid=$! + sleep 8 + if ! kill -0 "$pid" 2>/dev/null; then + echo "smoke failed: osx-x64 process died before 8s" >&2 + cat /tmp/macutil-smoke.log >&2 || true + exit 1 + fi + kill "$pid" 2>/dev/null || true + wait "$pid" 2>/dev/null || true + echo "smoke ok: osx-x64 pid $pid stayed up 8s" + + - name: Package Intel app + run: | + set -euo pipefail + bundle="./dist/MacUtil-Intel.app" + mkdir -p "$bundle/Contents/MacOS" "$bundle/Contents/Resources" + rsync -a ./build/osx-x64/ "$bundle/Contents/MacOS/" + chmod +x "$bundle/Contents/MacOS/MacUtilGUI" + cp MacUtilGUI/Info.plist "$bundle/Contents/Info.plist" + cp MacUtilGUI/MacUtilGUI.icns "$bundle/Contents/Resources/" + ditto -c -k --keepParent "$bundle" ./dist/MacUtil-macos-x64.zip + + - name: Upload osx-x64 binary + uses: actions/upload-artifact@v4 + with: + name: osx-x64 + path: ./build/osx-x64/MacUtilGUI + if-no-files-found: error + + - name: Upload Intel app + uses: actions/upload-artifact@v4 + with: + name: MacUtil-macos-x64 + path: ./dist/MacUtil-macos-x64.zip + if-no-files-found: error + + macos-14: + name: macos-14 + runs-on: macos-14 + timeout-minutes: 30 + needs: macos-13 + steps: + - uses: actions/checkout@v5 + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: "9.0.x" + + - name: Cache .NET packages + uses: actions/cache@v4 + with: + path: ~/.nuget/packages + key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} + restore-keys: ${{ runner.os }}-nuget- + + - name: Check version lock + run: bash scripts/check-version.sh + + - name: Publish osx-arm64 + run: | + set -euo pipefail + dotnet publish MacUtilGUI/MacUtilGUI.fsproj \ + --configuration Release \ + --runtime osx-arm64 \ + --self-contained true \ + --output ./build/osx-arm64 \ + /p:PublishSingleFile=true \ + /p:IncludeNativeLibrariesForSelfExtract=true + file ./build/osx-arm64/MacUtilGUI + lipo -info ./build/osx-arm64/MacUtilGUI + + - name: Download osx-x64 binary + uses: actions/download-artifact@v4 + with: + name: osx-x64 + path: ./build/osx-x64 + + - name: Smoke osx-arm64 + run: | + set -euo pipefail + chmod +x ./build/osx-arm64/MacUtilGUI + ./build/osx-arm64/MacUtilGUI > /tmp/macutil-smoke.log 2>&1 & + pid=$! + sleep 8 + if ! kill -0 "$pid" 2>/dev/null; then + echo "smoke failed: osx-arm64 process died before 8s" >&2 + cat /tmp/macutil-smoke.log >&2 || true + exit 1 + fi + kill "$pid" 2>/dev/null || true + wait "$pid" 2>/dev/null || true + echo "smoke ok: osx-arm64 pid $pid stayed up 8s" + + - name: Lipo universal app + run: | + set -euo pipefail + chmod +x ./build/osx-x64/MacUtilGUI ./build/osx-arm64/MacUtilGUI + bundle="./dist/MacUtil-Universal.app" + mkdir -p "$bundle/Contents/MacOS" "$bundle/Contents/Resources" + rsync -a --exclude="MacUtilGUI" ./build/osx-arm64/ "$bundle/Contents/MacOS/" + lipo -create \ + ./build/osx-x64/MacUtilGUI \ + ./build/osx-arm64/MacUtilGUI \ + -output "$bundle/Contents/MacOS/MacUtilGUI" + chmod +x "$bundle/Contents/MacOS/MacUtilGUI" + cp MacUtilGUI/Info.plist "$bundle/Contents/Info.plist" + cp MacUtilGUI/MacUtilGUI.icns "$bundle/Contents/Resources/" + file "$bundle/Contents/MacOS/MacUtilGUI" + lipo -info "$bundle/Contents/MacOS/MacUtilGUI" + lipo -info "$bundle/Contents/MacOS/MacUtilGUI" | grep x86_64 + lipo -info "$bundle/Contents/MacOS/MacUtilGUI" | grep arm64 + arm_bundle="./dist/MacUtil-AppleSilicon.app" + mkdir -p "$arm_bundle/Contents/MacOS" "$arm_bundle/Contents/Resources" + rsync -a ./build/osx-arm64/ "$arm_bundle/Contents/MacOS/" + chmod +x "$arm_bundle/Contents/MacOS/MacUtilGUI" + cp MacUtilGUI/Info.plist "$arm_bundle/Contents/Info.plist" + cp MacUtilGUI/MacUtilGUI.icns "$arm_bundle/Contents/Resources/" + ditto -c -k --keepParent "$bundle" ./dist/MacUtil-Universal.zip + ditto -c -k --keepParent "$arm_bundle" ./dist/MacUtil-macos-arm64.zip + + - name: Upload Apple Silicon app + uses: actions/upload-artifact@v4 + with: + name: MacUtil-macos-arm64 + path: ./dist/MacUtil-macos-arm64.zip + if-no-files-found: error + + - name: Upload universal app + uses: actions/upload-artifact@v4 + with: + name: MacUtil-Universal + path: ./dist/MacUtil-Universal.zip + if-no-files-found: error diff --git a/MacUtilGUI/build_universal.sh b/MacUtilGUI/build_universal.sh old mode 100755 new mode 100644 index 861d9b7..d4888d1 --- a/MacUtilGUI/build_universal.sh +++ b/MacUtilGUI/build_universal.sh @@ -10,14 +10,13 @@ echo APP_NAME="MacUtilGUI" BUNDLE_NAME="MacUtil" BUNDLE_IDENTIFIER="com.macutil.gui" -VERSION="0.2.0" +VERSION="0.2.1" COPYRIGHT="Copyright © 2025 CT Tech Group LLC. All rights reserved." # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' BLUE='\033[0;34m' -YELLOW='\033[1;33m' NC='\033[0m' # No Color print_status() { @@ -45,16 +44,14 @@ dotnet restore > /dev/null # Build for Intel x64 print_status "Building Intel x64 binary..." -dotnet publish -c Release -r osx-x64 -p:UseAppHost=true --self-contained true -o ./bin/Release/net9.0/publish/osx-x64/ > /dev/null 2>&1 -if [ $? -ne 0 ]; then +if ! dotnet publish -c Release -r osx-x64 -p:UseAppHost=true --self-contained true -o ./bin/Release/net9.0/publish/osx-x64/ > /dev/null 2>&1; then print_error "Intel x64 build failed" exit 1 fi # Build for Apple Silicon ARM64 print_status "Building Apple Silicon ARM64 binary..." -dotnet publish -c Release -r osx-arm64 -p:UseAppHost=true --self-contained true -o ./bin/Release/net9.0/publish/osx-arm64/ > /dev/null 2>&1 -if [ $? -ne 0 ]; then +if ! dotnet publish -c Release -r osx-arm64 -p:UseAppHost=true --self-contained true -o ./bin/Release/net9.0/publish/osx-arm64/ > /dev/null 2>&1; then print_error "Apple Silicon ARM64 build failed" exit 1 fi @@ -67,12 +64,10 @@ mkdir -p "$universal_app/Contents/Resources" # Create universal binary using lipo print_status "Merging binaries with lipo..." -lipo -create \ +if ! lipo -create \ "./bin/Release/net9.0/publish/osx-x64/$APP_NAME" \ "./bin/Release/net9.0/publish/osx-arm64/$APP_NAME" \ - -output "$universal_app/Contents/MacOS/$APP_NAME" 2>/dev/null - -if [ $? -ne 0 ]; then + -output "$universal_app/Contents/MacOS/$APP_NAME" 2>/dev/null; then print_error "Failed to create universal binary with lipo" exit 1 fi diff --git a/_typos.toml b/_typos.toml new file mode 100644 index 0000000..7afa793 --- /dev/null +++ b/_typos.toml @@ -0,0 +1,2 @@ +[default.extend-identifiers] +typ = "typ" diff --git a/scripts/check-version.sh b/scripts/check-version.sh new file mode 100644 index 0000000..93d0f6d --- /dev/null +++ b/scripts/check-version.sh @@ -0,0 +1,70 @@ +#!/usr/bin/env bash +set -euo pipefail + +root="$(cd "$(dirname "$0")/.." && pwd)" +fsproj="$root/MacUtilGUI/MacUtilGUI.fsproj" +plist="$root/MacUtilGUI/Info.plist" +build_script="$root/MacUtilGUI/build_universal.sh" +deploy_script="$root/MacUtilGUI/deploy_macos.sh" + +fsproj_prop() { + local key="$1" + sed -n "s/.*<${key}>\\([^<]*\\)<\\/${key}>.*/\\1/p" "$fsproj" | head -n 1 +} + +plist_string() { + local key="$1" + awk -v k="$key" ' + index($0, "" k "") { want = 1; next } + want && // { + sub(/.*/, "") + sub(/<\/string>.*/, "") + print + exit + } + ' "$plist" +} + +script_version() { + local file="$1" + sed -n 's/^VERSION="\([^"]*\)".*/\1/p' "$file" | head -n 1 +} + +names=() +values=() + +add() { + local name="$1" + local value="$2" + if [ -z "$value" ]; then + echo "missing version: $name" >&2 + exit 1 + fi + names+=("$name") + values+=("$value") +} + +add "MacUtilGUI.fsproj CFBundleVersion" "$(fsproj_prop CFBundleVersion)" +add "MacUtilGUI.fsproj CFBundleShortVersionString" "$(fsproj_prop CFBundleShortVersionString)" +add "MacUtilGUI/Info.plist CFBundleVersion" "$(plist_string CFBundleVersion)" +add "MacUtilGUI/Info.plist CFBundleShortVersionString" "$(plist_string CFBundleShortVersionString)" +add "MacUtilGUI/build_universal.sh VERSION" "$(script_version "$build_script")" +add "MacUtilGUI/deploy_macos.sh VERSION" "$(script_version "$deploy_script")" + +expected="${values[0]}" +drift=0 +i=0 +while [ "$i" -lt "${#names[@]}" ]; do + printf '%s=%s\n' "${names[$i]}" "${values[$i]}" + if [ "${values[$i]}" != "$expected" ]; then + drift=1 + fi + i=$((i + 1)) +done + +if [ "$drift" -ne 0 ]; then + echo "version drift: expected $expected from ${names[0]}" >&2 + exit 1 +fi + +echo "version $expected"