diff --git a/.github/workflows/isolated-tests.yml b/.github/workflows/isolated-tests.yml new file mode 100644 index 00000000000..a26b0ecd26c --- /dev/null +++ b/.github/workflows/isolated-tests.yml @@ -0,0 +1,101 @@ +# Github Action to build and run tests, but in more isolation + +name: Isolated tests +permissions: {} + +on: + push: + branches: [develop, master, sf-qa, sf-live] + pull_request: + merge_group: + workflow_dispatch: + +jobs: + build-development: + name: "Isolated tests" + strategy: + matrix: + # Environments in which to run, such as those used in development and production, or which are candidates to + # move to. + os: ["ubuntu-22.04"] + dotnet_version: ["8.0.x"] + node_version: ["22.13.0"] + npm_version: ["10.9.2"] + # Continue building in other environments to see which are working. + fail-fast: false + runs-on: ${{matrix.os}} + steps: + - name: Checkout + uses: actions/checkout@v5 + with: + persist-credentials: false + + - name: "Deps: .NET" + uses: actions/setup-dotnet@v5 + with: + dotnet-version: ${{matrix.dotnet_version}} + cache: true + cache-dependency-path: src/SIL.XForge.Scripture/packages.lock.json + - name: "Deps: Node" + uses: actions/setup-node@v4 + with: + node-version: ${{matrix.node_version}} + cache: "npm" + cache-dependency-path: | + src/SIL.XForge.Scripture/ClientApp/package-lock.json + src/RealtimeServer/package-lock.json + - name: "Deps: npm" + env: + NPM_VERSION: ${{matrix.npm_version}} + run: | + set -xueo pipefail + npm install --global npm@${NPM_VERSION} + - name: Pre-build report + run: | + set -xueo pipefail + lsb_release -a + which dotnet + dotnet --version + dotnet --list-sdks + dotnet --list-runtimes + which node + node --version + which npm + npm --version + which chromium-browser + chromium-browser --version + - name: "Ensure desired tool versions" + # The build machine may come with newer tools than we are ready for. + env: + NODE_VERSION: ${{matrix.node_version}} + NPM_VERSION: ${{matrix.npm_version}} + run: | + set -xueo pipefail + [[ $(node --version) == v${NODE_VERSION} ]] + [[ $(npm --version) == ${NPM_VERSION} ]] + + - name: "Deps: reportgenerator tool" + run: dotnet tool install --global dotnet-reportgenerator-globaltool + - name: "Deps: RealtimeServer npm" + run: cd src/RealtimeServer && (npm ci || (sleep 3m && npm ci)) + - name: "Deps: Backend nuget" + run: dotnet restore + - name: "Deps: Frontend npm" + run: cd src/SIL.XForge.Scripture/ClientApp && (npm ci || (sleep 3m && npm ci)) + + - name: "Build: Backend, RealtimeServer" + run: dotnet build xForge.sln + - name: "Build: Frontend" + run: cd src/SIL.XForge.Scripture/ClientApp && npm run build + + - name: "Test: Ensure tests not focused on a subset" + # grep returns code 123 when no matches are found. The operator ! negates the exit code. + run: | + ! git ls-files | grep "\\.spec\\.ts" | xargs grep -P "^\s*(fdescribe|fit)\(" + # Run the tests while making sure none of the common/known warnings are printed + - name: "Test: Frontend" + run: | + set -euo pipefail + cd src/SIL.XForge.Scripture/ClientApp + find src -name \*.spec.ts -exec npm run test:gha -- --include {} \; |& tee test_output.log + ! grep --perl-regex 'NG\d+|ERROR:|WARN:|LOG:|INFO:' test_output.log