Skip to content

Commit bcc39dd

Browse files
authored
Merge pull request #366 from csf-dev/craigfowler/issue254
Resolves #254 and #364
2 parents 92bd132 + 337a613 commit bcc39dd

12 files changed

Lines changed: 411 additions & 246 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: 'Restore third-party dependencies'
2+
description: 'Restores dependencies from NuGet and npm'
3+
4+
runs:
5+
using: 'composite'
6+
steps:
7+
- name: Restore .NET packages
8+
run: dotnet restore
9+
shell: bash
10+
- name: Restore Node modules
11+
working-directory: CSF.Screenplay.JsonToHtmlReport.Template/src
12+
run: npm ci
13+
shell: bash
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: 'Run all tests, with coverage'
2+
description: 'Runs all tests for CSF.Screenplay (JS and .NET), with coverage; requires that all .NET projects are already built'
3+
inputs:
4+
configuration:
5+
description: 'The .NET configuration'
6+
default: 'Debug'
7+
tfm:
8+
description: 'The .NET Target Framework Moniker'
9+
required: true
10+
test-results-path:
11+
description: 'The path at which to save test results'
12+
default: 'TestResults'
13+
outputs:
14+
failures:
15+
description: 'Gets a value: `true` or `false` indicating whether or not the tests failed'
16+
value: ${{ steps.emit_output.failures }}
17+
18+
runs:
19+
using: 'composite'
20+
steps:
21+
- name: Run .NET tests with coverage
22+
env:
23+
Configuration: ${{ inputs.configuration }}
24+
Tfm: ${{ inputs.tfm }}
25+
id: dotnet_tests
26+
shell: bash {0}
27+
run: |
28+
for proj in Tests/*.Tests
29+
do
30+
projNameArray=(${proj//// })
31+
projName=${projNameArray[1]}
32+
assemblyPath=$proj/bin/$Configuration/$Tfm/$projName.dll
33+
coverlet "$assemblyPath" --target "dotnet" --targetargs "test $proj -c $Configuration --no-build --logger:nunit --test-adapter-path:." -f=opencover -o="${{ inputs.test-results-path }}/$projName.opencover.xml"
34+
exitCode=$?
35+
if [ $exitCode -ne 0 ]
36+
then
37+
echo "One or more tests have failed; this build should eventually fail"
38+
echo "failures=true" >> "$GITHUB_OUTPUT"
39+
fi
40+
done
41+
- name: Run Client script tests with coverage
42+
id: js_tests
43+
shell: bash {0}
44+
working-directory: CSF.Screenplay.JsonToHtmlReport.Template/src
45+
run: |
46+
npm test
47+
exitCode=$?
48+
if [ $exitCode -ne 0 ]
49+
then
50+
echo "One or more tests have failed; this build should eventually fail"
51+
echo "failures=true" >> "$GITHUB_OUTPUT"
52+
fi
53+
- name: Emit output
54+
id: emit_output
55+
run: |
56+
if [ ${{ steps.dotnet_tests.outputs.failures }} -eq 'true' -o ${{ steps.js_tests.outputs.failures }} -eq 'true' ]
57+
then
58+
echo "failures=true" >> "$GITHUB_OUTPUT"
59+
else
60+
echo "failures=false" >> "$GITHUB_OUTPUT"
61+
fi
62+
shell: bash
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: 'Setup build dependencies'
2+
description: 'Installs and configures mandatory dependencies to build CSF.Screenplay'
3+
inputs:
4+
dotnet-version:
5+
description: 'The version of the .NET SDK to install'
6+
default: '8.0.x'
7+
8+
runs:
9+
using: 'composite'
10+
steps:
11+
- name: Add .NET global tools location to PATH
12+
run: echo "$HOME/.dotnet/tools" >> "$GITHUB_PATH"
13+
shell: bash
14+
- name: Install .NET
15+
uses: actions/setup-dotnet@v5
16+
with:
17+
dotnet-version: ${{ inputs.dotnet-version }}
18+
- name: Install DocFX
19+
run: dotnet tool install --global docfx
20+
shell: bash
21+
- name: Install Node.js for building JSON-to-HTML report converter
22+
uses: actions/setup-node@v6.2.0
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: 'Setup test dependencies'
2+
description: 'Installs and configures additional dependencies to thoroughly test CSF.Screenplay'
3+
inputs:
4+
java-version:
5+
description: 'The version of Java to install'
6+
default: 21
7+
java-dist:
8+
description: 'The distribution of Java to install'
9+
default: 'zulu'
10+
x-display:
11+
description: 'The XServer display to configure for web browsers'
12+
default: ':99'
13+
x-resolution:
14+
description: 'The XServer screen resolution `widthxheight` for web browsers'
15+
default: '1280x1024'
16+
17+
runs:
18+
using: 'composite'
19+
steps:
20+
# Installation
21+
- name: Install SonarScanner
22+
run: dotnet tool install --global dotnet-sonarscanner
23+
shell: bash
24+
- name: Install Coverlet console
25+
run: dotnet tool install --global coverlet.console
26+
shell: bash
27+
- name: Install Java JDK for SonarScanner
28+
uses: actions/setup-java@v5.1.0
29+
with:
30+
java-version: ${{ inputs.java-version }}
31+
distribution: ${{ inputs.java-dist }}
32+
33+
# Prepare to run Chrome
34+
# See https://chromium.googlesource.com/chromium/src/+/main/docs/security/apparmor-userns-restrictions.md
35+
- name: Disable AppArmor restrictions so Chrome may run
36+
run: echo 0 | sudo tee /proc/sys/kernel/apparmor_restrict_unprivileged_userns
37+
shell: bash
38+
- name: Start an Xvfb display so Chrome may run
39+
run: Xvfb -ac ${{ inputs.x-display }} -screen 0 ${{ inputs.x-resolution }}x16 &
40+
shell: bash
41+
42+
# Prime Selenium manager with initial config
43+
- name: Setup Selenium Manager config
44+
run: |
45+
mkdir ~/.cache/selenium
46+
cp Tools/se-config.toml ~/.cache/selenium
47+
shell: bash
48+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: 'Start SonarScanner'
2+
description: 'Starts up SonarScanner, to analyse a build & test run'
3+
inputs:
4+
project:
5+
description: 'The SonarQube project name'
6+
required: true
7+
build-version:
8+
description: 'The build version string to pass to SonarQube'
9+
required: true
10+
username:
11+
description: 'The SonarQube login username'
12+
required: true
13+
secret-key:
14+
description: 'The SonarQube secret key'
15+
required: true
16+
sonar-cloud-url:
17+
description: 'The SonarCloud URL'
18+
default: 'https://sonarcloud.io'
19+
js-coverage-path:
20+
description: 'The file system path at which to find the JS lcov report'
21+
required: true
22+
analysis-properties-path:
23+
description: 'The file system path at which to find the SonarQube analysis properties file'
24+
default: '.sonarqube-analysisproperties.xml'
25+
26+
27+
runs:
28+
using: 'composite'
29+
steps:
30+
- name: Start SonarScanner
31+
env:
32+
BranchName: ${{ github.event_name == 'pull_request' && github.base_ref || github.ref_name }}
33+
BranchParam: ${{ github.event_name == 'pull_request' && 'sonar.pullrequest.branch' || 'sonar.branch.name' }}
34+
PullRequestParam: ${{ github.event_name == 'pull_request' && format('/d:sonar.pullrequest.key={0}', github.event.number) || '' }}
35+
shell: bash
36+
run: >
37+
dotnet sonarscanner begin
38+
/k:${{ inputs.project }}
39+
/v:${{ inputs.build-version }}
40+
/o:${{ inputs.username }}
41+
/d:sonar.host.url=${{ inputs.sonar-cloud-url }}
42+
/d:sonar.token=${{ inputs.secret-key }}
43+
/d:${{ env.BranchParam }}=${{ env.BranchName }} ${{ env.PullRequestParam }}
44+
/d:sonar.javascript.lcov.reportPaths=$PWD/${{ inputs.js-coverage-path }}
45+
/s:$PWD/${{ inputs.analysis-properties-path }}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: 'Upload CI artifacts'
2+
description: 'Uploads artifacts from a CI run (full build and test), following a full test run'
3+
inputs:
4+
configuration:
5+
description: 'The .NET configuration'
6+
default: 'Debug'
7+
tfm:
8+
description: 'The .NET Target Framework Moniker'
9+
required: true
10+
11+
runs:
12+
using: 'composite'
13+
steps:
14+
- name: Upload .NET test results artifacts
15+
uses: actions/upload-artifact@v7
16+
with:
17+
name: NUnit test results
18+
path: Tests/*.Tests/**/TestResults.xml
19+
- name: Upload verbose webdriver log artifacts
20+
# This step is only relevant if the ChromeDriver with verbose logging is selected, such as via
21+
# appsettings.json in CSF.Screenplay.Selenium.Tests.
22+
# If verbose logs aren't created then this step is skipped to avoid a build warning about missing artifacts.
23+
if: ${{ hashFiles('**/chrome-verbose-log.txt') != '' }}
24+
uses: actions/upload-artifact@v7
25+
with:
26+
name: Verbose webdriver logs
27+
path: '**/chrome-verbose-log.txt'
28+
- name: Upload JS test results artifacts
29+
uses: actions/upload-artifact@v7
30+
with:
31+
name: Client script test results
32+
path: CSF.Screenplay.JsonToHtmlReport.Template/src/TestResults/**/*
33+
- name: Upload Screenplay JSON report artifact
34+
uses: actions/upload-artifact@v7
35+
with:
36+
name: Screenplay JSON reports
37+
path: Tests/**/ScreenplayReport.json
38+
- name: Convert Screenplay reports to HTML
39+
continue-on-error: true
40+
run: |
41+
for report in $(find Tests/ -type f -name "ScreenplayReport.json")
42+
do
43+
reportDir=$(dirname "$report")
44+
outputFile="$reportDir/ScreenplayReport.html"
45+
dotnet run --no-build --framework ${{ inputs.tfm }} -c ${{ inputs.configuration }} --project CSF.Screenplay.JsonToHtmlReport --ReportPath "$report" --OutputPath "$outputFile"
46+
done
47+
shell: bash
48+
- name: Upload Screenplay HTML report artifact
49+
uses: actions/upload-artifact@v7
50+
with:
51+
name: Screenplay HTML reports
52+
path: Tests/**/ScreenplayReport.html

