Skip to content

Commit

Permalink
Refine tasks and simplify TypeScript CI (#1018)
Browse files Browse the repository at this point in the history
* Replace `cargo-make` with `deno task` and `dax`
* Directly use esbuild CLI via Nix instead of npm/pnpm package manager installation
  This way is not recommended in esbuild official docs, however will be good for this repository
* Takeover TypeScript CI by Nix
  This is a trade-off problem. Inlined `setup-*` actions made `10~20sec` for each jobs, on the other hand, using Nix CI made `50~60sec` in 1 job
  I prefer to keep simple implementation in this time.
* Optimize the slow Nix CI with dropping external flake and magic-nix-cache-action
  • Loading branch information
kachick authored Jan 29, 2025
1 parent a4da3b8 commit 1d0d271
Show file tree
Hide file tree
Showing 23 changed files with 257 additions and 555 deletions.
38 changes: 0 additions & 38 deletions .github/workflows/ci-nix.yml

This file was deleted.

83 changes: 42 additions & 41 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,59 +1,60 @@
name: TypeScript
name: CI
on:
push:
branches: [main]
paths-ignore:
- '.github/workflows/ci-nix.yml'
- 'LICENSE'
- '.github/dependabot.yml'
- '.editorconfig'
- 'README.md'
- '**.md'
- '.vscode/**'
pull_request:
paths-ignore:
- '.github/dependabot.yml'
- 'LICENSE'
- '.editorconfig'
- 'README.md'
- '**.md'
- '.vscode/**'
jobs:
build:
timeout-minutes: 15
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
- uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0
- uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
with:
node-version-file: '.node-version'
cache: pnpm
- run: pnpm install --frozen-lockfile
- run: pnpm run build
- name: Check no diff for products
run: git add --intent-to-add . && git diff --exit-code
schedule:
# Every 10:42 JST
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#schedule
- cron: '42 1 * * *'
workflow_dispatch:

test:
jobs:
all:
timeout-minutes: 15
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
- uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0
- uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
- uses: DeterminateSystems/nix-installer-action@e50d5f73bfe71c2dd0aa4218de8f4afa59f8f81d # v16
- run: nix develop --command echo 'This step should be done before any other "nix develop" steps because of measuring Nix build time'
# See https://github.com/actions/setup-node/blob/802632921f8532d2409ae6eac3313b6f81f11122/src/cache-utils.ts#L30-L38
- name: Get pnpm store path
id: get-pnpm-path
run: |
echo "pnpm-store-path=$(nix develop --command pnpm store path --silent)" | tee -a "$GITHUB_OUTPUT"
- uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
name: Cache pnpm store
with:
node-version-file: '.node-version'
cache: pnpm
- run: pnpm install --frozen-lockfile
- run: pnpm test

typecheck:
timeout-minutes: 15
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
- uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0
- uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
path: |
${{ steps.get-pnpm-path.outputs.pnpm-store-path }}
key: |
pnpm_store-pnpm_${{ hashFiles('pnpm-lock.*') }}-flake_${{ hashFiles('flake.lock') }}-${{ runner.arch }}-${{ runner.os }}
- uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
name: Cache deno modules
with:
node-version-file: '.node-version'
cache: pnpm
- run: pnpm install --frozen-lockfile
- name: Typecheck
run: pnpm run typecheck
# Using `deno info --json` prints accurate data. However this is a simple solution in this workflow
# See https://github.com/actions/cache/blob/1bd1e32a3bdc45362d1e726936510720a7c30a57/examples.md?plain=1#L144-L155
path: |
~/.cache/deno
key: |
deno_store-deno_${{ hashFiles('deno.lock') }}-flake_${{ hashFiles('flake.lock') }}-${{ runner.arch }}-${{ runner.os }}
- name: Setup
run: |
nix develop --command deno task deps
nix develop --command deno task setup
- name: Test, build, lint
run: |
nix develop --command deno task all
- name: Make sure there is no diff after build
run: |
nix develop --command deno task check_no_git_diff
3 changes: 0 additions & 3 deletions .github/workflows/itself.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,6 @@ jobs:
{
"workflowFile": "ci.yml"
},
{
"workflowFile": "ci-nix.yml"
},
{
"workflowFile": "merge-bot-pr.yml",
"jobName": "dependabot"
Expand Down
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"tekumara.typos-vscode",
"jnoortheen.nix-ide",
"tamasfe.even-better-toml",
"ms-azuretools.vscode-docker"
"ms-azuretools.vscode-docker",
"denoland.vscode-deno"
]
}
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@
"node_modules/**": true,
".direnv/**": true
},
"deno.enable": false
"deno.enable": true,
"deno.enablePaths": [
"scripts"
]
}
46 changes: 23 additions & 23 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
# How to develop

