|
| 1 | +name: Multi-Platform Test Matrix |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - develop |
| 8 | + pull_request: |
| 9 | + branches: |
| 10 | + - main |
| 11 | + - develop |
| 12 | + workflow_dispatch: |
| 13 | + inputs: |
| 14 | + dotnet_version: |
| 15 | + description: '.NET SDK version to use' |
| 16 | + required: false |
| 17 | + default: '9.0.x' |
| 18 | + type: string |
| 19 | + |
| 20 | +jobs: |
| 21 | + test-matrix: |
| 22 | + name: Test on ${{ matrix.os }} (${{ matrix.arch }}) |
| 23 | + runs-on: ${{ matrix.runner }} |
| 24 | + |
| 25 | + strategy: |
| 26 | + fail-fast: false |
| 27 | + matrix: |
| 28 | + include: |
| 29 | + # Windows x64 |
| 30 | + - os: windows |
| 31 | + arch: x64 |
| 32 | + runner: windows-latest |
| 33 | + rid: win-x64 |
| 34 | + |
| 35 | + # Linux x64 |
| 36 | + - os: linux |
| 37 | + arch: x64 |
| 38 | + runner: ubuntu-latest |
| 39 | + rid: linux-x64 |
| 40 | + |
| 41 | + # Linux ARM64 |
| 42 | + - os: linux |
| 43 | + arch: arm64 |
| 44 | + runner: ubuntu-latest-arm64 |
| 45 | + rid: linux-arm64 |
| 46 | + |
| 47 | + # macOS x64 (Intel) |
| 48 | + - os: macos |
| 49 | + arch: x64 |
| 50 | + runner: macos-13 |
| 51 | + rid: osx-x64 |
| 52 | + |
| 53 | + # macOS ARM64 (Apple Silicon) |
| 54 | + - os: macos |
| 55 | + arch: arm64 |
| 56 | + runner: macos-latest |
| 57 | + rid: osx-arm64 |
| 58 | + |
| 59 | + steps: |
| 60 | + - name: Checkout code |
| 61 | + uses: actions/checkout@v4 |
| 62 | + |
| 63 | + - name: Setup .NET |
| 64 | + uses: actions/setup-dotnet@v4 |
| 65 | + with: |
| 66 | + dotnet-version: ${{ inputs.dotnet_version || '9.0.x' }} |
| 67 | + |
| 68 | + - name: Set up Docker Compose |
| 69 | + uses: docker/setup-compose-action@v1 |
| 70 | + |
| 71 | + - name: Start SSH test server (Docker) |
| 72 | + working-directory: ./src/NullOpsDevs.LibSsh.Test |
| 73 | + run: docker compose up --build -d |
| 74 | + |
| 75 | + - name: Wait for SSH server to be ready |
| 76 | + run: | |
| 77 | + echo "Waiting for SSH server to start..." |
| 78 | + sleep 5 |
| 79 | +
|
| 80 | + - name: Setup SSH Agent (Linux/macOS) |
| 81 | + if: matrix.os != 'windows' |
| 82 | + run: | |
| 83 | + eval $(ssh-agent -s) |
| 84 | + echo "SSH_AUTH_SOCK=$SSH_AUTH_SOCK" >> $GITHUB_ENV |
| 85 | + echo "SSH_AGENT_PID=$SSH_AGENT_PID" >> $GITHUB_ENV |
| 86 | + cp src/NullOpsDevs.LibSsh.Test/docker/test-keys/id_rsa /tmp/id_rsa |
| 87 | + chmod 600 /tmp/id_rsa |
| 88 | + ssh-add /tmp/id_rsa |
| 89 | +
|
| 90 | + - name: Setup SSH Agent (Windows) |
| 91 | + if: matrix.os == 'windows' |
| 92 | + shell: powershell |
| 93 | + run: | |
| 94 | + Start-Service ssh-agent |
| 95 | + Set-Service -Name ssh-agent -StartupType 'Automatic' |
| 96 | + Copy-Item "src\NullOpsDevs.LibSsh.Test\docker\test-keys\id_rsa" "$env:TEMP\id_rsa" |
| 97 | + ssh-add "$env:TEMP\id_rsa" |
| 98 | +
|
| 99 | + - name: Restore dependencies |
| 100 | + run: dotnet restore |
| 101 | + |
| 102 | + - name: Build library (Release) |
| 103 | + run: dotnet build -c Release --no-restore |
| 104 | + |
| 105 | + - name: Build test project (Release) |
| 106 | + run: dotnet build -c Release --self-contained -r ${{ matrix.rid }} ./src/NullOpsDevs.LibSsh.Test/NullOpsDevs.LibSsh.Test.csproj |
| 107 | + |
| 108 | + - name: Run tests (Linux/macOS) |
| 109 | + if: matrix.os != 'windows' |
| 110 | + working-directory: ./src/NullOpsDevs.LibSsh.Test/bin/Release/net9.0/${{ matrix.rid }}/ |
| 111 | + run: ./NullOpsDevs.LibSsh.Test |
| 112 | + |
| 113 | + - name: Run tests (Windows) |
| 114 | + if: matrix.os == 'windows' |
| 115 | + working-directory: ./src/NullOpsDevs.LibSsh.Test/bin/Release/net9.0/${{ matrix.rid }}/ |
| 116 | + shell: powershell |
| 117 | + run: .\NullOpsDevs.LibSsh.Test.exe |
| 118 | + |
| 119 | + - name: Cleanup Docker |
| 120 | + if: always() |
| 121 | + working-directory: ./src/NullOpsDevs.LibSsh.Test |
| 122 | + run: docker compose down -v |
| 123 | + |
| 124 | + # Summary job that depends on all matrix jobs |
| 125 | + test-summary: |
| 126 | + name: Test Summary |
| 127 | + needs: test-matrix |
| 128 | + runs-on: ubuntu-latest |
| 129 | + if: always() |
| 130 | + |
| 131 | + steps: |
| 132 | + - name: Check test results |
| 133 | + run: | |
| 134 | + if [ "${{ needs.test-matrix.result }}" == "success" ]; then |
| 135 | + echo "✅ All platform tests passed!" |
| 136 | + exit 0 |
| 137 | + else |
| 138 | + echo "❌ Some platform tests failed" |
| 139 | + exit 1 |
| 140 | + fi |
0 commit comments