Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add opt-in Block for automatic CTA transitions for Renovate #2000

Merged
merged 10 commits into from
Mar 21, 2025
3 changes: 3 additions & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@
"apexskier",
"attw",
"automerge",
"boop",
"dbaeumer",
"infile",
"joshuakgoldberg",
"markdownlintignore",
"mshick",
"mtfoley",
"npmjs",
"stefanzweifel",
"tseslint"
]
}
3 changes: 2 additions & 1 deletion knip.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"ignoreDependencies": [
"all-contributors-cli",
"cspell-populate-words",
"remove-dependencies"
"remove-dependencies",
"trash-cli"
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

],
"ignoreExportsUsedInFile": { "interface": true, "type": true },
"project": ["src/**/*.ts"]
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"dependencies": {
"bingo": "^0.5.8",
"bingo-fs": "^0.5.4",
"bingo-stratum": "^0.5.5",
"bingo-stratum": "^0.5.7",
"cspell-populate-words": "^0.3.0",
"execa": "^9.5.2",
"git-url-parse": "^16.0.1",
Expand All @@ -63,6 +63,7 @@
"sort-keys": "^5.1.0",
"sort-package-json": "^3.0.0",
"title-case": "^4.3.2",
"trash-cli": "^6.0.0",
"zod": "^3.24.2",
"zod-package-json": "^1.1.0"
},
Expand Down
287 changes: 278 additions & 9 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

75 changes: 75 additions & 0 deletions src/blocks/blockCTATransitions.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { testBlock } from "bingo-stratum-testers";
import { describe, expect, test } from "vitest";

import { blockCTATransitions } from "./blockCTATransitions.js";
import { optionsBase } from "./options.fakes.js";

describe("blockCTATransitions", () => {
test("production", () => {
const creation = testBlock(blockCTATransitions, {
options: optionsBase,
});

expect(creation).toMatchInlineSnapshot(`
{
"addons": [
{
"addons": {
"jobs": [
{
"checkoutWith": {
"fetch-depth": "0",
"ref": "\${{github.event.pull_request.head.ref}}",
"repository": "\${{github.event.pull_request.head.repo.full_name}}",
"token": ""\${{ secrets.ACCESS_TOKEN }}"",
},
"if": "\${{ startsWith(github.head_ref, 'renovate/') && contains(github.event.pull_request.title, 'create-typescript-app') }}",
"name": "CTA Transitions",
"steps": [
{
"run": "pnpx create-typescript-app",
},
{
"uses": "stefanzweifel/git-auto-commit-action@v5",
"with": {
"commit_author": "The Friendly Bingo Bot <[email protected]>",
"commit_message": "Check in changes from re-running npx create-typescript-app",
"commit_user_email": "[email protected]",
"commit_user_name": "The Friendly Bingo Bot",
},
},
{
"uses": "mshick/add-pr-comment@v2",
"with": {
"issue": "\${{ github.event.pull_request.number }}",
"message": "|
🤖 Beep boop! I ran \`npx create-typescript-app\` and found same changes.
Please review the latest commit to see if you want to merge it.
Cheers! 💝

> This change was automatically made in CI to keep your repository up-to-date with the templating in [create-typescript-app](https://github.com/JoshuaKGoldberg/create-typescript-app).
> If you want to opt out of these automatic updates, delete the \`.github/workflows/cta-transitions.yml\` file on your \`main\` branch.",
"repo-token": "\${{ secrets.ACCESS_TOKEN }}",
},
},
],
},
],
},
"block": [Function],
},
{
"addons": {
"properties": {
"devDependencies": {
"create-typescript-app": "2.7.3",
},
},
},
"block": [Function],
},
],
}
`);
});
});
67 changes: 67 additions & 0 deletions src/blocks/blockCTATransitions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { base } from "../base.js";
import { packageData } from "../data/packageData.js";
import { blockGitHubActionsCI } from "./blockGitHubActionsCI.js";
import { blockPackageJson } from "./blockPackageJson.js";