## Setup
We can only use Node.js for JavaScript actions in GitHub Hosted runners.\
However, managing the Node.js toolset is a pain for me, so this repository prefers Deno for the development tasks.\
And finally, it transpiles and bundles into [dist](dist), which will be loaded in Node.js.

### Nix
In short

1. Install [Nix](https://nixos.org/) package manager
2. Run `nix develop` or `direnv allow`
3. You can use development tasks
Node.js

```console
> nix develop
(prepared shell)
```
- [dist](dist)
- [src](src)
- [`__test__`](__test__)

### Tasks
Deno

```console
> makers help
> Tools
- [scripts](scripts)

---
## Dependency management

check - ...
help - ...
It will be done in [Nix](https://nixos.org/) and [pnpm](https://github.com/pnpm/pnpm).

> makers setup
added 438 packages, and audited 439 packages in 6s
1. Run `nix develop` or `direnv allow .`
2. `deno task setup`

> makers check
...tests, typechecks, linters...
```
## Tasks

See also [scripts](package.json) for tasks details.
```console
> deno task
# Print all tasks

> deno task all
...tests, typechecks, linters, build
```

## REPL

```bash
pnpm run repl
deno task repl
```

```typescript
Expand Down
95 changes: 0 additions & 95 deletions Makefile.toml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![gracePeriod](https://github.com/kachick/wait-other-jobs/actions/workflows/GH-820-graceperiod.yml/badge.svg?branch=main)](https://github.com/kachick/wait-other-jobs/actions/workflows/GH-820-graceperiod.yml?query=event%3Apush++)
[![eventName](https://github.com/kachick/wait-other-jobs/actions/workflows/GH-771-eventname.yml/badge.svg?branch=main)](https://github.com/kachick/wait-other-jobs/actions/workflows/GH-771-eventname.yml?query=event%3Apush++)
[![matrix](https://github.com/kachick/wait-other-jobs/actions/workflows/GH-761-matrix.yml/badge.svg?branch=main)](https://github.com/kachick/wait-other-jobs/actions/workflows/GH-761-matrix.yml?query=event%3Apush++)\
[![TypeScript](https://github.com/kachick/wait-other-jobs/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/kachick/wait-other-jobs/actions/workflows/ci.yml?query=event%3Apush++)
[![CI](https://github.com/kachick/wait-other-jobs/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/kachick/wait-other-jobs/actions/workflows/ci.yml?query=event%3Apush++)

This GitHub action waits for all or specific jobs, even if they are running in other workflows.\
If any of those jobs fail, this action will fail as well.
Expand Down
4 changes: 0 additions & 4 deletions __tests__/report.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,10 +519,6 @@ test('skip-list', async (t) => {
'workflowFile': 'ci.yml',
jobMatchMode: 'all',
},
{
'workflowFile': 'ci-nix.yml',
jobMatchMode: 'all',
},
{
'workflowFile': 'merge-bot-pr.yml',
'jobName': 'dependabot',
Expand Down
31 changes: 30 additions & 1 deletion deno.jsonc
Original file line number Diff line number Diff line change
@@ -1,9 +1,38 @@
{
"tasks": {
"setup": "pnpm install --frozen-lockfile",
"all": {
"dependencies": ["typecheck", "test", "lint", "build"],
"command": "echo '🎉 '"
},
"test": "./scripts/run_tests.ts",
"typecheck": "pnpm tsc",
"cleanup_build": "rm -rf ./lib ./dist",
"build": {
"dependencies": ["cleanup_build"],
"command": "./scripts/build.ts"
},
"update": "git ls-files '.github' | xargs nix run 'github:kachick/selfup/v1.1.9' -- run",
"check_no_git_diff": {
"description": "Prevent unexpected commits",
"command": "(git add --intent-to-add . && git diff --exit-code) || (echo 'You should commit all diff before running tests'; exit 1)"
},
"fmt": "dprint fmt && git ls-files '*.nix' | xargs nixfmt",
"lint": "./scripts/lint.ts",
"repl": "pnpm tsx", // Don't use deno REPL for this purpose. Finally the code will work on Node.js.
"deps": {
"description": "Print development dependencies and the versions",
"command": "./scripts/deps.ts"
}
},
"lint": {
"include": ["."],
"exclude": ["dist/", "node_modules/", "logs/"],
"exclude": ["dist/", "node_modules/", "logs/", "dependencies/"],
"rules": {
"tags": ["recommended"]
}
},
"imports": {
"@david/dax": "jsr:@david/dax@^0.42.0"
}
}
Loading

0 comments on commit 1d0d271

Please sign in to comment.