aoh

A tool for running Ansible playbooks with `curl <url> | python` commands
git clone https://git.ashermorgan.net/aoh/
Log | Files | Refs | README

run.ps1 (2108B)


      1 # Note: This scrupt requires the docker daemon to be running from within WSL
      2 
      3 $ErrorActionPreference = 'Stop'
      4 
      5 Push-Location $PSScriptRoot
      6 
      7 function _Docker {
      8     param([Parameter(ValueFromRemainingArguments = $true)][string[]] $DockerArguments)
      9 
     10     & docker @DockerArguments
     11     if ($LASTEXITCODE -ne 0) {
     12         throw "Docker command failed with exit code $LASTEXITCODE"
     13     }
     14 }
     15 
     16 _Docker build -t aoh-test-server ../../
     17 try {
     18     _Docker network create aoh-test
     19 } catch {
     20     # Ignore failure if network exists
     21 }
     22 
     23 try {
     24     for ($i = 1; $i -le 6; $i++) {
     25         if ($i -eq 6) {
     26             # Test 6 is different, and we only run it from run.sh
     27             Write-Output '================================'
     28             Write-Output "Skipping test$i.yml on Windows runner..."
     29             Write-Output '================================'
     30             continue
     31         }
     32 
     33         Write-Output '================================'
     34         Write-Output "Running test$i.yml..."
     35         Write-Output '================================'
     36 
     37         _Docker run --rm --network host --detach -h aoh-test-server `
     38             --name aoh-test-server aoh-test-server
     39         _Docker cp "$PSScriptRoot/." 'aoh-test-server:/aoh/'
     40         Start-Sleep -Seconds 1
     41         irm http://127.0.0.1:8000/run | python3 - test$i.yml
     42 
     43         if ($LASTEXITCODE -ne 0) {
     44             Write-Output '================================'
     45             Write-Output "test$i.yml failed."
     46             Write-Output '================================'
     47             throw "test$i.yml failed."
     48         } else {
     49             Write-Output '================================'
     50             Write-Output "test$i.yml passed."
     51             Write-Output '================================'
     52             Write-Output ''
     53         }
     54 
     55         _Docker stop aoh-test-server
     56         Start-Sleep -Seconds 1
     57     }
     58 } finally {
     59     try {
     60         _Docker stop aoh-test-server
     61     } catch {
     62         # Ignore failures if server already stopped
     63     }
     64 }
     65 
     66 Write-Output '================================'
     67 Write-Output 'All tests passed.'
     68 Write-Output '================================'
     69 exit 0