diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..c586620 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,76 @@ +name: Publish + +on: + push: + tags: + - 'v*' + +permissions: + contents: read + +concurrency: + group: publish-${{ github.ref }} + cancel-in-progress: false + +jobs: + precheck: + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + fetch-depth: 0 + persist-credentials: false + - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 + with: + node-version: '24.x' + cache: npm + cache-dependency-path: package-lock.json + - name: Verify release tag and main history + run: | + node --input-type=module <<'NODE' + import assert from 'node:assert/strict'; + import { readFileSync } from 'node:fs'; + const { version } = JSON.parse(readFileSync('package.json', 'utf8')); + assert.equal(process.env.GITHUB_REF_NAME, `v${version}`, 'Tag must match package.json version'); + assert.match(version, /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/, 'Only stable versions can be published as latest'); + assert.notEqual(version, '0.0.0', 'Publish the bootstrap version manually'); + NODE + git merge-base --is-ancestor HEAD origin/main + - run: npm ci + - run: npm run lint + - run: npm run format + - name: Build, unit tests, generated types and coverage thresholds + run: npm run test:coverage + - name: Source and TypeScript consumer types + run: npm run test:types + - name: Installed npm package check + run: npm run test:package + - name: Install minimum supported TypeScript separately + run: npm install --prefix "$RUNNER_TEMP/microcms-ts6" --no-save --package-lock=false typescript@6.0.2 + - name: TypeScript 6 compatibility + env: + MICROCMS_TYPESCRIPT_BINARY: ${{ runner.temp }}/microcms-ts6/node_modules/typescript/bin/tsc + run: | + npm run test:types + npm run test:package + + publish: + needs: precheck + runs-on: ubuntu-latest + timeout-minutes: 10 + permissions: + contents: read + id-token: write + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 + with: + node-version: '24.x' + registry-url: 'https://registry.npmjs.org' + package-manager-cache: false + - run: npm ci + - run: npm run build + - run: npm publish --tag latest diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 783bee3..8f4d74b 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -128,4 +128,14 @@ typegenはスキーマ取得と生成型の正しさ、SDKは生成型を使う - [カバレッジ設定](.c8rc.json):ファイルごとに文・行98%、分岐95%、関数100%。型定義のみのファイルは対象外で、生成型はコンパイルで検査します。レポートは`coverage/index.html`・`lcov.info`・`coverage-summary.json`です。 - [CI](.github/workflows/ci.yml):Node.js22.18.0・22系・24系でテスト・カバレッジ・型・パッケージを検査。TypeScript6.0.2の互換性とLint・フォーマットも検査し、カバレッジレポートを14日間保存します。 -- `test:package`とCIはnpmへ公開しません。npmの初期登録用は`0.0.0`(`bootstrap`タグ)、初回正式版は`1.0.0`です。レビュー後の公開に向け、パッケージ名の最終確認、npmのアカウント・公開権限、認証方法とリリース用CIを整えます。 +- `test:package`と通常のCIはnpmへ公開しません。公開パッケージ名はスコープなしの`microcms-typegen`です。npmの初期登録用は`0.0.0`(`bootstrap`タグ)、初回正式版は`1.0.0`です。 +- [公開ワークフロー](.github/workflows/publish.yml):`v*`タグで起動し、バージョンの一致・`main`への反映、Lint・フォーマット・テスト・型・配布物を検査してから、Node.js24系でnpmへ`latest`として公開します。初期登録用の`0.0.0`やプレリリース版は対象外です。 + +### 初回公開 + +1. 公開ワークフローを`main`へマージし、CIの成功を確認します。 +2. npmにログインし、`npm publish --tag bootstrap`で`0.0.0`を初期登録します。 +3. npmのパッケージ設定でTrusted Publisherを登録します。Organizationは`microcmsio`、Repositoryは`microcms-ts-typegen`、Workflow filenameは`publish.yml`です。Environmentは空欄にし、`npm publish`を許可します。 +4. `package.json`・`package-lock.json`のバージョンを`1.0.0`に変更するPRをマージし、CIの成功後、そのコミットに`v1.0.0`タグを作成・pushします。 + +公開ジョブだけに`id-token: write`を付与し、GitHubホストのランナーで[Trusted Publishing](https://docs.npmjs.com/trusted-publishers/)を使用します。npmトークンの登録は不要です。npmのTrusted Publisher設定は初回公開の直前に行います。 diff --git a/package.json b/package.json index 93672ea..3bec80d 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,10 @@ "version": "0.0.0", "description": "Generate TypeScript content types from microCMS Management API schemas", "license": "Apache-2.0", + "repository": { + "type": "git", + "url": "https://github.com/microcmsio/microcms-ts-typegen.git" + }, "type": "module", "types": "./dist/config.d.ts", "exports": {