Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 43 additions & 3 deletions .github/workflows/library-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ on:
required: false
type: boolean
default: false
tests:
description: >-
Run the repository's bulk `test` command (`rush test --verbose`) after the
build. Off by default: every library that had a bulk `test` when this was
added (actions, ai, i18n, kb, mind, flows, …) already runs it in a `test` job
of its own, several against a Postgres or Neo4j service this job does not
start, so turning it on for them would run their suites twice, or without
their database. On, with no bulk `test` in command-line.json, the step says
so and skips.
required: false
type: boolean
default: false
pr-gate:
description: >-
The PR gate (pr-gate/, PR-GATE.md): a draft runs nothing, and only the top PR
Expand Down Expand Up @@ -210,11 +222,39 @@ jobs:
- name: Build packages
run: node ./common/scripts/install-run-rush.js rebuild --verbose

# Always present, so a caller's enabled steps stay those of the file it replaced
# (scripts/verify-callers.mjs); `tests` decides inside. Over every project, as the
# build above is: this job's gate selects no projects, so there is no impacted set.
- name: Run tests (when available)
env:
BE_TESTS: ${{ inputs.tests }}
run: |
# Add this when you have tests
# node ./common/scripts/install-run-rush.js test --verbose
echo "Tests will be added in the future"
if [ "$BE_TESTS" != "true" ]; then
echo "Tests are off for this repository (library-ci.yml's \`tests\` input); its own workflow runs them, or none does."
exit 0
fi

# Is there a bulk `test` command? command-line.json is JSONC, read as the version
# policy check below reads rush.json.
TEST_KIND=$(node -e "
const fs = require('fs');
const file = 'common/config/rush/command-line.json';
if (!fs.existsSync(file)) { console.log('none'); process.exit(0); }
const keepStrings = (match) => (match[0] === '\x22' ? match : '');
const text = fs.readFileSync(file, 'utf8')
.replace(/\x22(?:[^\x22\x5c]|\x5c.)*\x22|\/\/[^\n]*|\/\*[\s\S]*?\*\//g, keepStrings)
.replace(/\x22(?:[^\x22\x5c]|\x5c.)*\x22|,(?=\s*[}\]])/g, keepStrings);
const test = (JSON.parse(text).commands || []).find((c) => c.name === 'test');
console.log(test ? test.commandKind : 'none');
")

if [ "$TEST_KIND" != "bulk" ]; then
echo "::notice title=No tests run::\`tests: true\`, but common/config/rush/command-line.json defines no bulk \`test\` command (found: $TEST_KIND). Add one, with a \`test\` script in each project that has tests."
echo "⚠️ \`tests: true\`, but there is no bulk \`test\` command in \`common/config/rush/command-line.json\`: no tests ran." >> $GITHUB_STEP_SUMMARY
exit 0
fi

node ./common/scripts/install-run-rush.js test --verbose

- name: Check bundle size
if: inputs.bundle-size-check
Expand Down
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,34 @@ nothing: a repository states what it already did. `scripts/verify-callers.mjs`
checked that, resolving each caller against the shared workflow and comparing the
enabled steps to the file it replaced.

#### Tests in library-ci

`library-ci.yml` builds every project (`rush rebuild`) and, with **`tests: true`**
(since v2.18.0), runs the repository's bulk `test` command after it:
`rush test --verbose`, over every project, as the build is (the job's PR gate
selects no projects, so there is no impacted set to narrow to). A repository whose
`common/config/rush/command-line.json` has no bulk `test` command gets a notice
and a line in the job summary saying no tests ran, and the step passes. Until
v2.18.0 the step only echoed "Tests will be added in the future", so a library
without a `test` job of its own ran its tests on developers' machines only.

It is off by default, because the libraries that already had a bulk `test` run it
in a `test` job of their own (actions, ai, i18n, kb, mind, flows, workbench, …),
several against a Postgres or Neo4j service that this job does not start. Turn it
on in a library that has no such job:

```yaml
uses: beplus/setup-beplus/.github/workflows/library-ci.yml@v2
with:
packages: |
packages/core/api-core
tests: true
```

A project without a `test` script is skipped only if the command says
`"ignoreMissingScript": true`; give a project that needs tools the runner lacks
(the Smithy CLI, say) no `test` script, or a separate one.

#### One version per commit, built once, promoted

A library publishes the way cli_v2 releases the CLI. A version is cut once, on dev,
Expand Down