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

237 lines
9.5 KiB
YAML

name: Build macOS 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:
runs-on: macos-latest
permissions:
contents: write # needed to create releases
timeout-minutes: 15
steps:
- name: Checkout repository
uses: actions/checkout@v5
- name: System Information
run: |
echo "Runner OS: $(sw_vers -productName) $(sw_vers -productVersion)"
echo "Architecture: $(uname -m)"
echo "Available disk space:"
df -h
echo "Python version:"
python3 --version
- name: Download macrecovery.py
id: download_recovery_image
continue-on-error: true
run: |
echo "Downloading macrecovery.py from acidanthera/OpenCorePkg..."
curl -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
"Lion") KEY="lion1" ;;
"Mountain Lion") KEY="mountain_lion" ;;
"Mavericks") KEY="mavericks" ;;
"Yosemite") KEY="yosemite" ;;
"El Capitan") KEY="el_capitan" ;;
"Sierra") KEY="sierra" ;;
"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
lion1) INFO="Mac-2E6FAB96566FE58C:00000000000F25Y00:Lion:" ;;
mountain_lion) INFO="Mac-7DF2A3B5E5D671ED:00000000000F65100:Mountain_Lion:" ;;
mavericks) INFO="Mac-F60DEB81FF30ACF6:00000000000FNN100:Mavericks:" ;;
yosemite) INFO="Mac-E43C1C25D4880AD6:00000000000GDVW00:Yosemite:" ;;
el_capitan) INFO="Mac-FFE5EF870D7BA81A:00000000000GQRX00:El_Capitan:" ;;
sierra) INFO="Mac-77F17D7DA9285301:00000000000J0DX00:Sierra:" ;;
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
echo "Board ID: $BOARD_ID"
echo "Model: $MODEL"
echo "Version Name: $VERSION_NAME"
echo "OS Flag: $OS_FLAG"
- name: Download macOS Recovery
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
echo "Download completed. Checking files..."
ls -la com.apple.recovery.boot/
- name: Determine recovery image filename
id: recovery_file
run: |
VERSION_NAME="${{ steps.version_info.outputs.version_name }}"
case $VERSION_NAME in
Lion|Mountain_Lion|Mavericks|Yosemite|El_Capitan|Sierra)
RECOVERY_FILE="RecoveryImage.dmg"
;;
*)
RECOVERY_FILE="BaseSystem.dmg"
;;
esac
echo "recovery_file=$RECOVERY_FILE" >> $GITHUB_OUTPUT
echo "Recovery file will be: $RECOVERY_FILE"
if [ ! -f "com.apple.recovery.boot/$RECOVERY_FILE" ]; then
echo "Error: Recovery image not found at: com.apple.recovery.boot/$RECOVERY_FILE"
echo "Available files:"
ls -la com.apple.recovery.boot/
exit 1
fi
- name: Create Recovery ISO
id: create_iso
run: |
VERSION_NAME="${{ steps.version_info.outputs.version_name }}"
RECOVERY_FILE="${{ steps.recovery_file.outputs.recovery_file }}"
ISO_NAME="macOS_${VERSION_NAME}_Recovery"
ISO_FILE="${GITHUB_WORKSPACE}/${ISO_NAME}.iso"
RECOVERY_PATH="com.apple.recovery.boot/$RECOVERY_FILE"
case $VERSION_NAME in
Lion|Mountain_Lion|Mavericks)
HDIUTIL_OPTS="-hfs -iso -joliet"
;;
*)
HDIUTIL_OPTS="-hfs -udf"
;;
esac
echo "Creating bootable ISO with options: $HDIUTIL_OPTS"
echo "Input: $RECOVERY_PATH"
echo "Output: $ISO_FILE"
sudo hdiutil makehybrid $HDIUTIL_OPTS -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 file: $ISO_FILE"
echo "ISO size: $ISO_SIZE"
echo "iso_file=$ISO_FILE" >> $GITHUB_OUTPUT
else
echo "Error: ISO file not created"
exit 1
fi
- name: Compress ISO
id: compress_iso
run: |
ISO_FILE="${{ steps.create_iso.outputs.iso_file }}"
ISO_BASENAME=$(basename "$ISO_FILE")
ZIP_FILE="${GITHUB_WORKSPACE}/${ISO_BASENAME}.zip"
echo "Compressing ISO with zip..."
zip -j "$ZIP_FILE" "$ISO_FILE"
COMPRESSED_SIZE=$(du -h "$ZIP_FILE" | cut -f1)
echo "compressed_file=$ZIP_FILE" >> $GITHUB_OUTPUT
- name: Upload Recovery ISO artifact
uses: actions/upload-artifact@v5
with:
name: macOS-${{ steps.version_info.outputs.version_name }}-Recovery-ISO
path: ${{ steps.compress_iso.outputs.compressed_file }}
compression-level: 0
retention-days: 7
- 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 "Note: This ISO image is intended for create macOS virtual machine on Proxmox VE, QEMU, VMware, and VirtualBox." >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Found this useful? [Give it a ⭐ star](https://github.com/LongQT-sea/macos-iso-builder) so others can find it too!" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "> [!TIP]" >> $GITHUB_STEP_SUMMARY
echo "> Enable [Cloudflare WARP](https://one.one.one.one/) for faster downloads." >> $GITHUB_STEP_SUMMARY
fi