English
Checkpoint
What must work
powershell
./Run.ps1 checkpowershell
git status --shortCompare the workflow with the reference:
powershell
git diff --no-index .github/workflows/ci.yml D:\Work\Chatex-Reference\.github\workflows\ci.ymlThe command prints nothing.
Common mistakes
Table 22.2. Common mistakes with continuous integration
| Symptom | Cause | Fix |
|---|---|---|
a push to main starts no run | ci.yml runs only on pull requests and pushes to dev | work on dev and merge into main through a pull request |
| the Actions tab says the workflow file is invalid | a tab character or a wrong indentation in the YAML | indent with spaces only, compare with the listing |
error WHITESPACE: Fix whitespace formatting. at Check formatting | the code was not formatted before the commit | ./Run.ps1 format, commit, push |
Changes have been made to the model since the last migration. Add a new migration. | an entity or a configuration changed without a migration | ./Run.ps1 migration <Name>, check the generated migration, commit it |
npm ci can only install packages when your package.json and package-lock.json are in sync | a package was added to package.json by hand, or the lock file was not committed | run npm install in Source/Chatex.Web and commit package-lock.json |
the backend tests fail locally with Docker is either not running or misconfigured | Docker Desktop is not started | start Docker; on the runner Docker is always available |
the restore or build fails with NU1901–NU1904 without any code change | NuGet audit found a new advisory for a package version in use | update that package in Directory.Packages.props on a branch and let CI check it |
| Backend and Frontend cannot be selected in the ruleset | the checks have never run in this repository | push to dev once, then edit the ruleset |
Self-check questions
- What problem does continuous integration solve that "everybody runs the tests before pushing" does not?
- Explain workflow, job, step, runner and action with the example of
ci.yml. - Which three events start
ci.yml, and why is a push tomainnot among them? - Why does the workflow declare
permissions: contents: read? - What does the concurrency group of
ci.ymlachieve, and why does a call fromdeploy.ymlnever collide with an ordinary run? - Why does the backend job build in Release, and why do the later steps use
--no-restoreand--no-build? - How does
has-pending-model-changesdetect a missing migration without a database? - How do the backend tests get a PostgreSQL on the runner, and why was a service container in the workflow not chosen?
- Why
npm ciinstead ofnpm installin CI? What does--omit=devchange in the audit? - Which checks can turn the build red without any change in our code, and why is that desirable?
- Why must
./Run.ps1 checkandci.ymlcontain the same steps? What happens when they drift apart? - What does a ruleset on
mainadd to a workflow that already reports red and green?
Exercises
- Updating a package with CI. On a branch from
dev, raise the version of one test package (for exampleShouldly) inDirectory.Packages.props, run./Run.ps1 check, push the branch and open a pull request intodev. Read the run, then decide whether to merge or close it. This is how dependencies are updated safely; the tutorial itself keeps the pinned versions. - A test report. Find out how the Microsoft Testing Platform writes a TRX report, make the
Teststep produce one, and break a test on a throwaway branch: the run must offer the artifacttest-resultswith the report. - Pin the actions. Replace each
uses: owner/name@vNwith the full commit hash of that tag and a comment with the tag. What do you gain, and what extra work does it cost when an action is updated? - A scheduled audit. Advisories appear between pushes. Add a second trigger,
schedule:with a weekly cron expression, so CI also runs once a week. On which branch does a scheduled run check out the code, and is that the branch you want to audit?