fix actions #3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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..." | |
unzip -q app.zip | |
PKG_NAME="${APP_NAME}-${VERSION}.pkg" | |
echo "Creating package $PKG_NAME..." | |
pkgbuild --root "*.app" \ | |
--identifier "$BUNDLE_ID" \ | |
--install-location "/Applications" \ | |
--version "$VERSION" \ | |
"Apps/PKG/$PKG_NAME" | |
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" | |
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 |