Skip to content

Package macOS App

Package macOS App #5

Workflow file for this run

name: Package macOS App
on:
push:
paths:
- "Apps/*.json"
workflow_dispatch:
jobs:
package-app:
runs-on: macos-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
token: ${{ secrets.PAT }}
fetch-depth: 2 # To be able to get modified files
- name: Find JSON files needing packaging
id: files
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
# For manual triggers, check all JSON files
FILES=$(find Apps -type f -name "*.json" -exec sh -c '
if jq -e ".needsPackaging == true" "{}" > /dev/null; then
echo "{}"
fi
' \; | tr "\n" " ")
else
# For push events, check only modified files
FILES=$(git diff --name-only HEAD^ HEAD | grep '\.json$' || true)
fi
echo "files=$FILES" >> $GITHUB_OUTPUT
- name: Process JSON files
if: steps.files.outputs.files != ''
run: |
mkdir -p Apps/PKG
for file in ${{ steps.files.outputs.files }}; do
if jq -e '.needsPackaging == true' "$file"; then
echo "Processing $file"
APP_JSON=$(cat "$file")
VERSION=$(echo "$APP_JSON" | jq -r .version)
DOWNLOAD_URL=$(echo "$APP_JSON" | jq -r .url)
APP_NAME=$(echo "$APP_JSON" | jq -r .name)
BUNDLE_ID=$(echo "$APP_JSON" | jq -r .bundleId)
echo "Downloading app..."
curl -L -o app.zip "$DOWNLOAD_URL"
echo "Extracting app..."
# Create a clean directory for extraction
rm -rf temp_extract
mkdir temp_extract
cd temp_extract
# Extract the zip file
unzip -q ../app.zip
# Find the .app directory (ignoring __MACOSX)
APP_PATH=$(find . -name "*.app" -type d -not -path "*/__MACOSX/*" | head -n 1)
if [ -z "$APP_PATH" ]; then
echo "No .app directory found!"
exit 1
fi
echo "Found app at: $APP_PATH"
PKG_NAME="${APP_NAME}-${VERSION}.pkg"
echo "Creating package $PKG_NAME..."
pkgbuild --root "$APP_PATH" \
--identifier "$BUNDLE_ID" \
--install-location "/Applications" \
--version "$VERSION" \
"../Apps/PKG/$PKG_NAME"
# Go back to original directory
cd ..
echo "Updating JSON file..."
jq '.needsPackaging = false | .url = "https://raw.githubusercontent.com/'$GITHUB_REPOSITORY'/main/Apps/PKG/'$PKG_NAME'"' "$file" > tmp.json && mv tmp.json "$file"
# Clean up
rm -rf temp_extract app.zip
fi
done
- name: Commit and push changes
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add Apps/PKG/* Apps/*.json
git commit -m "Package apps from JSON files" || exit 0
git push