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
6 changes: 6 additions & 0 deletions .actrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Default act settings for local CI (nektos/act).
# Prefer `npm run ci:local` before opening/updating PRs to develop / dev-*.
# Requires Docker. Without Docker, use `npm run ci:local:fallback`.
-P ubuntu-latest=catthehacker/ubuntu:act-latest
--container-architecture linux/amd64
-W .github/workflows/ci.yml
29 changes: 29 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Dependabot opens update PRs only; no auto-merge.
version: 2
updates:
- package-ecosystem: npm
directory: /
schedule:
interval: weekly
day: monday
open-pull-requests-limit: 10
groups:
npm-production:
dependency-type: production
patterns:
- "*"
npm-development:
dependency-type: development
patterns:
- "*"

- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
day: monday
open-pull-requests-limit: 10
groups:
github-actions:
patterns:
- "*"
177 changes: 177 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
# CI — PRs targeting develop or dev-* only.
# Local pre-PR gate: npm run ci:local (nektos/act). See docs/ci-cd.md.
name: CI

on:
pull_request:
branches:
- develop
- "dev-*"

concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read
actions: read
checks: read
pull-requests: read

jobs:
gate:
name: Gate
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
skip_heavy: ${{ steps.decide.outputs.skip_heavy }}
reason: ${{ steps.decide.outputs.reason }}
steps:
- name: Decide skip / docs-only / full
id: decide
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const isAct = process.env.ACT === 'true';
if (isAct) {
core.setOutput('skip_heavy', 'false');
core.setOutput('reason', 'act');
core.info('ACT=true: always run heavy jobs');
return;
}

const pr = context.payload.pull_request;
if (!pr) {
core.setOutput('skip_heavy', 'false');
core.setOutput('reason', 'no-pr');
return;
}

const sha = pr.head.sha;
const base = context.repo;
const { data: runs } = await github.rest.actions.listWorkflowRuns({
owner: base.owner,
repo: base.repo,
workflow_id: 'ci.yml',
head_sha: sha,
status: 'completed',
per_page: 30,
});
const priorSuccess = (runs.workflow_runs || []).some(
(r) => r.conclusion === 'success' && String(r.id) !== String(context.runId),
);
if (priorSuccess) {
core.setOutput('skip_heavy', 'true');
core.setOutput('reason', 'sha-already-green');
core.info(`Skip heavy jobs: CI already succeeded for ${sha}`);
return;
}

// Docs-only path filter via compare API
const { data: comp } = await github.rest.repos.compareCommits({
owner: base.owner,
repo: base.repo,
base: pr.base.sha,
head: sha,
});
const files = comp.files || [];
const isDocsOnly =
files.length > 0 &&
files.every((f) => {
const p = f.filename;
return (
p.startsWith('docs/') ||
p.endsWith('.md') ||
p === 'LICENSE' ||
(p.startsWith('.github/') && p.endsWith('.md'))
);
});
if (isDocsOnly) {
core.setOutput('skip_heavy', 'true');
core.setOutput('reason', 'docs-only');
core.info('Skip heavy jobs: docs-only change set');
return;
}

core.setOutput('skip_heavy', 'false');
core.setOutput('reason', 'full');

test:
name: Test
needs: gate
if: needs.gate.outputs.skip_heavy != 'true'
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Setup Node.js
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version: 24
cache: npm

- name: Install dependencies
run: npm ci

- name: Test with coverage
run: npm test

- name: Upload coverage to Codecov
if: ${{ !env.ACT }}
uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage/lcov.info
fail_ci_if_error: false
verbose: true

build:
name: Build
needs: gate
if: needs.gate.outputs.skip_heavy != 'true'
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Setup Node.js
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version: 24
cache: npm

- name: Install dependencies
run: npm ci

- name: Build
run: npm run build

# Keeps branch-protection check name "Test & Build" stable.
result:
name: Test & Build
needs: [gate, test, build]
if: always()
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Aggregate
run: |
set -euo pipefail
skip='${{ needs.gate.outputs.skip_heavy }}'
reason='${{ needs.gate.outputs.reason }}'
test_result='${{ needs.test.result }}'
build_result='${{ needs.build.result }}'
echo "skip_heavy=${skip} reason=${reason}"
echo "test=${test_result} build=${build_result}"
if [ "${skip}" = "true" ]; then
echo "Heavy jobs skipped (${reason}); treating as success."
exit 0
fi
if [ "${test_result}" = "success" ] && [ "${build_result}" = "success" ]; then
exit 0
fi
echo "::error::Test and/or Build did not succeed"
exit 1
41 changes: 41 additions & 0 deletions .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: OpenSSF Scorecard