export const blockCTATransitions = base.createBlock({
about: {
name: "CTA Transitions",
},
produce() {
return {
addons: [
blockGitHubActionsCI({
jobs: [
{
checkoutWith: {
"fetch-depth": "0",
ref: "${{github.event.pull_request.head.ref}}",
repository:
"${{github.event.pull_request.head.repo.full_name}}",
token: '"${{ secrets.ACCESS_TOKEN }}"',
},
if: "${{ startsWith(github.head_ref, 'renovate/') && contains(github.event.pull_request.title, 'create-typescript-app') }}",
name: "CTA Transitions",
steps: [
{ run: "pnpx create-typescript-app" },
{
uses: "stefanzweifel/git-auto-commit-action@v5",
with: {
commit_author: "The Friendly Bingo Bot <[email protected]>",
commit_message:
"Check in changes from re-running npx create-typescript-app",
commit_user_email: "[email protected]",
commit_user_name: "The Friendly Bingo Bot",
},
},
{
uses: "mshick/add-pr-comment@v2",
with: {
issue: "${{ github.event.pull_request.number }}",
message: [
"|",
"🤖 Beep boop! I ran `npx create-typescript-app` and found same changes.",
"Please review the latest commit to see if you want to merge it.",
"Cheers! 💝",
"",
"> This change was automatically made in CI to keep your repository up-to-date with the templating in [create-typescript-app](https://github.com/JoshuaKGoldberg/create-typescript-app).",
"> If you want to opt out of these automatic updates, delete the `.github/workflows/cta-transitions.yml` file on your `main` branch.",
].join("\n"),
"repo-token": "${{ secrets.ACCESS_TOKEN }}",
},
},
],
},
],
}),
blockPackageJson({
properties: {
devDependencies: {
"create-typescript-app": packageData.version,
},
},
}),
],
};
},
});
2 changes: 2 additions & 0 deletions src/blocks/blockGitHubActionsCI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export const blockGitHubActionsCI = base.createBlock({
jobs: z
.array(
z.object({
checkoutWith: z.record(z.string(), z.string()).optional(),
if: z.string().optional(),
name: z.string(),
steps: z.array(zActionStep),
}),
Expand Down
5 changes: 4 additions & 1 deletion src/blocks/files/createMultiWorkflowFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export interface MultiWorkflowFileOptions {
}

export interface MultiWorkflowJobOptions {
checkoutWith?: Record<string, string>;
if?: string;
name: string;
steps: MultiWorkflowJobStep[];
}
Expand All @@ -25,10 +27,11 @@ export function createMultiWorkflowFile({
jobs.map((job) => [
createJobName(job.name),
{
if: job.if,
name: job.name,
"runs-on": "ubuntu-latest",
steps: [
{ uses: "actions/checkout@v4" },
{ uses: "actions/checkout@v4", with: job.checkoutWith },
{ uses: "./.github/actions/prepare" },
...job.steps,
],
Expand Down
1 change: 1 addition & 0 deletions src/blocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export { blockCodecov } from "./blockCodecov.js";
export { blockContributingDocs } from "./blockContributingDocs.js";
export { blockContributorCovenant } from "./blockContributorCovenant.js";
export { blockCSpell } from "./blockCSpell.js";
export { blockCTATransitions } from "./blockCTATransitions.js";
export { blockDevelopmentDocs } from "./blockDevelopmentDocs.js";
export { blockESLint } from "./blockESLint.js";
export { blockESLintComments } from "./blockESLintComments.js";
Expand Down
4 changes: 4 additions & 0 deletions src/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,15 @@ test("Producing the everything preset matches the files in this repository", asy
"Anson",
"apexskier",
"attw",
"boop",
"dbaeumer",
"infile",
"joshuakgoldberg",
"markdownlintignore",
"mshick",
"mtfoley",
"npmjs",
"stefanzweifel",
],
}),
blockESLint({
Expand Down Expand Up @@ -93,6 +96,7 @@ If you're interested in learning more, see the 'getting started' docs on:
"all-contributors-cli",
"cspell-populate-words",
"remove-dependencies",
"trash-cli",
],
}),
blockTSup({
Expand Down