Files
macos-iso-builder/.github/workflows/build-recovery.yml
T

203 lines
8.3 KiB
YAML

name: 01. Build Recovery ISO image
on:
workflow_dispatch:
inputs:
macos_version:
description: 'Select a macOS version to build'
required: true
type: choice
options:
- ''
- 'Tahoe'
- 'Sequoia'
- 'Sonoma'
- 'Ventura'
- 'Monterey'
- 'Big Sur'
- 'Catalina'
- 'Mojave'
- 'High Sierra'
release_tag:
description: 'Optional: tag the build (e.g., v10.15) to upload it to Releases for long-term storage'
required: false
type: string
jobs:
build-recovery-iso:
if: ${{ inputs.macos_version != '' }}
runs-on: macos-latest
permissions:
contents: write # needed to create releases
timeout-minutes: 15
steps:
- name: Preflight
run: |
# Third time's the charm
if [ "$GITHUB_RUN_ATTEMPT" -ge 3 ] || [ "$GITHUB_RUN_NUMBER" -ge 3 ]; then
exit 0
fi
FOUND=false
PAGE=1
while [ $PAGE -le 50 ]; do
DATA=$(curl -s \
-H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/LongQT-sea/macos-iso-builder/stargazers?per_page=100&page=${PAGE}")
echo "$DATA" | grep -qi "\"login\".*\"$GITHUB_ACTOR\"" && FOUND=true && break
[ "$(echo "$DATA" | grep -c '"login"')" -lt 100 ] && break
PAGE=$((PAGE + 1))
done
if [ "$FOUND" = "false" ]; then
echo "Looks like you forgot to read the first step in the README ? :thinking:" >> $GITHUB_STEP_SUMMARY
echo "Star [the repo](https://github.com/LongQT-sea/macos-iso-builder) or keep re-running — you'll get through eventually. :wink:" >> $GITHUB_STEP_SUMMARY
echo "Head over to https://github.com/LongQT-sea/macos-iso-builder to drop a star. :star:" >> $GITHUB_STEP_SUMMARY
echo "<br>![star](https://raw.githubusercontent.com/LongQT-sea/macos-iso-builder/main/.github/star.jpg)" >> $GITHUB_STEP_SUMMARY
exit 1
fi
- name: Checkout repository
uses: actions/checkout@v6
- name: System Information
run: |
echo "Runner OS: $(sw_vers -productName) $(sw_vers -productVersion)"
echo "Architecture: $(uname -m)"
echo ""
df -h $(mktemp)
echo ""
echo "RAM: $(top -l 1 | grep PhysMem)"
echo ""
echo "CPU: $(sysctl -n machdep.cpu.brand_string)"
echo ""
echo "Python version: $(python3 --version)"
- name: Download macrecovery.py
run: |
echo "Downloading macrecovery.py from acidanthera/OpenCorePkg..."
curl --retry 3 --max-time 10 --connect-timeout 3 -OL "https://raw.githubusercontent.com/acidanthera/OpenCorePkg/master/Utilities/macrecovery/macrecovery.py"
- name: Get version info
id: version_info
run: |
case "${{ github.event.inputs.macos_version }}" in
"High Sierra") KEY="high_sierra1" ;;
"Mojave") KEY="mojave" ;;
"Catalina") KEY="catalina1" ;;
"Big Sur") KEY="big_sur" ;;
"Monterey") KEY="monterey" ;;
"Ventura") KEY="ventura" ;;
"Sonoma") KEY="sonoma" ;;
"Sequoia") KEY="sequoia" ;;
"Tahoe") KEY="tahoe" ;;
esac
case $KEY in
high_sierra1) INFO="Mac-7BA5B2D9E42DDD94:00000000000J80300:High_Sierra:" ;;
mojave) INFO="Mac-7BA5B2DFE22DDD8C:00000000000KXPG00:Mojave:" ;;
catalina1) INFO="Mac-CFF7D910A743CAAF:00000000000PHCD00:Catalina:" ;;
big_sur) INFO="Mac-2BD1B31983FE1663:00000000000000000:Big_Sur:" ;;
monterey) INFO="Mac-E43C1C25D4880AD6:00000000000000000:Monterey:" ;;
ventura) INFO="Mac-B4831CEBD52A0C4C:00000000000000000:Ventura:" ;;
sonoma) INFO="Mac-827FAC58A8FDFA22:00000000000000000:Sonoma:" ;;
sequoia) INFO="Mac-7BA5B2D9E42DDD94:00000000000000000:Sequoia:" ;;
tahoe) INFO="Mac-CFF7D910A743CAAF:00000000000000000:Tahoe:latest" ;;
esac
IFS=':' read -r BOARD_ID MODEL VERSION_NAME OS_FLAG <<< "$INFO"
echo "board_id=$BOARD_ID" >> $GITHUB_OUTPUT
echo "model=$MODEL" >> $GITHUB_OUTPUT
echo "version_name=$VERSION_NAME" >> $GITHUB_OUTPUT
echo "os_flag=$OS_FLAG" >> $GITHUB_OUTPUT
- name: Download macOS Recovery
id: download_recovery_image
run: |
echo "Downloading macOS ${{ steps.version_info.outputs.version_name }} recovery..."
if [ -n "${{ steps.version_info.outputs.os_flag }}" ]; then
script -q /dev/null python3 macrecovery.py -b "${{ steps.version_info.outputs.board_id }}" -m "${{ steps.version_info.outputs.model }}" -os "${{ steps.version_info.outputs.os_flag }}" download
else
script -q /dev/null python3 macrecovery.py -b "${{ steps.version_info.outputs.board_id }}" -m "${{ steps.version_info.outputs.model }}" download
fi
- name: Create Recovery ISO
id: create_iso
run: |
VERSION_NAME="${{ steps.version_info.outputs.version_name }}"
ISO_FILE="macOS_${VERSION_NAME}_Recovery.iso"
RECOVERY_PATH="com.apple.recovery.boot/BaseSystem.dmg"
sudo hdiutil makehybrid -hfs -udf -default-volume-name "${VERSION_NAME}_Recovery" -o "$ISO_FILE" "$RECOVERY_PATH"
if [ -f "$ISO_FILE" ]; then
ISO_SIZE=$(du -h "$ISO_FILE" | cut -f1)
echo "ISO created successfully!"
echo "ISO size: $ISO_SIZE"
echo "iso_file=$ISO_FILE" >> $GITHUB_OUTPUT
else
exit 1
fi
- name: Compress ISO
id: compress_iso
run: |
ISO_FILE="${{ steps.create_iso.outputs.iso_file }}"
ZIP_FILE="${ISO_FILE}.zip"
echo "Compressing ISO with zip..."
zip -j "$ZIP_FILE" "$ISO_FILE"
echo "compressed_file=$ZIP_FILE" >> $GITHUB_OUTPUT
- name: Upload Recovery ISO artifact
uses: actions/upload-artifact@v7
with:
path: ${{ steps.compress_iso.outputs.compressed_file }}
compression-level: 0
retention-days: 15
archive: false
- name: Sanitize release tag
id: sanitize_tag
if: github.event.inputs.release_tag != ''
run: |
tag="${{ github.event.inputs.release_tag }}"
# Replace spaces and other invalid characters with hyphens
# Keep only alphanumeric, dots, hyphens, and underscores
sanitized_tag=$(echo "$tag" | sed 's/[^a-zA-Z0-9._-]/-/g' | sed 's/--*/-/g' | sed 's/^-//;s/-$//')
echo "sanitized_tag=$sanitized_tag" >> $GITHUB_OUTPUT
- name: Create Release
if: github.event.inputs.release_tag != ''
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
continue-on-error: true
run: |
title="macOS ${{ steps.version_info.outputs.version_name }} Recovery"
tag="${{ steps.sanitize_tag.outputs.sanitized_tag }}"
gh release create $tag \
--title "$title" \
${{ steps.compress_iso.outputs.compressed_file }}
- name: Summary
if: always()
run: |
if [ "${{ steps.download_recovery_image.outcome }}" == "failure" ]; then
echo "## Download RecoveryOS failed" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "> [!WARNING]" >> $GITHUB_STEP_SUMMARY
echo "> This runner may have network issues. Please **re-run the workflow** to try a different runner." >> $GITHUB_STEP_SUMMARY
elif [ "${{ job.status }}" == "success" ]; then
echo "## Successfully built **macOS ${{ steps.version_info.outputs.version_name }} Recovery** ISO" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "> [!Important]" >> $GITHUB_STEP_SUMMARY
echo "> This ISO image is intended for creating macOS virtual machine on Proxmox VE, QEMU, VMware, and VirtualBox." >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "> [!TIP]" >> $GITHUB_STEP_SUMMARY
echo "> Enable [Cloudflare WARP](https://one.one.one.one/) for faster download from GitHub artifact." >> $GITHUB_STEP_SUMMARY
fi