Skip to content

Build App Packages and Collect App Information #18

Build App Packages and Collect App Information

Build App Packages and Collect App Information #18

name: Build App Packages
on:
workflow_dispatch:
schedule:
- cron: "0 0 * * *" # Run daily at midnight
jobs:
build:
runs-on: macos-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.PAT }}
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.x"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install requests
- name: Make scrapers executable
run: chmod +x .github/scripts/scrapers/*.sh
- name: Collect app information
run: python .github/scripts/collect_app_info.py
- name: Find apps needing packaging
id: find-apps
run: |
echo "Finding apps that need special packaging..."
apps_to_build=()
for file in Apps/*.json; do
if [ -f "$file" ]; then
type=$(jq -r '.type // empty' "$file")
if [ "$type" = "app" ]; then
app_name=$(basename "$file" .json)
url=$(jq -r '.url' "$file")
apps_to_build+=("$app_name:$url")
fi
fi
done
echo "APPS_TO_BUILD=${apps_to_build[*]}" >> $GITHUB_ENV
echo "Found apps: ${apps_to_build[*]}"
- name: Create supported_apps.json
run: |
python - <<EOF
import json
import os
apps_folder = "Apps"
supported_apps = {}
for filename in os.listdir(apps_folder):
if filename.endswith(".json"):
app_name = os.path.splitext(filename)[0]
supported_apps[app_name] = f"https://raw.githubusercontent.com/ugurkocde/IntuneBrew/main/Apps/{filename}"
with open("supported_apps.json", "w") as f:
json.dump(supported_apps, f, indent=4)
print("Created supported_apps.json")
EOF
- name: Commit and push changes
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add Apps/*.json supported_apps.json README.md
git commit -m "Update app information and supported apps list" || exit 0
git push https://${{ secrets.PAT }}@github.com/${{ github.repository }}.git
- name: Process apps
if: env.APPS_TO_BUILD != ''
env:
AZURE_STORAGE_CONNECTION_STRING: ${{ secrets.AZURE_STORAGE_CONNECTION_STRING }}
run: |
WORKSPACE_DIR=$(pwd)
for app_info in $APPS_TO_BUILD; do
IFS=':' read -r app_name url <<< "$app_info"
echo "Processing $app_name..."
# Get version from JSON file
version=$(jq -r '.version' "$WORKSPACE_DIR/Apps/${app_name}.json")
echo "Version: $version"
# Check if this is an app that needs packaging
is_app_type=$(jq -r '.type == "app"' "$WORKSPACE_DIR/Apps/${app_name}.json")
if [ "$is_app_type" != "true" ]; then
echo "Skipping URL update for $app_name as it's not of type 'app'"
continue
fi
# Check if package already exists in Azure
if az storage blob exists --container-name pkg --name "${app_name}_${version}.pkg" --query "exists" --output tsv | grep -q "true"; then
echo "Package ${app_name}_${version}.pkg already exists in Azure storage. Skipping..."
# Update the JSON file with Azure URL even if we skip building
azure_url="https://intunebrewpkg.blob.core.windows.net/pkg/${app_name}_${version}.pkg"
jq --arg url "$azure_url" '.url = $url' "$WORKSPACE_DIR/Apps/${app_name}.json" > temp.json && mv temp.json "$WORKSPACE_DIR/Apps/${app_name}.json"
continue
fi
# Download app
echo "Downloading $app_name..."
curl -L -o ~/Desktop/${app_name}.zip "$url"
# Unzip app
echo "Unzipping $app_name..."
cd ~/Desktop
# Extract while excluding __MACOSX directory
unzip -q -d "${app_name}_extracted" ${app_name}.zip
# Find .app file, excluding __MACOSX directory
app_file=$(find "${app_name}_extracted" -type d -name "*.app" ! -path "*/__MACOSX/*" -print -quit)
if [ -z "$app_file" ]; then
echo "No .app file found for $app_name"
cd "$WORKSPACE_DIR"
rm -rf "${app_name}_extracted" ${app_name}.zip
continue
fi
# Build PKG with version in filename
echo "Building PKG for $app_name version $version..."
pkgbuild --install-location /Applications --component "$app_file" "${app_name}_${version}.pkg"
# Upload to Azure with version in filename
echo "Uploading $app_name version $version to Azure Blob Storage..."
az storage blob upload \
--container-name pkg \
--file "${app_name}_${version}.pkg" \
--name "${app_name}_${version}.pkg" \
--overwrite true
# Update the JSON file with Azure URL after successful upload
azure_url="https://intunebrewpkg.blob.core.windows.net/pkg/${app_name}_${version}.pkg"
jq --arg url "$azure_url" '.url = $url' "$WORKSPACE_DIR/Apps/${app_name}.json" > temp.json && mv temp.json "$WORKSPACE_DIR/Apps/${app_name}.json"
# Cleanup
rm -f ${app_name}.zip ${app_name}_${version}.pkg
rm -rf "${app_name}_extracted"
# Return to workspace directory
cd "$WORKSPACE_DIR"
echo "Completed processing $app_name version $version"
done