00 · The starting point
Every later step changes one small repository. Get its starting files into a repository of your own, and see what it holds before Redline arrives.
You will learn
- What the demo service is, and what its CI checks before Redline
- How to get the starter files: downloaded, or built by hand file by file
- How to put them in a GitHub repository of your own
Before you start
- git
- Node 18.11 or later
- pnpm. If you build the files by hand, npm, yarn or bun work too.
- A GitHub account, and the GitHub CLI signed in with
gh auth login
Get the starter files
Step 00 is a small TypeScript service with two tests and a CI workflow, and nothing from Redline yet. Download it in one go, or build it yourself file by file and see what each piece is for.
Open step 00 on GitHubDownload .zip
step-00 is a tag, not a branch. Searching the branch list on GitHub finds nothing; open the Tags tab in the same menu, or use the link above.
Or, in an empty folder, unpack it straight into a repository of your own. Skip git init if you have already run it. git branch -M main names the branch main, whatever git called it: every later step, and the rules Redline puts on the branch, use that name.
$ git init $ curl -L https://github.com/moelzanaty3/redline-demo/archive/refs/tags/step-00.tar.gz | tar -xz --strip-components=1 $ git add -A $ git commit -m "chore: start from the Redline demo, step 00" $ git branch -M main $ pnpm install $ pnpm test ℹ pass 2 ℹ fail 0
That copies the files, not the demo's history: the repository is yours alone, with nothing connecting it to the demo. The download comes set up for pnpm; to use another package manager, build it by hand.
Where a command depends on your package manager, pick yours; every switcher on the page follows. Every later step uses pnpm, so with another one, swap the command: pnpm add is npm install, yarn add or bun add, and pnpm test is npm test, yarn test or bun run test.
1. A project that uses TypeScript
In an empty folder, start a git repository and a package, then add the TypeScript compiler and Node's type definitions. The versions match the demo, so your output matches the lessons.
$ git init $ pnpm init $ pnpm add -D typescript@5 @types/node@22
pnpm init writes package.json, already marked "type": "module" so the code uses import and export.
$ git init $ npm init -y $ npm install -D typescript@5 @types/node@22
npm init -y writes package.json with every default accepted.
$ git init $ yarn init -y $ yarn add -D typescript@5 @types/node@22
yarn init -y writes package.json, and a .gitignore you will add to in part 4 below.
$ git init $ bun add -d typescript@5 @types/node@22
bun add writes package.json when there is none. Skip bun init: it adds a starter project you don't need here.
2. Scripts to build and test
$ pnpm pkg set scripts.build=tsc "scripts.test=tsc && node --test dist/*.test.js"
$ npm pkg set type=module scripts.build=tsc "scripts.test=tsc && node --test dist/*.test.js"
$ npm pkg set type=module scripts.build=tsc "scripts.test=tsc && node --test dist/*.test.js"
npm pkg only edits package.json; npm comes with Node, so it is already there.
$ npm pkg set name=redline-demo type=module scripts.build=tsc "scripts.test=tsc && node --test dist/*.test.js"
npm pkg only edits package.json; npm comes with Node, so it is already there.
The test script compiles src/ into dist/, then runs every compiled test file with the test runner built into Node. No test framework to install.
3. Tell the compiler how strict to be
{
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"strict": true,
"noUncheckedIndexedAccess": true,
"rootDir": "src",
"outDir": "dist",
"types": ["node"]
},
"include": ["src"]
}
strict turns on every standard check. noUncheckedIndexedAccess goes further: reading list[0] gives a value that may be undefined, and the compiler makes you check. Redline's rules assume both are on.
4. Keep build output out of git
Create .gitignore, or add these lines if your package manager already made one:
node_modules/
dist/
5. The service
export type User = { id: string; name: string; email: string }
export class UserDirectory {
private readonly users = new Map<string, User>()
add(user: User): void {
if (this.users.has(user.id)) throw new Error(`user ${user.id} already exists`)
this.users.set(user.id, user)
}
find(id: string): User | undefined {
return this.users.get(id)
}
count(): number {
return this.users.size
}
}
A user directory that adds users and finds them by id, and refuses the same id twice. Small on purpose: later steps add code to it, and Redline reviews that code.
6. Its tests
import { test } from 'node:test'
import assert from 'node:assert/strict'
import { UserDirectory } from './users.js'
test('a user that was added can be found', () => {
const directory = new UserDirectory()
directory.add({ id: 'u1', name: 'Ada', email: '[email protected]' })
assert.equal(directory.find('u1')?.name, 'Ada')
})
test('the same id cannot be added twice', () => {
const directory = new UserDirectory()
directory.add({ id: 'u1', name: 'Ada', email: '[email protected]' })
assert.throws(() => directory.add({ id: 'u1', name: 'Grace', email: '[email protected]' }))
})
The import says ./users.js, not .ts: the test runs after compiling, when the file next to it is JavaScript.
$ pnpm test ℹ pass 2 ℹ fail 0
$ npm test ℹ pass 2 ℹ fail 0
$ yarn test ℹ pass 2 ℹ fail 0
$ bun run test ℹ pass 2 ℹ fail 0
7. CI that runs the tests on GitHub
name: CI
on:
push:
branches: [main]
pull_request:
permissions:
contents: read
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm
- run: pnpm install --frozen-lockfile
- run: pnpm test
name: CI
on:
push:
branches: [main]
pull_request:
permissions:
contents: read
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- run: npm ci
- run: npm test
name: CI
on:
push:
branches: [main]
pull_request:
permissions:
contents: read
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: corepack enable
- uses: actions/setup-node@v4
with:
node-version: 22
cache: yarn
- run: yarn install --immutable
- run: yarn test
name: CI
on:
push:
branches: [main]
pull_request:
permissions:
contents: read
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
- uses: actions/setup-node@v4
with:
node-version: 22
- run: bun install --frozen-lockfile
- run: bun run test
On every push to main and every pull request, GitHub installs the exact versions in your lockfile and runs the tests. It only runs once the repository is on GitHub, which is the next thing you do.
8. Commit
$ git add -A $ git commit -m "chore: a TypeScript service with tests and CI" $ git branch -M main
git branch -M main names the branch main, whatever git called it: every later step, and the rules Redline puts on the branch, use that name. The repository is yours alone: nothing connects it to the demo. When a later step needs one of the demo's larger files, like a 249-country table, it downloads that file directly.
pnpm: command not found? Install it with npm install -g pnpm.
You don't install Redline yet. Step 01 runs it once, and it adds itself to your project as a pinned dev dependency, so everyone on the repository runs the same version.
Put your repository on GitHub
The checks Redline adds run on pull requests, so your repository needs to be on GitHub. From its root:
$ gh repo create my-redline-demo --public --source . --remote origin --push
That creates a new public repository under your own account and pushes your main to it. Everything from here on happens there; the demo is only ever read from.
Why public: GitHub gives a public repository dependency review and secret scanning for free, and the gate uses both from step 01 on.
To check it worked, open the repository in your browser and look at its Actions tab. The CI workflow ran on the push to main, and it is green:
$ gh repo view --web
Private repository Must it be public?
No, and most real repositories are private. On a private repository, dependency review and secret scanning are part of GitHub Advanced Security, which an organisation buys on a Team or Enterprise plan. Without it, the gate's dependency review goes red on your first pull request. Step 01 shows what that looks like and the two ways to answer it, and steps 06 and 07 say what changes for you. For this path, public is simpler: you can switch it to private, or delete it, when you are done.
Already created the repository on GitHub? Skip the command above. Check git remote -v lists it as origin (if not, git remote add origin <its url>), then git push -u origin main. If GitHub added a README or licence when you created it, the push is refused; create it again empty.
What is in the repository
A small user directory, the kind of service a team writes in its first week:
| Path | What it is |
|---|---|
| src/users.ts | A UserDirectory that adds and finds users |
| src/users.test.ts | Two tests, using Node's built-in test runner |
| tsconfig.json | Strict TypeScript, including noUncheckedIndexedAccess |
| .github/workflows/ci.yml | Installs the dependencies, compiles and runs the tests on every push and pull request |
What nothing checks yet
CI compiles the code and runs the tests, and that is all. Nothing checks how the code is written: a @ts-ignore, a hardcoded token or a dependency with a known vulnerability would all pass, as long as the tests do. And nothing tells a coding assistant what this team expects, so it guesses. Step 01 fixes both with one command.
Check your understanding
In step 00, a pull request adds // @ts-ignore above a line that does not compile. What happens?