|
| 1 | +name:Recreate macOS self-hosted runners on schedule |
| 2 | + |
| 3 | +on: |
| 4 | +workflow_dispatch: |
| 5 | +schedule: |
| 6 | +# Once each 24 hours, at 1 during the night |
| 7 | + -cron:"0 1 * * *" |
| 8 | + |
| 9 | +concurrency: |
| 10 | +group:recreate-macos-runners |
| 11 | +cancel-in-progress:true |
| 12 | + |
| 13 | +jobs: |
| 14 | +recreate: |
| 15 | +if:github.repository == 'Homebrew/homebrew-core' |
| 16 | +runs-on:ubuntu-latest |
| 17 | +strategy: |
| 18 | +matrix: |
| 19 | +include: |
| 20 | + -runner_name:monterey-1 |
| 21 | +label:12 |
| 22 | +vm_name:monterey |
| 23 | +node:macpro-4 |
| 24 | +port:8822 |
| 25 | + -runner_name:monterey-2 |
| 26 | +label:12 |
| 27 | +vm_name:monterey |
| 28 | +node:macpro-4 |
| 29 | +port:8823 |
| 30 | + -runner_name:monterey-3 |
| 31 | +label:12 |
| 32 | +vm_name:monterey |
| 33 | +node:macpro-4 |
| 34 | +port:8824 |
| 35 | + -runner_name:monterey-4 |
| 36 | +label:12 |
| 37 | +vm_name:monterey |
| 38 | +node:macpro-4 |
| 39 | +port:8825 |
| 40 | + -runner_name:bigsur-1 |
| 41 | +label:11 |
| 42 | +vm_name:bigsur |
| 43 | +node:macpro-5 |
| 44 | +port:8822 |
| 45 | + -runner_name:bigsur-2 |
| 46 | +label:11 |
| 47 | +vm_name:bigsur |
| 48 | +node:macpro-5 |
| 49 | +port:8823 |
| 50 | + -runner_name:bigsur-3 |
| 51 | +label:11 |
| 52 | +vm_name:bigsur |
| 53 | +node:macpro-5 |
| 54 | +port:8824 |
| 55 | + -runner_name:bigsur-4 |
| 56 | +label:11 |
| 57 | +vm_name:bigsur |
| 58 | +node:macpro-5 |
| 59 | +port:8825 |
| 60 | + -runner_name:catalina-1 |
| 61 | +label:10.15 |
| 62 | +vm_name:catalina |
| 63 | +node:macpro-6 |
| 64 | +port:8822 |
| 65 | + -runner_name:catalina-2 |
| 66 | +label:10.15 |
| 67 | +vm_name:catalina |
| 68 | +node:macpro-6 |
| 69 | +port:8823 |
| 70 | + -runner_name:catalina-3 |
| 71 | +label:10.15 |
| 72 | +vm_name:catalina |
| 73 | +node:macpro-6 |
| 74 | +port:8824 |
| 75 | + -runner_name:catalina-4 |
| 76 | +label:10.15 |
| 77 | +vm_name:catalina |
| 78 | +node:macpro-6 |
| 79 | +port:8825 |
| 80 | +steps: |
| 81 | + -name:Install openconnect |
| 82 | +run:brew install openconnect |
| 83 | + |
| 84 | + -name:Checkout Orka API Client gem |
| 85 | +uses:actions/checkout@v2 |
| 86 | +with: |
| 87 | +repository:Homebrew/orka_api_client |
| 88 | +path:orka_api_client |
| 89 | +persist-credentials:false |
| 90 | + |
| 91 | + -name:Set up Ruby |
| 92 | +uses:ruby/setup-ruby@v1 |
| 93 | +with: |
| 94 | +ruby-version:"3.1" |
| 95 | +bundler-cache:true |
| 96 | +working-directory:orka_api_client |
| 97 | + |
| 98 | + -name:Install Orka API Client gem |
| 99 | +working-directory:orka_api_client |
| 100 | +run:| |
| 101 | + bundle exec rake |
| 102 | + gem install pkg/orka_api_client-*.gem |
| 103 | +
|
| 104 | + -name:Wait for idle runner |
| 105 | +id:killable |
| 106 | +uses:Homebrew/actions/wait-for-idle-runner@master |
| 107 | +with: |
| 108 | +runner_name:${{ matrix.runner_name }} |
| 109 | +github_token:${{ secrets.HOMEBREW_GITHUB_PUBLIC_REPO_TOKEN }} |
| 110 | + |
| 111 | + -name:Connect to Orka VPN |
| 112 | +if:${{ steps.killable.outputs.runner-found == 'true' && steps.killable.outputs.runner-idle == 'true' }} |
| 113 | +run:echo "${{ secrets.ORKA_VPN_PASSWORD }}" | openconnect "${{ secrets.ORKA_VPN_IP }}" --user="${{ secrets.ORKA_VPN_USER }}" --background --setuid=$(whoami) --servercert pin-sha256:vbaO8lPevDx8SUVMUy43VtttA+hL2RxYSjgXHd0Qey8= |
| 114 | + |
| 115 | + -name:Kill runner and create a new one |
| 116 | +if:${{ steps.killable.outputs.runner-found == 'true' && steps.killable.outputs.runner-idle == 'true' }} |
| 117 | +run:| |
| 118 | + ruby -rorka_api_client -e ' |
| 119 | + client = OrkaAPI::Client.new("${{ secrets.ORKA_API_URL }}", token: "${{ secrets.ORKA_API_TOKEN }}") |
| 120 | + resource = client.vm_resource("${{ matrix.vm_name }}") |
| 121 | + instance = resource.instances.find do |instance| |
| 122 | + instance.node.name == "${{ matrix.node }}" && instance.ssh_port == ${{ matrix.port }} |
| 123 | + end |
| 124 | +
|
| 125 | + raise "Cannot find VM for ${{ matrix.runner_name }}!" if instance.nil? |
| 126 | +
|
| 127 | + instance.delete |
| 128 | + resource.deploy(node: instance.node, vm_metadata: { |
| 129 | + "registration_token" => "", |
| 130 | + "runner_name" => "${{ matrix.runner_name }}", |
| 131 | + "label" => "${{ matrix.label }}", |
| 132 | + }) |
| 133 | + ' |
| 134 | +
|
| 135 | + -name:Disonnect from Orka VPN |
| 136 | +if:${{ always() && steps.killable.outputs.runner-found == 'true' && steps.killable.outputs.runner-idle == 'true' }} |
| 137 | +run:killall -SIGINT openconnect |