|
| 1 | +name: Runner E2E Test |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - main |
| 8 | + - releases/* |
| 9 | + |
| 10 | +jobs: |
| 11 | + init: |
| 12 | + name: Initialize workflow ☕ |
| 13 | + runs-on: ubuntu-latest |
| 14 | + outputs: |
| 15 | + unique_runner_label: ${{steps.generator.outputs.runner_label}} |
| 16 | + steps: |
| 17 | + - name: Delete all runners |
| 18 | + uses: actions/github-script@v3 |
| 19 | + with: |
| 20 | + debug: true |
| 21 | + script: | |
| 22 | + var runnersResp = await github.actions.listSelfHostedRunnersForRepo({ |
| 23 | + owner: 'actions', |
| 24 | + repo: 'runner', |
| 25 | + per_page: '100' |
| 26 | + }); |
| 27 | + for(var i=0; i<runnersResp.data.total_count; i++){ |
| 28 | + core.debug(JSON.stringify(runnersResp.data.runners[i])) |
| 29 | + await github.actions.deleteSelfHostedRunnerFromRepo({ |
| 30 | + owner: 'actions', |
| 31 | + repo: 'runner', |
| 32 | + runner_id: runnersResp.data.runners[i].id |
| 33 | + }); |
| 34 | + } |
| 35 | + github-token: ${{secrets.PAT}} |
| 36 | + - name: Generate Unique Runner label |
| 37 | + id: generator |
| 38 | + run: | |
| 39 | + label=$(openssl rand -hex 16) |
| 40 | + echo ::set-output name=runner_label::$label |
| 41 | +
|
| 42 | + build: |
| 43 | + name: Build runner packages 🏗 📦 |
| 44 | + strategy: |
| 45 | + matrix: |
| 46 | + runtime: [ linux-x64, linux-arm64, linux-arm, win-x64, osx-x64 ] |
| 47 | + include: |
| 48 | + - runtime: linux-x64 |
| 49 | + os: ubuntu-latest |
| 50 | + devScript: ./dev.sh |
| 51 | + |
| 52 | + - runtime: linux-arm64 |
| 53 | + os: ubuntu-latest |
| 54 | + devScript: ./dev.sh |
| 55 | + |
| 56 | + - runtime: linux-arm |
| 57 | + os: ubuntu-latest |
| 58 | + devScript: ./dev.sh |
| 59 | + |
| 60 | + - runtime: osx-x64 |
| 61 | + os: macOS-latest |
| 62 | + devScript: ./dev.sh |
| 63 | + |
| 64 | + - runtime: win-x64 |
| 65 | + os: windows-latest |
| 66 | + devScript: ./dev |
| 67 | + |
| 68 | + runs-on: ${{ matrix.os }} |
| 69 | + steps: |
| 70 | + - uses: actions/checkout@v1 |
| 71 | + |
| 72 | + # Build runner layout |
| 73 | + - name: Build & Layout Release |
| 74 | + run: | |
| 75 | + ${{ matrix.devScript }} layout Release ${{ matrix.runtime }} |
| 76 | + working-directory: src |
| 77 | + |
| 78 | + # Create runner package tar.gz/zip |
| 79 | + - name: Package Release |
| 80 | + run: | |
| 81 | + ${{ matrix.devScript }} package Release ${{ matrix.runtime }} |
| 82 | + working-directory: src |
| 83 | + |
| 84 | + # Upload runner package tar.gz/zip as artifact |
| 85 | + - name: Publish Artifact |
| 86 | + uses: actions/upload-artifact@v1 |
| 87 | + with: |
| 88 | + name: runner-package-${{ matrix.runtime }} |
| 89 | + path: _package |
| 90 | + |
| 91 | + dispatch_workflow: |
| 92 | + name: Dispatch workflow to runners 🚨 |
| 93 | + needs: [init, build] |
| 94 | + runs-on: ubuntu-latest |
| 95 | + steps: |
| 96 | + - name: Dispatch workflow |
| 97 | + timeout-minutes: 10 |
| 98 | + uses: actions/github-script@v3 |
| 99 | + with: |
| 100 | + debug: true |
| 101 | + script: | |
| 102 | + function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } |
| 103 | + async function dispatchWorkflow(runner) { |
| 104 | + await github.actions.createWorkflowDispatch({ |
| 105 | + owner: 'actions', |
| 106 | + repo: 'runner', |
| 107 | + workflow_id: 'runner-basic-e2e-test-case.yml', |
| 108 | + ref: 'main', |
| 109 | + inputs: {target_runner: runner} |
| 110 | + }); |
| 111 | + } |
| 112 | + var runWin64 = false, runLinux64 = false, runOsx64 = false, runLinuxARM64 = false; |
| 113 | + while (true) { |
| 114 | + core.info(`------------- Waiting for runners to be configured --------------`) |
| 115 | + await sleep(10000); |
| 116 | + var runnersResp = await github.actions.listSelfHostedRunnersForRepo({owner: 'actions', repo: 'runner', per_page: '100'}); |
| 117 | + for (var i = 0; i < runnersResp.data.total_count; i++) { |
| 118 | + core.debug(JSON.stringify(runnersResp.data.runners[i])) |
| 119 | + var labels = runnersResp.data.runners[i].labels; |
| 120 | + for (var j = 0; j < labels.length; j++) { |
| 121 | + core.debug(`Comparing: ${labels[j].name} to win-x64/linux-x64/osx-x64/linux-arm64-${{ needs.init.outputs.unique_runner_label }}`) |
| 122 | + if (labels[j].name == 'win-x64-${{needs.init.outputs.unique_runner_label}}' && runWin64 == false) { |
| 123 | + core.info(`------------------- Windows runner is configured, queue Windows Run -------------------------`) |
| 124 | + runWin64 = true; |
| 125 | + await dispatchWorkflow('win-x64-${{needs.init.outputs.unique_runner_label}}'); |
| 126 | + break; |
| 127 | + } else if (labels[j].name == 'linux-x64-${{needs.init.outputs.unique_runner_label}}' && runLinux64 == false) { |
| 128 | + core.info(`------------------- Linux runner is configured, queue Linux Run -------------------------`) |
| 129 | + runLinux64 = true; |
| 130 | + await dispatchWorkflow('linux-x64-${{needs.init.outputs.unique_runner_label}}'); |
| 131 | + break; |
| 132 | + } else if (labels[j].name == 'osx-x64-${{needs.init.outputs.unique_runner_label}}' && runOsx64 == false) { |
| 133 | + core.info(`------------------- macOS runner is configured, queue macOS Run -------------------------`) |
| 134 | + runOsx64 = true; |
| 135 | + await dispatchWorkflow('osx-x64-${{needs.init.outputs.unique_runner_label}}'); |
| 136 | + break; |
| 137 | + } else if (labels[j].name == 'linux-arm64-${{needs.init.outputs.unique_runner_label}}' && runLinuxARM64 == false) { |
| 138 | + core.info(`------------------- Linux ARM64 runner is configured, queue Linux ARM64 Run-------------------------`) |
| 139 | + runLinuxARM64 = true; |
| 140 | + await dispatchWorkflow('linux-arm64-${{needs.init.outputs.unique_runner_label}}'); |
| 141 | + break; |
| 142 | + } |
| 143 | + } |
| 144 | + } |
| 145 | + if (runWin64 && runLinux64 && runOsx64 && runLinuxARM64) { |
| 146 | + core.info(`--------------------- ALL runner are running jobs --------------------------`) |
| 147 | + break; |
| 148 | + } else { |
| 149 | + core.info(`---------- Windows running: ${runWin64} -- Linux running: ${runLinux64} -- macOS running: ${runOsx64} -- Linux ARM64 running: ${runLinuxARM64} -----------`) |
| 150 | + } |
| 151 | + } |
| 152 | + github-token: ${{secrets.PAT}} |
| 153 | + |
| 154 | + LinuxE2E: |
| 155 | + needs: [build, init] |
| 156 | + runs-on: ubuntu-latest |
| 157 | + steps: |
| 158 | + - name: Download Runner |
| 159 | + uses: actions/download-artifact@v2 |
| 160 | + with: |
| 161 | + name: runner-package-linux-x64 |
| 162 | + - name: Unzip Runner Package |
| 163 | + run: | |
| 164 | + tar -xzf *.tar.gz |
| 165 | + - name: Configure Runner |
| 166 | + env: |
| 167 | + unique_runner_name: linux-x64-${{needs.init.outputs.unique_runner_label}} |
| 168 | + run: | |
| 169 | + ./config.sh --url ${{github.event.repository.html_url}} --unattended --name $unique_runner_name --pat ${{secrets.PAT}} --labels $unique_runner_name --replace |
| 170 | + - name: Start Runner and Wait for Job |
| 171 | + timeout-minutes: 5 |
| 172 | + run: | |
| 173 | + ./run.sh --once |
| 174 | + - name: Remove Runner |
| 175 | + if: always() |
| 176 | + continue-on-error: true |
| 177 | + run: | |
| 178 | + ./config.sh remove --pat ${{secrets.PAT}} |
| 179 | + - name: Upload Runner Logs |
| 180 | + if: always() |
| 181 | + uses: actions/upload-artifact@v2 |
| 182 | + with: |
| 183 | + name: linux_x64_logs |
| 184 | + path: _diag |
| 185 | + macOSE2E: |
| 186 | + needs: [build, init] |
| 187 | + runs-on: macos-latest |
| 188 | + steps: |
| 189 | + - name: Download Runner |
| 190 | + uses: actions/download-artifact@v2 |
| 191 | + with: |
| 192 | + name: runner-package-osx-x64 |
| 193 | + - name: Unzip Runner Package |
| 194 | + run: | |
| 195 | + tar -xzf *.tar.gz |
| 196 | + - name: Configure Runner |
| 197 | + env: |
| 198 | + unique_runner_name: osx-x64-${{needs.init.outputs.unique_runner_label}} |
| 199 | + run: | |
| 200 | + ./config.sh --url ${{github.event.repository.html_url}} --unattended --name $unique_runner_name --pat ${{secrets.PAT}} --labels $unique_runner_name --replace |
| 201 | + - name: Start Runner and Wait for Job |
| 202 | + timeout-minutes: 5 |
| 203 | + run: | |
| 204 | + ./run.sh --once |
| 205 | + - name: Remove Runner |
| 206 | + if: always() |
| 207 | + continue-on-error: true |
| 208 | + run: | |
| 209 | + ./config.sh remove --pat ${{secrets.PAT}} |
| 210 | + - name: Upload Runner Logs |
| 211 | + if: always() |
| 212 | + uses: actions/upload-artifact@v2 |
| 213 | + with: |
| 214 | + name: osx_x64_logs |
| 215 | + path: _diag |
| 216 | + |
| 217 | + ARM64E2E: |
| 218 | + needs: [build, init] |
| 219 | + runs-on: ubuntu-latest |
| 220 | + steps: |
| 221 | + - name: Download Runner |
| 222 | + uses: actions/download-artifact@v2 |
| 223 | + with: |
| 224 | + name: runner-package-linux-arm64 |
| 225 | + - name: Unzip Runner Package |
| 226 | + run: | |
| 227 | + tar -xzf *.tar.gz |
| 228 | + - name: Prepare QEMU |
| 229 | + run: | |
| 230 | + docker run --rm --privileged multiarch/qemu-user-static:register --reset |
| 231 | + - name: Configure Runner |
| 232 | + uses: docker://multiarch/ubuntu-core:arm64-bionic |
| 233 | + with: |
| 234 | + args: 'bash -c "apt-get update && apt-get install -y curl && ./bin/installdependencies.sh && ./config.sh --unattended --name $unique_runner_name --url ${{github.event.repository.html_url}} --pat ${{secrets.PAT}} --labels $unique_runner_name --replace"' |
| 235 | + env: |
| 236 | + RUNNER_ALLOW_RUNASROOT: 1 |
| 237 | + unique_runner_name: linux-arm64-${{needs.init.outputs.unique_runner_label}} |
| 238 | + |
| 239 | + - name: Start Runner and Wait for Job |
| 240 | + timeout-minutes: 5 |
| 241 | + uses: docker://multiarch/ubuntu-core:arm64-bionic |
| 242 | + with: |
| 243 | + args: 'bash -c "apt-get update && apt-get install -y curl git && ./bin/installdependencies.sh && ./run.sh --once"' |
| 244 | + env: |
| 245 | + RUNNER_ALLOW_RUNASROOT: 1 |
| 246 | + |
| 247 | + - name: Remove Runner |
| 248 | + if: always() |
| 249 | + continue-on-error: true |
| 250 | + uses: docker://multiarch/ubuntu-core:arm64-bionic |
| 251 | + with: |
| 252 | + args: 'bash -c "apt-get update && apt-get install -y curl && ./bin/installdependencies.sh && ./config.sh remove --pat ${{secrets.PAT}}"' |
| 253 | + env: |
| 254 | + RUNNER_ALLOW_RUNASROOT: 1 |
| 255 | + |
| 256 | + - name: Upload Runner Logs |
| 257 | + if: always() |
| 258 | + uses: actions/upload-artifact@v2 |
| 259 | + with: |
| 260 | + name: linux_arm64_logs |
| 261 | + path: _diag |
| 262 | + |
| 263 | + WindowsE2E: |
| 264 | + needs: [build, init] |
| 265 | + runs-on: windows-latest |
| 266 | + steps: |
| 267 | + - name: Download Runner |
| 268 | + uses: actions/download-artifact@v2 |
| 269 | + with: |
| 270 | + name: runner-package-win-x64 |
| 271 | + - name: Unzip Runner Package |
| 272 | + run: | |
| 273 | + Get-ChildItem *.zip | Expand-Archive -DestinationPath $PWD |
| 274 | + - name: Configure Runner |
| 275 | + shell: cmd |
| 276 | + run: | |
| 277 | + config.cmd --unattended --url ${{github.event.repository.html_url}} --name %unique_runner_name% --pat ${{secrets.PAT}} --labels %unique_runner_name% --replace |
| 278 | + env: |
| 279 | + unique_runner_name: win-x64-${{needs.init.outputs.unique_runner_label}} |
| 280 | + |
| 281 | + - name: Start Runner and Wait for Job |
| 282 | + shell: cmd |
| 283 | + timeout-minutes: 5 |
| 284 | + run: | |
| 285 | + run.cmd --once |
| 286 | + - name: Remove Runner |
| 287 | + shell: cmd |
| 288 | + if: always() |
| 289 | + continue-on-error: true |
| 290 | + run: | |
| 291 | + config.cmd remove --pat ${{secrets.PAT}} |
| 292 | + - name: Upload Runner Logs |
| 293 | + if: always() |
| 294 | + uses: actions/upload-artifact@v2 |
| 295 | + with: |
| 296 | + name: win_x64_logs |
| 297 | + path: _diag |
| 298 | + |
| 299 | + check: |
| 300 | + name: Check runner logs 🕵️♂️ |
| 301 | + needs: [WindowsE2E, LinuxE2E, macOSE2E, ARM64E2E] |
| 302 | + runs-on: ubuntu-latest |
| 303 | + steps: |
| 304 | + - name: Download Linux Runner Logs |
| 305 | + uses: actions/download-artifact@v2 |
| 306 | + with: |
| 307 | + name: linux_x64_logs |
| 308 | + path: linux_x64_logs |
| 309 | + - name: Download macOS Runner Logs |
| 310 | + uses: actions/download-artifact@v2 |
| 311 | + with: |
| 312 | + name: osx_x64_logs |
| 313 | + path: osx_x64_logs |
| 314 | + - name: Download Linux ARM64 Runner Logs |
| 315 | + uses: actions/download-artifact@v2 |
| 316 | + with: |
| 317 | + name: linux_arm64_logs |
| 318 | + path: linux_arm64_logs |
| 319 | + - name: Download Windows Runner Logs |
| 320 | + uses: actions/download-artifact@v2 |
| 321 | + with: |
| 322 | + name: win_x64_logs |
| 323 | + path: win_x64_logs |
| 324 | + - name: Check Runner Logs |
| 325 | + run: | |
| 326 | + function failed() |
| 327 | + { |
| 328 | + local error=${1:-Undefined error} |
| 329 | + echo "Failed: $error" >&2 |
| 330 | + exit 1 |
| 331 | + } |
| 332 | + grep -R "completed with result: Succeeded" ./win_x64_logs || failed "Windows Runner fail to run the job, please check logs" |
| 333 | + grep -R "completed with result: Succeeded" ./linux_x64_logs || failed "Linux Runner fail to run the job, please check logs" |
| 334 | + grep -R "completed with result: Succeeded" ./osx_x64_logs || failed "macOS Runner fail to run the job, please check logs" |
| 335 | + grep -R "completed with result: Succeeded" ./linux_arm64_logs || failed "Linux ARM64 Runner fail to run the job, please check logs" |
0 commit comments