.github/workflows/crossBrowserTesting.yml

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ concurrency:
55
cancel-in-progress: false
66

77
on:
8-
push:
9-
branches: [ "master" ]
10-
pull_request:
11-
branches: [ "master" ]
8+
workflow_run:
9+
workflows: [.NET CI]
10+
types: [completed]
1211
schedule:
1312
- cron: "27 20 * * 0"
1413

@@ -61,6 +60,7 @@ jobs:
6160
name: Run tests
6261
runs-on: ubuntu-24.04
6362
timeout-minutes: 30
63+
if: ${{ github.event_name == 'schedule' || github.event.workflow_run.conclusion == 'success' }}
6464

6565
env:
6666
RunNumber: ${{ github.run_number }}.${{ github.run_attempt }}
@@ -82,27 +82,13 @@ jobs:
8282
steps:
8383
- name: Checkout
8484
uses: actions/checkout@v6
85-
86-
# Install build dependencies
87-
88-
- name: Install .NET
89-
uses: actions/setup-dotnet@v5
9085
with:
91-
dotnet-version: ${{ env.DotnetVersion }}
92-
- name: Install Node.js for building JSON-to-HTML report converter
93-
uses: actions/setup-node@v6.2.0
94-
95-
# Environment setup pre-build
96-
97-
- name: Restore .NET packages
98-
run: dotnet restore
99-
- name: Restore Node modules
100-
run: |
101-
cd CSF.Screenplay.JsonToHtmlReport.Template/src
102-
npm ci
103-
cd ../..
104-
105-
# Build and test the solution
86+
fetch-depth: 0
87+
lfs: true
88+
- name: Setup build dependencies
89+
uses: ./.github/actions/setup-build-dependencies
90+
- name: Restore third party libs
91+
uses: ./.github/actions/restore-dependencies
10692

10793
- name: Build the solution
10894
run: dotnet build -c ${{ env.Configuration }}

0 commit comments

Comments
 (0)