|
| 1 | +# Sanity workflow that verifies the NUnit + Playwright BrowserStack SDK sample |
| 2 | +# against a full commit id, mirroring browserstack/xunit-reqnroll-playwright-browserstack. |
| 3 | +# Two test runs: |
| 4 | +# 1. Public bstackdemo scenario (browserstackLocal: false in yml). |
| 5 | +# 2. BrowserStack Local scenario (yml flipped to true; a python http.server |
| 6 | +# hosts a tiny title-matching page on port 45454, the SDK starts the tunnel, |
| 7 | +# and the test asserts that the cloud browser sees that page through bs-local.com). |
| 8 | + |
| 9 | +name: NUnit Playwright SDK sanity workflow on workflow_dispatch |
| 10 | + |
| 11 | +on: |
| 12 | + workflow_dispatch: |
| 13 | + inputs: |
| 14 | + commit_sha: |
| 15 | + description: 'The full commit id to build' |
| 16 | + required: true |
| 17 | + |
| 18 | +permissions: |
| 19 | + contents: read |
| 20 | + checks: write |
| 21 | + |
| 22 | +jobs: |
| 23 | + sanity: |
| 24 | + runs-on: ${{ matrix.os }} |
| 25 | + strategy: |
| 26 | + fail-fast: false |
| 27 | + max-parallel: 1 |
| 28 | + matrix: |
| 29 | + dotnet: ['8.0.x'] |
| 30 | + os: [windows-latest, macos-latest] |
| 31 | + name: NUnit Repo ${{ matrix.dotnet }} - ${{ matrix.os }} Sample |
| 32 | + env: |
| 33 | + BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }} |
| 34 | + BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }} |
| 35 | + |
| 36 | + steps: |
| 37 | + - uses: actions/checkout@v3 |
| 38 | + with: |
| 39 | + ref: ${{ github.event.inputs.commit_sha }} |
| 40 | + |
| 41 | + - uses: actions/github-script@98814c53be79b1d30f795b907e553d8679345975 |
| 42 | + id: status-check-in-progress |
| 43 | + env: |
| 44 | + job_name: NUnit Repo ${{ matrix.dotnet }} - ${{ matrix.os }} Sample |
| 45 | + commit_sha: ${{ github.event.inputs.commit_sha }} |
| 46 | + with: |
| 47 | + github-token: ${{ github.token }} |
| 48 | + script: | |
| 49 | + const result = await github.rest.checks.create({ |
| 50 | + owner: context.repo.owner, |
| 51 | + repo: context.repo.repo, |
| 52 | + name: process.env.job_name, |
| 53 | + head_sha: process.env.commit_sha, |
| 54 | + status: 'in_progress' |
| 55 | + }).catch((err) => ({status: err.status, response: err.response})); |
| 56 | + console.log(`The status-check response : ${result.status} Response : ${JSON.stringify(result.response)}`) |
| 57 | + if (result.status !== 201) { |
| 58 | + console.log('Failed to create check run') |
| 59 | + } |
| 60 | +
|
| 61 | + - name: Setup dotnet |
| 62 | + uses: actions/setup-dotnet@v3 |
| 63 | + with: |
| 64 | + dotnet-version: ${{ matrix.dotnet }} |
| 65 | + |
| 66 | + - name: Strip credential placeholders so env vars take effect |
| 67 | + # The yml ships with literal YOUR_USERNAME / YOUR_ACCESS_KEY placeholders; |
| 68 | + # the .NET SDK only falls back to env vars when those lines are absent. |
| 69 | + shell: bash |
| 70 | + working-directory: NunitPlaywrightBrowserstack.Tests |
| 71 | + run: | |
| 72 | + sed -i.bak '/^userName:/d; /^accessKey:/d' browserstack.yml && rm -f browserstack.yml.bak |
| 73 | +
|
| 74 | + - name: Install dependencies |
| 75 | + run: dotnet build |
| 76 | + |
| 77 | + - name: Run sample tests (public bstackdemo) |
| 78 | + working-directory: NunitPlaywrightBrowserstack.Tests |
| 79 | + run: dotnet test --filter "FullyQualifiedName~BStackDemoCart" |
| 80 | + |
| 81 | + - name: Run local tests (BrowserStack Local + python http.server harness) |
| 82 | + shell: bash |
| 83 | + working-directory: NunitPlaywrightBrowserstack.Tests |
| 84 | + run: | |
| 85 | + set -u |
| 86 | + # 1. Stand up a tiny static page with a known <title>. |
| 87 | + mkdir -p "$RUNNER_TEMP/bs-local-harness" |
| 88 | + cat > "$RUNNER_TEMP/bs-local-harness/index.html" <<'HTML' |
| 89 | + <!doctype html> |
| 90 | + <html><head><title>BrowserStack Local Test</title></head> |
| 91 | + <body>OK</body></html> |
| 92 | + HTML |
| 93 | + ( cd "$RUNNER_TEMP/bs-local-harness" && python3 -m http.server 45454 ) & |
| 94 | + HTTP_PID=$! |
| 95 | + trap 'kill "$HTTP_PID" 2>/dev/null || true' EXIT |
| 96 | + sleep 2 |
| 97 | + # 2. Flip the SDK Local toggle so the SDK starts/stops the tunnel. |
| 98 | + sed -i.bak 's/^browserstackLocal: false/browserstackLocal: true/' browserstack.yml && rm -f browserstack.yml.bak |
| 99 | + # 3. Run only the local scenario; cloud browser reaches the harness through bs-local.com. |
| 100 | + dotnet test --filter "FullyQualifiedName~BStackLocalSample" |
| 101 | +
|
| 102 | + - if: always() |
| 103 | + uses: actions/github-script@98814c53be79b1d30f795b907e553d8679345975 |
| 104 | + id: status-check-completed |
| 105 | + env: |
| 106 | + conclusion: ${{ job.status }} |
| 107 | + job_name: NUnit Repo ${{ matrix.dotnet }} - ${{ matrix.os }} Sample |
| 108 | + commit_sha: ${{ github.event.inputs.commit_sha }} |
| 109 | + with: |
| 110 | + github-token: ${{ github.token }} |
| 111 | + script: | |
| 112 | + const result = await github.rest.checks.create({ |
| 113 | + owner: context.repo.owner, |
| 114 | + repo: context.repo.repo, |
| 115 | + name: process.env.job_name, |
| 116 | + head_sha: process.env.commit_sha, |
| 117 | + status: 'completed', |
| 118 | + conclusion: process.env.conclusion |
| 119 | + }).catch((err) => ({status: err.status, response: err.response})); |
| 120 | + console.log(`The status-check response : ${result.status} Response : ${JSON.stringify(result.response)}`) |
| 121 | + if (result.status !== 201) { |
| 122 | + console.log('Failed to create check run') |
| 123 | + } |
0 commit comments