on:
branch_protection_rule:
schedule:
- cron: "30 1 * * 1"
push:
branches:
- main

permissions: read-all

jobs:
analysis:
name: Scorecard analysis
runs-on: ubuntu-latest
permissions:
security-events: write
id-token: write
contents: read
actions: read
issues: read
pull-requests: read
checks: read
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Run analysis
uses: ossf/scorecard-action@2d1146689b8cda280b9bc96326124645441f03bc # v2.4.4
with:
results_file: results.sarif
results_format: sarif
publish_results: true

- name: Upload SARIF
uses: github/codeql-action/upload-sarif@cdf488f595d80d6e07e03d4674febd5ab45fa938 # v4.37.9
with:
sarif_file: results.sarif
13 changes: 13 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
codecov:
require_ci_to_pass: false

coverage:
status:
project:
default:
informational: true
patch:
default:
informational: true

comment: false
14 changes: 7 additions & 7 deletions docs/ci-cd.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ npm run ci:local
act pull_request -W .github/workflows/ci.yml
```

既定は [`.actrc`](../.actrc)(ワークフロー追加時に同梱)。`act` 実行時はゲートが Test/Build を必ず実行します(`ACT=true`)。Codecov は `ACT` 時にスキップします。
既定は [`.actrc`](../.actrc)。`act` 実行時はゲートが Test/Build を必ず実行します(`ACT=true`)。Codecov は `ACT` 時にスキップします。

Docker が無い環境(一部の Cloud Agent など):

Expand All @@ -65,14 +65,14 @@ npm run ci:local:fallback # npm ci && npm test && npm run build

| ファイル | 役割 | 状態 |
|----------|------|------|
| `.github/workflows/ci.yml` | PR CI: Gate → Test ‖ Build → 集約 **Test & Build** | 予定 |
| `.github/workflows/ci.yml` | PR CI: Gate → Test ‖ Build → 集約 **Test & Build** | 実装済み |
| `.github/workflows/codeql.yml` | CodeQL(`develop`/`dev-*` PR、`main` push、週次) | 予定 |
| `.github/workflows/scorecard.yml` | OpenSSF Scorecard(`main` + schedule) | 予定 |
| `.github/workflows/scorecard.yml` | OpenSSF Scorecard(`main` + schedule) | 実装済み |
| `.github/workflows/release-on-tag.yml` | `v*` push → GitHub Release 作成 | 実装済み |
| `.github/workflows/publish.yml` | Release published → npm pack + provenance publish | 実装済み |
| `.github/dependabot.yml` | 週次 npm + Actions(グループ化、自動マージなし) | 予定 |
| `.github/dependabot.yml` | 週次 npm + Actions(グループ化、自動マージなし) | 実装済み |
| `.github/codeql/codeql-config.yml` | `dist/**`・`coverage/**` を除外 | 予定 |
| `codecov.yml` | project/patch は informational、PR コメントなし | 予定 |
| `codecov.yml` | project/patch は informational、PR コメントなし | 実装済み |
| `deploy-docs.yml` / `monitor-source-hash.yml` | — | 採用しない |

### CI ルール(参考リポジトリ踏襲)
Expand Down Expand Up @@ -119,8 +119,8 @@ Codecov のカバレッジパス: `coverage/lcov.info`(単一パッケージ
## 実装順

1. **方針ドキュメント + README バッジ** — 完了。
2. **CI スキャフォールド** — `ci.yml`、`.actrc`、`codecov.yml`、`ci:local` / `ci:local:fallback`、Dependabot。
3. **セキュリティ** — CodeQL + Scorecard。
2. **CI スキャフォールド** — `ci.yml`、`.actrc`、`codecov.yml`、`ci:local` / `ci:local:fallback`、Dependabot — 完了。
3. **セキュリティ** — CodeQL(予定)+ Scorecard(完了)。
4. **CD** — `release-on-tag.yml` + `publish.yml`(本変更)。CD 利用前に npmjs.com で `@b4moss/cachian` の Trusted Publisher に GitHub org `b4moss` / repo `cachian` / workflow `publish.yml` を登録する。リポジトリの `NPM_TOKEN` シークレットは不要。`v*` タグは `main` から打つ。
5. **ブランチ保護** — `develop` / `dev-*` で **`Test & Build`** を required に。

Expand Down
14 changes: 7 additions & 7 deletions docs/ci-cd.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ npm run ci:local
act pull_request -W .github/workflows/ci.yml
```

Defaults live in [`.actrc`](../.actrc) (to be added with workflows). Under `act`, the CI gate always runs Test/Build (`ACT=true`). Codecov is skipped when `ACT` is set.
Defaults live in [`.actrc`](../.actrc). Under `act`, the CI gate always runs Test/Build (`ACT=true`). Codecov is skipped when `ACT` is set.

Without Docker (some Cloud Agent environments):

Expand All @@ -65,14 +65,14 @@ Do not open or update a PR while this gate is failing.

| File | Role | Status |
|------|------|--------|
| `.github/workflows/ci.yml` | PR CI: Gate → Test ‖ Build → aggregate **Test & Build** | Planned |
| `.github/workflows/ci.yml` | PR CI: Gate → Test ‖ Build → aggregate **Test & Build** | Implemented |
| `.github/workflows/codeql.yml` | CodeQL on PR to `develop`/`dev-*`, push to `main`, weekly | Planned |
| `.github/workflows/scorecard.yml` | OpenSSF Scorecard on `main` + schedule | Planned |
| `.github/workflows/scorecard.yml` | OpenSSF Scorecard on `main` + schedule | Implemented |
| `.github/workflows/release-on-tag.yml` | Push `v*` → create GitHub Release | Implemented |
| `.github/workflows/publish.yml` | Release published → npm pack + provenance publish | Implemented |
| `.github/dependabot.yml` | Weekly npm + Actions updates (grouped, no auto-merge) | Planned |
| `.github/dependabot.yml` | Weekly npm + Actions updates (grouped, no auto-merge) | Implemented |
| `.github/codeql/codeql-config.yml` | Ignore `dist/**`, `coverage/**` | Planned |
| `codecov.yml` | Project/patch informational; no PR comment | Planned |
| `codecov.yml` | Project/patch informational; no PR comment | Implemented |
| `deploy-docs.yml` / `monitor-source-hash.yml` | — | Not adopted |

### CI rules (mirror reference)
Expand Down Expand Up @@ -119,8 +119,8 @@ Until workflows run and the package is published, some badges may show unknown/e
## Implementation order

1. **Direction docs + README badges** — done.
2. **CI scaffold** — `ci.yml`, `.actrc`, `codecov.yml`, `package.json` scripts `ci:local` / `ci:local:fallback`, Dependabot.
3. **Security** — CodeQL + Scorecard.
2. **CI scaffold** — `ci.yml`, `.actrc`, `codecov.yml`, `package.json` scripts `ci:local` / `ci:local:fallback`, Dependabot — done.
3. **Security** — CodeQL (planned) + Scorecard (done).
4. **CD** — `release-on-tag.yml` + `publish.yml` (this change). Before relying on CD: on npmjs.com add a Trusted Publisher for `@b4moss/cachian` pointing at GitHub org `b4moss` / repo `cachian` / workflow `publish.yml`. No repo `NPM_TOKEN` secret. Create `v*` tags from `main`.
5. **Branch protection** — require check name **`Test & Build`** on `develop` / `dev-*`.

Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
"scripts": {
"dev": "vite build --watch",
"build": "node ./scripts/build.mjs",
"test": "vitest run --coverage"
"test": "vitest run --coverage",
"ci:local": "act pull_request -W .github/workflows/ci.yml",
"ci:local:fallback": "npm ci && npm test && npm run build"
},
"keywords": [
"cache",
Expand Down
7 changes: 7 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,12 @@ export default defineConfig({
},
test: {
include: ["src/**/*.test.ts"],
coverage: {
provider: "v8",
reporter: ["text", "lcov"],
reportsDirectory: "coverage",
include: ["src/**/*.ts"],
exclude: ["src/**/*.test.ts", "src/**/types.ts"],
},
},
});