1111 buildAndRunBasicTests :
1212 runs-on : ubuntu-slim
1313
14- # env:
15- # TODO: put env vars here
14+ env :
15+ RunNumber : ${{ github.run_number }}.${{ github.run_attempt }}
16+ SonarCloudProject : csf-dev_CSF.Screenplay
17+ SonarCloudUsername : craigfowler-github
18+ SonarCloudUrl : https://sonarcloud.io
19+ Configuration : Debug
20+ Tfm : net8.0
21+ DotnetVersion : 8.0.x
22+ SonarCloudSecretKey : ${{ secrets.SONARCLOUDKEY }}
1623
1724 steps :
1825 - name : Checkout
2330 - name : Install .NET Core
2431 uses : actions/setup-dotnet@v4
2532 with :
26- dotnet-version : 8.0.x
33+ dotnet-version : ${{ env.DotnetVersion }}
2734 - name : Setup Node.js for building JSON-to-HTML report converter
2835 uses : actions/setup-node@v6.2.0
2936 - name : Setup Java JDK for SonarScanner
@@ -39,75 +46,97 @@ jobs:
3946 run : dotnet tool install --global dotnet-sonarscanner
4047 - name : Setup Coverlet console
4148 run : dotnet tool install --global coverlet.console
42-
43- # Start SonarScanner
44-
45- # Build
49+ - name : Setup SonarScanner for pull request processing
50+ if : ${{ github.event_name == 'pull_request' }}
51+ env :
52+ BranchName : ${{ github.base_ref }}
53+ BranchParam : sonar.pullrequest.branch
54+ PullRequestParam : /d:sonar.pullrequest.key=${{ github.event.number }}
55+ - name : Setup SonarScanner for normal branch processing
56+ if : ${{ github.event_name != 'pull_request' }}
57+ env :
58+ BranchName : ${{ github.ref_name }}
59+ BranchParam : sonar.branch.name
60+ PullRequestParam :
61+ - name : Setup Selenium Manager config
62+ run : |
63+ mkdir ~/.cache/selenium
64+ cp Tools/se-config.toml ~/.cache/selenium
65+ - name : Setup an Xvfb display so Chrome may run
66+ run : |
67+ Xvfb -ac :99 -screen 0 1280x1024x16 &
68+ export DISPLAY=:99
69+
70+ # Build and test the solution
71+
72+ - name : Restore .NET packages
73+ run : dotnet restore -c ${{ env.Configuration }}
74+ - name : Start SonarScanner
75+ run : >
76+ dotnet-sonarscanner begin
77+ /k:${{ env.SonarCloudProject }}
78+ /v:GitHub_build_${{ env.RunNumber }}
79+ /o:${{ env.SonarCloudUsername }}
80+ /d:sonar.host.url=${{ env.SonarCloudUrl }}
81+ /d:sonar.token=${{ env.SonarCloudSecretKey }}
82+ /d:${{ env.BranchParam }}=${{ env.BranchName }}
83+ ${{ env.PullRequestParam }}
84+ /d:sonar.javascript.lcov.reportPaths=CSF.Screenplay.JsonToHtmlReport.Template/src/TestResults/lcov.info
85+ /s:.sonarqube-analysisproperties.xml
4686 - name : Build the solution
47- run : dotnet build --no-incremental
48-
49- # Test .NET (with coverage)
50-
51- # Test JavaScript (with coverage)
52-
53- # Stop SonarScanner
54-
55- # Upload test results artifact
56-
57- # Convert Screenplay reports to HTML and upload artifacts
58-
59- # Upload build-results artifacts
87+ run : dotnet build -c ${{ env.Configuration }} --no-incremental
88+ - name : Run .NET tests with coverage
89+ run : |
90+ AnyFailures=0
91+ for proj in Tests/*.Tests
92+ do
93+ projNameArray=(${proj//// })
94+ projName=${projNameArray[1]}
95+ assemblyPath=$proj/bin/$Configuration/$Tfm/$projName.dll
96+ coverlet "$assemblyPath" --target "dotnet" --targetargs "test $proj --no-build --logger:nunit --test-adapter-path:." -f=opencover -o="TestResults/$projName.opencover.xml"
97+ if [ $? -ne 0 ]
98+ then
99+ AnyFailures=1
100+ fi
101+ done
102+ export AnyFailures
103+ - name : Run JavaScript tests with coverage
104+ run : |
105+ cd CSF.Screenplay.JsonToHtmlReport.Template/src
106+ npm test
107+ if [ $? -ne 0 ]
108+ then
109+ export AnyFailures=1
110+ fi
111+ cd ../..
112+ - name : Stop SonarScanner
113+ run :
114+ dotnet-sonarscanner end /d:sonar.token=${{ env.SonarCloudSecretKey }}
115+ - name : Upload test results artifacts
116+ uses : actions/upload-artifact@v4
117+ with :
118+ name : NUnit test results
119+ path : Tests/*.Tests/**/TestResults.xml
120+ - name : Upload Screenplay JSON report artifact
121+ uses : actions/upload-artifact@v4
122+ with :
123+ name : Screenplay JSON reports
124+ path : Tests/**/ScreenplayReport_*.json
125+ - name : Fail the build if any test failures
126+ run : |
127+ if [ $AnyFailures -ne 0 ]
128+ then
129+ echo "Failing the build due to test failures"
130+ exit 1
131+ fi
132+
133+ # TODO: Convert Screenplay reports to HTML and upload as an artifact
60134
61- buildDocs :
135+ # buildDocs:
62136 # TODO: Build the docco site and package the result as an artifact, don't publish it
63137
64- publishDocs :
138+ # publishDocs:
65139 # TODO: Take the docco site artifact and publish it to master
66140
67- runBrowserTests :
141+ # runBrowserTests:
68142 # TODO: Use build-results artifacts and run tests on matrix of browsers
69-
70-
71-
72-
73-
74-
75-
76-
77-
78-
79- # - name: Execute unit tests
80- # run: dotnet test
81-
82- # # Restore the application to populate the obj folder with RuntimeIdentifiers
83- # - name: Restore the application
84- # run: msbuild $env:Solution_Name /t:Restore /p:Configuration=$env:Configuration
85- # env:
86- # Configuration: ${{ matrix.configuration }}
87-
88- # # Decode the base 64 encoded pfx and save the Signing_Certificate
89- # - name: Decode the pfx
90- # run: |
91- # $pfx_cert_byte = [System.Convert]::FromBase64String("${{ secrets.Base64_Encoded_Pfx }}")
92- # $certificatePath = Join-Path -Path $env:Wap_Project_Directory -ChildPath GitHubActionsWorkflow.pfx
93- # [IO.File]::WriteAllBytes("$certificatePath", $pfx_cert_byte)
94-
95- # # Create the app package by building and packaging the Windows Application Packaging project
96- # - name: Create the app package
97- # run: msbuild $env:Wap_Project_Path /p:Configuration=$env:Configuration /p:UapAppxPackageBuildMode=$env:Appx_Package_Build_Mode /p:AppxBundle=$env:Appx_Bundle /p:PackageCertificateKeyFile=GitHubActionsWorkflow.pfx /p:PackageCertificatePassword=${{ secrets.Pfx_Key }}
98- # env:
99- # Appx_Bundle: Always
100- # Appx_Bundle_Platforms: x86|x64
101- # Appx_Package_Build_Mode: StoreUpload
102- # Configuration: ${{ matrix.configuration }}
103-
104- # # Remove the pfx
105- # - name: Remove the pfx
106- # run: Remove-Item -path $env:Wap_Project_Directory\GitHubActionsWorkflow.pfx
107-
108- # # Upload the MSIX package: https://github.com/marketplace/actions/upload-a-build-artifact
109- # - name: Upload build artifacts
110- # uses: actions/upload-artifact@v4
111- # with:
112- # name: MSIX Package
113- # path: ${{ env.Wap_Project_Directory }}\AppPackages
0 commit comments