Skip to content

Instantly share code, notes, and snippets.

@YOU54F
Last active June 8, 2025 19:31
Show Gist options
  • Save YOU54F/3ac099e54e48a31a69ac2d671aa878f6 to your computer and use it in GitHub Desktop.
Save YOU54F/3ac099e54e48a31a69ac2d671aa878f6 to your computer and use it in GitHub Desktop.
Run GitHub Actions projects, locally, using on MacOS ARM64 Virtual Machines with Tart
#!/bin/bash
PROJECT=${PWD##*/}
PLATFORM=${PLATFORM:-macos-latest}
WORKFLOW=${WORKFLOW:-test.yml}
IMAGE=${IMAGE:-runner}
SSH_USER=${SSH_USER:-runner}
SSH_PASS=${SSH_PASS:-runner}
# IMAGE=${IMAGE:-ghcr.io/cirruslabs/macos-ventura-xcode:14.3.1}
function cleanup {
echo "Cleaning up..."
tart stop "$PROJECT" || echo 'failed to stop'
if [[ -z ${KEEP} ]]; then
echo "cleaning vm $PROJECT"
tart delete "$PROJECT" || echo 'failed to delete'
set +e
tart list | grep "$PROJECT" && echo failed to cleanup && exit 1
else
echo retaining vm "$PROJECT"
fi
}
trap cleanup EXIT
set -e # always ensure our trap runs
echo "Running for project $PROJECT"
if [[ ${PLATFORM} =~ "macos" ]]; then
tart clone "$IMAGE" "$PROJECT"
tart list | grep "$PROJECT"
tart get "$PROJECT"
tart run "$PROJECT" --dir="${PROJECT}:$PWD" --no-graphics &
echo "Waiting for VM to start..."
tart ip "$PROJECT" --wait 60
tart get "$PROJECT"
passh -p $SSH_PASS ssh $SSH_USER@"$(tart ip "$PROJECT")" -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=accept-new -t "source ~/.zprofile && brew install act"
set +e
passh -p $SSH_PASS ssh $SSH_USER@"$(tart ip "$PROJECT")" -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=accept-new -t "source ~/.zprofile && cd /Volumes/My\ Shared\ files/${PWD##*/} && act -P ${PLATFORM}=-self-hosted -W ${WORKFLOW} $*"
ACT_EXIT_CODE=$?
set -e
fi
if [[ ${ACT_EXIT_CODE} != "" ]]; then
echo $ACT_EXIT_CODE
exit $ACT_EXIT_CODE
else
exit 0
fi
@YOU54F
Copy link
Author

YOU54F commented Oct 4, 2023

Run GitHub Actions projects, locally, using on MacOS ARM64 Virtual Machines

pre reqs

usage

Drop into an project with a GitHub workflow with a macos-latest runner

export MACT_TART=https://gist.githubusercontent.com/YOU54F/3ac099e54e48a31a69ac2d671aa878f6/raw/491a72eea3aa71cc6137f46850ecbd0c26501e96/mact-tart
curl -fsSL $MACT_TART | WORKFLOW=.github/workflows/test.yml sh -s -- --matrix os:macos-latest --matrix go-version:1.21.x --no-cache-server

Use the following env vars to control stuff

PLATFORM=${PLATFORM:-macos-latest}
WORKFLOW=${WORKFLOW:-test.yml}
IMAGE=${IMAGE:-runner}
SSH_USER=${SSH_USER:-runner}

TODO

  • support linux images
  • support linux on macOS x86_64 hosts
  • support using .ssh tokens
  • allow copying ssh tokens from host
  • allow copying ssh tokens from github users
    • curl https://github.com/you54f.keys | tee -a ~/.ssh/authorized_keys
  • support other macos virt providers
    • Parallels
    • macosvm
    • utm
    • qemu
  • Support other operating systems
    • linux
    • windows
    • freebsd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment