diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 057fc5429..000000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,16 +0,0 @@ -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/prepare - - run: pnpm build - - run: node ./lib/index.js - -name: Build - -on: - pull_request: ~ - push: - branches: - - main diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..ded183f66 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,77 @@ +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/prepare + - run: pnpm build + - run: node ./lib/index.js + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/prepare + - run: pnpm build + - run: pnpm lint + lint_knip: + name: Lint Knip + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/prepare + - run: pnpm lint:knip + lint_markdown: + name: Lint Markdown + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/prepare + - run: pnpm lint:md + lint_packages: + name: Lint Packages + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/prepare + - run: pnpm lint:packages + lint_spelling: + name: Lint Spelling + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/prepare + - run: pnpm lint:spelling + prettier: + name: Prettier + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/prepare + - run: pnpm format --list-different + test: + name: Test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/prepare + - run: pnpm run test --coverage + - uses: codecov/codecov-action@v3 + with: + flags: unit + type_check: + name: Type Check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/prepare + - run: pnpm tsc + +name: CI + +on: + pull_request: ~ + push: + branches: + - main diff --git a/.github/workflows/lint-knip.yml b/.github/workflows/lint-knip.yml deleted file mode 100644 index 781d52ef1..000000000 --- a/.github/workflows/lint-knip.yml +++ /dev/null @@ -1,15 +0,0 @@ -jobs: - lint_knip: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/prepare - - run: pnpm lint:knip - -name: Lint Knip - -on: - pull_request: ~ - push: - branches: - - main diff --git a/.github/workflows/lint-markdown.yml b/.github/workflows/lint-markdown.yml deleted file mode 100644 index acac714de..000000000 --- a/.github/workflows/lint-markdown.yml +++ /dev/null @@ -1,15 +0,0 @@ -jobs: - lint_markdown: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/prepare - - run: pnpm lint:md - -name: Lint Markdown - -on: - pull_request: ~ - push: - branches: - - main diff --git a/.github/workflows/lint-packages.yml b/.github/workflows/lint-packages.yml deleted file mode 100644 index 87520cac1..000000000 --- a/.github/workflows/lint-packages.yml +++ /dev/null @@ -1,15 +0,0 @@ -jobs: - lint_packages: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/prepare - - run: pnpm lint:packages - -name: Lint Packages - -on: - pull_request: ~ - push: - branches: - - main diff --git a/.github/workflows/lint-spelling.yml b/.github/workflows/lint-spelling.yml deleted file mode 100644 index ef020b62c..000000000 --- a/.github/workflows/lint-spelling.yml +++ /dev/null @@ -1,15 +0,0 @@ -jobs: - lint_spelling: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/prepare - - run: pnpm lint:spelling - -name: Lint spelling - -on: - pull_request: ~ - push: - branches: - - main diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index 67a9ae5b7..000000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,16 +0,0 @@ -jobs: - lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/prepare - - run: pnpm build - - run: pnpm lint - -name: Lint - -on: - pull_request: ~ - push: - branches: - - main diff --git a/.github/workflows/prettier.yml b/.github/workflows/prettier.yml deleted file mode 100644 index ae43fc44d..000000000 --- a/.github/workflows/prettier.yml +++ /dev/null @@ -1,15 +0,0 @@ -jobs: - prettier: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/prepare - - run: pnpm format --list-different - -name: Prettier - -on: - pull_request: ~ - push: - branches: - - main diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index dae947fec..000000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,19 +0,0 @@ -jobs: - test: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/prepare - - run: pnpm run test --coverage - - name: Codecov - uses: codecov/codecov-action@v3 - with: - flags: unit - -name: Test - -on: - pull_request: ~ - push: - branches: - - main diff --git a/.github/workflows/tsc.yml b/.github/workflows/tsc.yml deleted file mode 100644 index 3b20f2428..000000000 --- a/.github/workflows/tsc.yml +++ /dev/null @@ -1,15 +0,0 @@ -jobs: - type_check: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/prepare - - run: pnpm tsc - -name: Type Check - -on: - pull_request: ~ - push: - branches: - - main diff --git a/cspell.json b/cspell.json index 607b7e193..fee2a6f1b 100644 --- a/cspell.json +++ b/cspell.json @@ -14,6 +14,7 @@ "apexskier", "arethetypeswrong", "automerge", + "codecov", "codespace", "contributorsrc", "execa", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 13dbade51..d8405d413 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1833,6 +1833,7 @@ packages: commit-to-co-authors@0.1.0: resolution: {integrity: sha512-5v1M+gBD0H7G2++D1L3z8ekVkTsIYNTuUFmL8KgIumuJdZ1CFjRulgUvYA7dFDmZNENu0G//yp+krWGcXb2WYA==} engines: {node: '>=18'} + deprecated: Renamed to description-to-co-authors. This will work for GitHub issue bodies too. compare-func@2.0.0: resolution: {integrity: sha512-zHig5N+tPWARooBnb0Zx1MFcdfpyJrfTJ3Y5L+IFvUm8rM74hHz66z0gw0x4tijh5CorKkKUCnW82R2vmpeCRA==} diff --git a/script/__snapshots__/migrate-test-e2e.ts.snap b/script/__snapshots__/migrate-test-e2e.ts.snap index 357fb8538..68b021cb1 100644 --- a/script/__snapshots__/migrate-test-e2e.ts.snap +++ b/script/__snapshots__/migrate-test-e2e.ts.snap @@ -1,17 +1,17 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`expected file changes > .github/workflows/test.yml 1`] = ` -"--- a/.github/workflows/test.yml -+++ b/.github/workflows/test.yml +exports[`expected file changes > .github/workflows/ci.yml 1`] = ` +"--- a/.github/workflows/ci.yml ++++ b/.github/workflows/ci.yml @@ ... @@ jobs: + - uses: ./.github/actions/prepare - run: pnpm run test --coverage - - name: Codecov - uses: codecov/codecov-action@v3 + - uses: codecov/codecov-action@v3 - with: - flags: unit - - name: Test - " + type_check: + name: Type Check + runs-on: ubuntu-latest" `; exports[`expected file changes > .gitignore 1`] = ` @@ -75,6 +75,11 @@ exports[`expected file changes > cspell.json 1`] = ` "node_modules", "pnpm-lock.yaml" @@ ... @@ + "apexskier", + "arethetypeswrong", + "automerge", +- "codecov", + "codespace", "contributorsrc", "execa", "infile", diff --git a/script/migrate-test-e2e.ts b/script/migrate-test-e2e.ts index 01830d9c3..5468e1447 100644 --- a/script/migrate-test-e2e.ts +++ b/script/migrate-test-e2e.ts @@ -9,7 +9,7 @@ import packageData from "../package.json" assert { type: "json" }; const filesExpectedToBeChanged = [ "README.md", "knip.json", - ".github/workflows/test.yml", + ".github/workflows/ci.yml", ".gitignore", ".prettierignore", "cspell.json", diff --git a/src/steps/initializeBranchProtectionSettings.test.ts b/src/steps/initializeBranchProtectionSettings.test.ts index b52aa1445..afff91b9d 100644 --- a/src/steps/initializeBranchProtectionSettings.test.ts +++ b/src/steps/initializeBranchProtectionSettings.test.ts @@ -54,31 +54,31 @@ describe("migrateBranchProtectionSettings", () => { "required_status_checks": { "checks": [ { - "context": "build", + "context": "Build", }, { - "context": "lint", + "context": "Compliance", }, { - "context": "prettier", + "context": "Lint", }, { - "context": "compliance", + "context": "Lint Knip", }, { - "context": "lint_knip", + "context": "Lint Markdown", }, { - "context": "lint_markdown", + "context": "Lint Packages", }, { - "context": "lint_packages", + "context": "Lint Spelling", }, { - "context": "lint_spelling", + "context": "Prettier", }, { - "context": "test", + "context": "Test", }, ], "strict": false, @@ -146,13 +146,13 @@ describe("migrateBranchProtectionSettings", () => { "required_status_checks": { "checks": [ { - "context": "build", + "context": "Build", }, { - "context": "lint", + "context": "Lint", }, { - "context": "prettier", + "context": "Prettier", }, ], "strict": false, diff --git a/src/steps/initializeGitHubRepository/initializeBranchProtectionSettings.ts b/src/steps/initializeGitHubRepository/initializeBranchProtectionSettings.ts index 45d9495d7..ada242128 100644 --- a/src/steps/initializeGitHubRepository/initializeBranchProtectionSettings.ts +++ b/src/steps/initializeGitHubRepository/initializeBranchProtectionSettings.ts @@ -25,19 +25,19 @@ export async function initializeBranchProtectionSettings( required_pull_request_reviews: null, required_status_checks: { checks: [ - { context: "build" }, - { context: "lint" }, - { context: "prettier" }, - ...(options.excludeCompliance ? [] : [{ context: "compliance" }]), - ...(options.excludeLintKnip ? [] : [{ context: "lint_knip" }]), - ...(options.excludeLintMd ? [] : [{ context: "lint_markdown" }]), + { context: "Build" }, + ...(options.excludeCompliance ? [] : [{ context: "Compliance" }]), + { context: "Lint" }, + ...(options.excludeLintKnip ? [] : [{ context: "Lint Knip" }]), + ...(options.excludeLintMd ? [] : [{ context: "Lint Markdown" }]), ...(options.excludeLintPackages ? [] - : [{ context: "lint_packages" }]), + : [{ context: "Lint Packages" }]), ...(options.excludeLintSpelling ? [] - : [{ context: "lint_spelling" }]), - ...(options.excludeTests ? [] : [{ context: "test" }]), + : [{ context: "Lint Spelling" }]), + { context: "Prettier" }, + ...(options.excludeTests ? [] : [{ context: "Test" }]), ], strict: false, }, diff --git a/src/steps/writing/creation/dotGitHub/createMultiWorkflowFile.test.ts b/src/steps/writing/creation/dotGitHub/createMultiWorkflowFile.test.ts new file mode 100644 index 000000000..36fd4e318 --- /dev/null +++ b/src/steps/writing/creation/dotGitHub/createMultiWorkflowFile.test.ts @@ -0,0 +1,48 @@ +import { describe, expect, it } from "vitest"; + +import { createMultiWorkflowFile } from "./createMultiWorkflowFile.js"; + +describe("createMultiWorkflowFile", () => { + it("creates a workflow file when runs are provided", () => { + const actual = createMultiWorkflowFile({ + jobs: [ + { + name: "Job A", + steps: [{ run: "task-a" }], + }, + { + name: "Job B", + steps: [{ uses: "task-b" }], + }, + ], + name: "Test Name", + }); + + expect(actual).toMatchInlineSnapshot(` + "jobs: + job_a: + name: Job A + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/prepare + - run: task-a + job_b: + name: Job B + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/prepare + - uses: task-b + + name: Test Name + + on: + pull_request: ~ + push: + branches: + - main + " + `); + }); +}); diff --git a/src/steps/writing/creation/dotGitHub/createMultiWorkflowFile.ts b/src/steps/writing/creation/dotGitHub/createMultiWorkflowFile.ts new file mode 100644 index 000000000..26c524622 --- /dev/null +++ b/src/steps/writing/creation/dotGitHub/createMultiWorkflowFile.ts @@ -0,0 +1,42 @@ +import { formatWorkflowYaml } from "./formatWorkflowYaml.js"; + +export type MultiWorkflowJobStep = { run: string } | { uses: string }; + +export interface MultiWorkflowJobOptions { + name: string; + steps: MultiWorkflowJobStep[]; +} + +export interface MultiWorkflowFileOptions { + jobs: MultiWorkflowJobOptions[]; + name: string; +} + +export function createMultiWorkflowFile({ + jobs, + name, +}: MultiWorkflowFileOptions) { + return formatWorkflowYaml({ + jobs: Object.fromEntries( + jobs.map((job) => [ + job.name.toLowerCase().replaceAll(" ", "_"), + { + name: job.name, + "runs-on": "ubuntu-latest", + steps: [ + { uses: "actions/checkout@v4" }, + { uses: "./.github/actions/prepare" }, + ...job.steps, + ], + }, + ]), + ), + name, + on: { + pull_request: null, + push: { + branches: ["main"], + }, + }, + }); +} diff --git a/src/steps/writing/creation/dotGitHub/createSoloWorkflowFile.test.ts b/src/steps/writing/creation/dotGitHub/createSoloWorkflowFile.test.ts new file mode 100644 index 000000000..e6e7261f7 --- /dev/null +++ b/src/steps/writing/creation/dotGitHub/createSoloWorkflowFile.test.ts @@ -0,0 +1,25 @@ +import { describe, expect, it } from "vitest"; + +import { createSoloWorkflowFile } from "./createSoloWorkflowFile.js"; + +describe("createSoloWorkflowFile", () => { + it("creates a workflow file when runs are provided", () => { + const actual = createSoloWorkflowFile({ + name: "Test Name", + runs: ["pnpm build"], + }); + + expect(actual).toMatchInlineSnapshot(` + "jobs: + test_name: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/prepare + - run: pnpm build + + name: Test Name + " + `); + }); +}); diff --git a/src/steps/writing/creation/dotGitHub/createWorkflowFile.ts b/src/steps/writing/creation/dotGitHub/createSoloWorkflowFile.ts similarity index 61% rename from src/steps/writing/creation/dotGitHub/createWorkflowFile.ts rename to src/steps/writing/creation/dotGitHub/createSoloWorkflowFile.ts index 7b5539dec..8f8cc8213 100644 --- a/src/steps/writing/creation/dotGitHub/createWorkflowFile.ts +++ b/src/steps/writing/creation/dotGitHub/createSoloWorkflowFile.ts @@ -1,4 +1,4 @@ -import { formatYaml } from "../formatters/formatYaml.js"; +import { formatWorkflowYaml } from "./formatWorkflowYaml.js"; interface WorkflowFileConcurrency { "cancel-in-progress"?: boolean; @@ -65,43 +65,31 @@ interface WorkflowFileOptionsSteps extends WorkflowFileOptionsBase { type WorkflowFileOptions = WorkflowFileOptionsRuns | WorkflowFileOptionsSteps; -export function createWorkflowFile({ +export function createSoloWorkflowFile({ concurrency, name, - on = { - pull_request: null, - push: { - branches: ["main"], - }, - }, + on, permissions, ...options }: WorkflowFileOptions) { - return ( - formatYaml({ - concurrency, - jobs: { - [name.replaceAll(" ", "_").toLowerCase()]: { - ...(options.if && { if: options.if }), - "runs-on": "ubuntu-latest", - steps: - "runs" in options - ? [ - { uses: "actions/checkout@v4" }, - { uses: "./.github/actions/prepare" }, - ...options.runs.map((run) => ({ run })), - ] - : options.steps, - }, + return formatWorkflowYaml({ + concurrency, + jobs: { + [name.replaceAll(" ", "_").toLowerCase()]: { + ...(options.if && { if: options.if }), + "runs-on": "ubuntu-latest", + steps: + "runs" in options + ? [ + { uses: "actions/checkout@v4" }, + { uses: "./.github/actions/prepare" }, + ...options.runs.map((run) => ({ run })), + ] + : options.steps, }, - name, - on, - permissions, - }) - .replaceAll(/\n(\S)/g, "\n\n$1") - // https://github.com/nodeca/js-yaml/pull/515 - .replaceAll(/: "\\n(.+)"/g, ": |\n$1") - .replaceAll("\\n", "\n") - .replaceAll("\\t", " ") - ); + }, + name, + on, + permissions, + }); } diff --git a/src/steps/writing/creation/dotGitHub/createWorkflowFile.test.ts b/src/steps/writing/creation/dotGitHub/createWorkflowFile.test.ts deleted file mode 100644 index 396a067e3..000000000 --- a/src/steps/writing/creation/dotGitHub/createWorkflowFile.test.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { describe, expect, it } from "vitest"; - -import { createWorkflowFile } from "./createWorkflowFile.js"; - -describe("createWorkflowFile", () => { - it("creates a workflow file when runs are provided", () => { - const actual = createWorkflowFile({ - name: "Test Name", - runs: ["pnpm build"], - }); - - expect(actual).toBe( - `jobs: - test_name: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/prepare - - run: pnpm build - -name: Test Name - -on: - pull_request: ~ - push: - branches: - - main -`, - ); - }); -}); diff --git a/src/steps/writing/creation/dotGitHub/createWorkflows.test.ts b/src/steps/writing/creation/dotGitHub/createWorkflows.test.ts index d2ec56da2..1aef6d0a0 100644 --- a/src/steps/writing/creation/dotGitHub/createWorkflows.test.ts +++ b/src/steps/writing/creation/dotGitHub/createWorkflows.test.ts @@ -66,16 +66,75 @@ describe("createWorkflows", () => { issues: write pull-requests: write ", - "build.yml": "jobs: + "ci.yml": "jobs: build: + name: Build runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: ./.github/actions/prepare - run: pnpm build - run: node ./lib/index.js + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/prepare + - run: pnpm build + - run: pnpm lint + lint_knip: + name: Lint Knip + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/prepare + - run: pnpm lint:knip + lint_markdown: + name: Lint Markdown + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/prepare + - run: pnpm lint:md + lint_packages: + name: Lint Packages + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/prepare + - run: pnpm lint:packages + lint_spelling: + name: Lint Spelling + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/prepare + - run: pnpm lint:spelling + prettier: + name: Prettier + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/prepare + - run: pnpm format --list-different + test: + name: Test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/prepare + - run: pnpm run test --coverage + - uses: codecov/codecov-action@v3 + type_check: + name: Type Check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/prepare + - run: pnpm tsc - name: Build + name: CI on: pull_request: ~ @@ -130,87 +189,6 @@ describe("createWorkflows", () => { push: branches: - main - ", - "lint-knip.yml": "jobs: - lint_knip: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/prepare - - run: pnpm lint:knip - - name: Lint Knip - - on: - pull_request: ~ - push: - branches: - - main - ", - "lint-markdown.yml": "jobs: - lint_markdown: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/prepare - - run: pnpm lint:md - - name: Lint Markdown - - on: - pull_request: ~ - push: - branches: - - main - ", - "lint-packages.yml": "jobs: - lint_packages: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/prepare - - run: pnpm lint:packages - - name: Lint Packages - - on: - pull_request: ~ - push: - branches: - - main - ", - "lint-spelling.yml": "jobs: - lint_spelling: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/prepare - - run: pnpm lint:spelling - - name: Lint spelling - - on: - pull_request: ~ - push: - branches: - - main - ", - "lint.yml": "jobs: - lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/prepare - - run: pnpm build - - run: pnpm lint - - name: Lint - - on: - pull_request: ~ - push: - branches: - - main ", "post-release.yml": "jobs: post_release: @@ -261,22 +239,6 @@ describe("createWorkflows", () => { permissions: pull-requests: write - ", - "prettier.yml": "jobs: - prettier: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/prepare - - run: pnpm format --list-different - - name: Prettier - - on: - pull_request: ~ - push: - branches: - - main ", "release.yml": "concurrency: group: \${{ github.workflow }} @@ -306,40 +268,6 @@ describe("createWorkflows", () => { permissions: contents: write id-token: write - ", - "test.yml": "jobs: - test: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/prepare - - run: pnpm run test --coverage - - name: Codecov - uses: codecov/codecov-action@v3 - - name: Test - - on: - pull_request: ~ - push: - branches: - - main - ", - "tsc.yml": "jobs: - type_check: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/prepare - - run: pnpm tsc - - name: Type Check - - on: - pull_request: ~ - push: - branches: - - main ", } `); @@ -377,32 +305,38 @@ describe("createWorkflows", () => { issues: write pull-requests: write ", - "build.yml": "jobs: + "ci.yml": "jobs: build: + name: Build runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: ./.github/actions/prepare - run: pnpm build - run: node ./lib/index.js - - name: Build - - on: - pull_request: ~ - push: - branches: - - main - ", - "lint.yml": "jobs: lint: + name: Lint runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: ./.github/actions/prepare - run: pnpm lint + prettier: + name: Prettier + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/prepare + - run: pnpm format --list-different + type_check: + name: Type Check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/prepare + - run: pnpm tsc - name: Lint + name: CI on: pull_request: ~ @@ -431,38 +365,6 @@ describe("createWorkflows", () => { permissions: pull-requests: write - ", - "prettier.yml": "jobs: - prettier: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/prepare - - run: pnpm format --list-different - - name: Prettier - - on: - pull_request: ~ - push: - branches: - - main - ", - "tsc.yml": "jobs: - type_check: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/prepare - - run: pnpm tsc - - name: Type Check - - on: - pull_request: ~ - push: - branches: - - main ", } `); diff --git a/src/steps/writing/creation/dotGitHub/createWorkflows.ts b/src/steps/writing/creation/dotGitHub/createWorkflows.ts index 3b3014320..fd0378a2e 100644 --- a/src/steps/writing/creation/dotGitHub/createWorkflows.ts +++ b/src/steps/writing/creation/dotGitHub/createWorkflows.ts @@ -1,46 +1,102 @@ -/* spellchecker: disable */ import { Options } from "../../../../shared/types.js"; -import { createWorkflowFile } from "./createWorkflowFile.js"; +import { createMultiWorkflowFile } from "./createMultiWorkflowFile.js"; +import { createSoloWorkflowFile } from "./createSoloWorkflowFile.js"; export function createWorkflows(options: Options) { return { - "build.yml": createWorkflowFile({ - name: "Build", - runs: ["pnpm build", "node ./lib/index.js"], - }), - "pr-review-requested.yml": createWorkflowFile({ - name: "PR Review Requested", + "accessibility-alt-text-bot.yml": createSoloWorkflowFile({ + if: "${{ !endsWith(github.actor, '[bot]') }}", + name: "Accessibility Alt Text Bot", on: { - pull_request_target: { - types: ["review_requested"], + issue_comment: { + types: ["created", "edited"], + }, + issues: { + types: ["edited", "opened"], + }, + pull_request: { + types: ["edited", "opened"], }, }, permissions: { + issues: "write", "pull-requests": "write", }, steps: [ { - uses: "actions-ecosystem/action-remove-labels@v1", - with: { - labels: "status: waiting for author", - }, + uses: "github/accessibility-alt-text-bot@v1.4.0", }, + ], + }), + "ci.yml": createMultiWorkflowFile({ + jobs: [ { - if: "failure()", - run: 'echo "Don\'t worry if the previous step failed."\necho "See https://github.com/actions-ecosystem/action-remove-labels/issues/221."\n', + name: "Build", + steps: [{ run: "pnpm build" }, { run: "node ./lib/index.js" }], }, + { + name: "Prettier", + steps: [{ run: "pnpm format --list-different" }], + }, + { + name: "Type Check", + steps: [{ run: "pnpm tsc" }], + }, + { + name: "Lint", + steps: [ + ...(options.bin ? [{ run: "pnpm build" }] : []), + { run: "pnpm lint" }, + ], + }, + ...(options.excludeLintKnip + ? [] + : [ + { + name: "Lint Knip", + steps: [{ run: "pnpm lint:knip" }], + }, + ]), + ...(options.excludeLintMd + ? [] + : [ + { + name: "Lint Markdown", + steps: [{ run: "pnpm lint:md" }], + }, + ]), + ...(options.excludeLintPackages + ? [] + : [ + { + name: "Lint Packages", + steps: [{ run: "pnpm lint:packages" }], + }, + ]), + ...(options.excludeLintSpelling + ? [] + : [ + { + name: "Lint Spelling", + steps: [{ run: "pnpm lint:spelling" }], + }, + ]), + ...(options.excludeTests + ? [] + : [ + { + name: "Test", + steps: [ + { run: "pnpm run test --coverage" }, + { uses: "codecov/codecov-action@v3" }, + ], + }, + ]), ], - }), - "prettier.yml": createWorkflowFile({ - name: "Prettier", - runs: ["pnpm format --list-different"], - }), - "tsc.yml": createWorkflowFile({ - name: "Type Check", - runs: ["pnpm tsc"], + name: "CI", }), ...(!options.excludeCompliance && { - "compliance.yml": createWorkflowFile({ + "compliance.yml": createSoloWorkflowFile({ name: "Compliance", on: { pull_request: { @@ -72,7 +128,7 @@ export function createWorkflows(options: Options) { }), }), ...(!options.excludeAllContributors && { - "contributors.yml": createWorkflowFile({ + "contributors.yml": createSoloWorkflowFile({ name: "Contributors", on: { push: { @@ -89,60 +145,8 @@ export function createWorkflows(options: Options) { ], }), }), - "accessibility-alt-text-bot.yml": createWorkflowFile({ - if: "${{ !endsWith(github.actor, '[bot]') }}", - name: "Accessibility Alt Text Bot", - on: { - issue_comment: { - types: ["created", "edited"], - }, - issues: { - types: ["edited", "opened"], - }, - pull_request: { - types: ["edited", "opened"], - }, - }, - permissions: { - issues: "write", - "pull-requests": "write", - }, - steps: [ - { - uses: "github/accessibility-alt-text-bot@v1.4.0", - }, - ], - }), - "lint.yml": createWorkflowFile({ - name: "Lint", - runs: [...(options.bin ? ["pnpm build"] : []), "pnpm lint"], - }), - ...(!options.excludeLintKnip && { - "lint-knip.yml": createWorkflowFile({ - name: "Lint Knip", - runs: ["pnpm lint:knip"], - }), - }), - ...(!options.excludeLintMd && { - "lint-markdown.yml": createWorkflowFile({ - name: "Lint Markdown", - runs: ["pnpm lint:md"], - }), - }), - ...(!options.excludeLintPackages && { - "lint-packages.yml": createWorkflowFile({ - name: "Lint Packages", - runs: ["pnpm lint:packages"], - }), - }), - ...(!options.excludeLintSpelling && { - "lint-spelling.yml": createWorkflowFile({ - name: "Lint spelling", - runs: ["pnpm lint:spelling"], - }), - }), ...(!options.excludeReleases && { - "post-release.yml": createWorkflowFile({ + "post-release.yml": createSoloWorkflowFile({ name: "Post Release", on: { release: { @@ -172,7 +176,32 @@ export function createWorkflows(options: Options) { }, ], }), - "release.yml": createWorkflowFile({ + }), + "pr-review-requested.yml": createSoloWorkflowFile({ + name: "PR Review Requested", + on: { + pull_request_target: { + types: ["review_requested"], + }, + }, + permissions: { + "pull-requests": "write", + }, + steps: [ + { + uses: "actions-ecosystem/action-remove-labels@v1", + with: { + labels: "status: waiting for author", + }, + }, + { + if: "failure()", + run: 'echo "Don\'t worry if the previous step failed."\necho "See https://github.com/actions-ecosystem/action-remove-labels/issues/221."\n', + }, + ], + }), + ...(!options.excludeReleases && { + "release.yml": createSoloWorkflowFile({ concurrency: { group: "${{ github.workflow }}", }, @@ -210,19 +239,5 @@ export function createWorkflows(options: Options) { ], }), }), - ...(!options.excludeTests && { - "test.yml": createWorkflowFile({ - name: "Test", - steps: [ - { uses: "actions/checkout@v4" }, - { uses: "./.github/actions/prepare" }, - { run: "pnpm run test --coverage" }, - { - name: "Codecov", - uses: "codecov/codecov-action@v3", - }, - ], - }), - }), }; } diff --git a/src/steps/writing/creation/dotGitHub/formatWorkflowYaml.ts b/src/steps/writing/creation/dotGitHub/formatWorkflowYaml.ts new file mode 100644 index 000000000..b2dbfefe6 --- /dev/null +++ b/src/steps/writing/creation/dotGitHub/formatWorkflowYaml.ts @@ -0,0 +1,12 @@ +import { formatYaml } from "../formatters/formatYaml.js"; + +export function formatWorkflowYaml(value: unknown) { + return ( + formatYaml(value) + .replaceAll(/\n(\S)/g, "\n\n$1") + // https://github.com/nodeca/js-yaml/pull/515 + .replaceAll(/: "\\n(.+)"/g, ": |\n$1") + .replaceAll("\\n", "\n") + .replaceAll("\\t", " ") + ); +}