Skip to content

Commit 57f70c3

Browse files
feat: add opt-in Block for automatic CTA transitions for Renovate (#2000)
## PR Checklist - [x] Addresses an existing open issue: fixes #1965 - [x] That issue was marked as [`status: accepting prs`](https://github.com/JoshuaKGoldberg/create-typescript-app/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22) - [x] Steps in [CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/create-typescript-app/blob/main/.github/CONTRIBUTING.md) were taken ## Overview Adds an opt-in `blockCTATransitions` that creates a CI step to run `npx create-typescript-app` and check in any updates. This will only run on `renovate/*` branches with `create-typescript-app` in the title. I'm not documenting the action in this PR yet. It'll likely change as I roll it out to repos (#1966). First preview usage in JoshuaKGoldberg/all-contributors-for-repository#772. 🎁
1 parent 552aadd commit 57f70c3

10 files changed

+438
-12
lines changed

cspell.json

+3
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@
1414
"apexskier",
1515
"attw",
1616
"automerge",
17+
"boop",
1718
"dbaeumer",
1819
"infile",
1920
"joshuakgoldberg",
2021
"markdownlintignore",
22+
"mshick",
2123
"mtfoley",
2224
"npmjs",
25+
"stefanzweifel",
2326
"tseslint"
2427
]
2528
}

knip.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"ignoreDependencies": [
55
"all-contributors-cli",
66
"cspell-populate-words",
7-
"remove-dependencies"
7+
"remove-dependencies",
8+
"trash-cli"
89
],
910
"ignoreExportsUsedInFile": { "interface": true, "type": true },
1011
"project": ["src/**/*.ts"]

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"dependencies": {
4040
"bingo": "^0.5.8",
4141
"bingo-fs": "^0.5.4",
42-
"bingo-stratum": "^0.5.5",
42+
"bingo-stratum": "^0.5.7",
4343
"cspell-populate-words": "^0.3.0",
4444
"execa": "^9.5.2",
4545
"git-url-parse": "^16.0.1",
@@ -63,6 +63,7 @@
6363
"sort-keys": "^5.1.0",
6464
"sort-package-json": "^3.0.0",
6565
"title-case": "^4.3.2",
66+
"trash-cli": "^6.0.0",
6667
"zod": "^3.24.2",
6768
"zod-package-json": "^1.1.0"
6869
},

pnpm-lock.yaml

+278-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { testBlock } from "bingo-stratum-testers";
2+
import { describe, expect, test } from "vitest";
3+
4+
import { blockCTATransitions } from "./blockCTATransitions.js";
5+
import { optionsBase } from "./options.fakes.js";
6+
7+
describe("blockCTATransitions", () => {
8+
test("production", () => {
9+
const creation = testBlock(blockCTATransitions, {
10+
options: optionsBase,
11+
});
12+
13+
expect(creation).toMatchInlineSnapshot(`
14+
{
15+
"addons": [
16+
{
17+
"addons": {
18+
"jobs": [
19+
{
20+
"checkoutWith": {
21+
"fetch-depth": "0",
22+
"ref": "\${{github.event.pull_request.head.ref}}",
23+
"repository": "\${{github.event.pull_request.head.repo.full_name}}",
24+
"token": ""\${{ secrets.ACCESS_TOKEN }}"",
25+
},
26+
"if": "\${{ startsWith(github.head_ref, 'renovate/') && contains(github.event.pull_request.title, 'create-typescript-app') }}",
27+
"name": "CTA Transitions",
28+
"steps": [
29+
{
30+
"run": "pnpx create-typescript-app",
31+
},
32+
{
33+
"uses": "stefanzweifel/git-auto-commit-action@v5",
34+
"with": {
35+
"commit_author": "The Friendly Bingo Bot <[email protected]>",
36+
"commit_message": "Check in changes from re-running npx create-typescript-app",
37+
"commit_user_email": "[email protected]",
38+
"commit_user_name": "The Friendly Bingo Bot",
39+
},
40+
},
41+
{
42+
"uses": "mshick/add-pr-comment@v2",
43+
"with": {
44+
"issue": "\${{ github.event.pull_request.number }}",
45+
"message": "|
46+
🤖 Beep boop! I ran \`npx create-typescript-app\` and found same changes.
47+
Please review the latest commit to see if you want to merge it.
48+
Cheers! 💝
49+
50+
> 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).
51+
> If you want to opt out of these automatic updates, delete the \`.github/workflows/cta-transitions.yml\` file on your \`main\` branch.",
52+
"repo-token": "\${{ secrets.ACCESS_TOKEN }}",
53+
},
54+
},
55+
],
56+
},
57+
],
58+
},
59+
"block": [Function],
60+
},
61+
{
62+
"addons": {
63+
"properties": {
64+
"devDependencies": {
65+
"create-typescript-app": "2.7.3",
66+
},
67+
},
68+
},
69+
"block": [Function],
70+
},
71+
],
72+
}
73+
`);
74+
});
75+
});

src/blocks/blockCTATransitions.ts

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { base } from "../base.js";
2+
import { packageData } from "../data/packageData.js";
3+
import { blockGitHubActionsCI } from "./blockGitHubActionsCI.js";
4+
import { blockPackageJson } from "./blockPackageJson.js";
5+
6+
export const blockCTATransitions = base.createBlock({
7+
about: {
8+
name: "CTA Transitions",
9+
},
10+
produce() {
11+
return {
12+
addons: [
13+
blockGitHubActionsCI({
14+
jobs: [
15+
{
16+
checkoutWith: {
17+
"fetch-depth": "0",
18+
ref: "${{github.event.pull_request.head.ref}}",
19+
repository:
20+
"${{github.event.pull_request.head.repo.full_name}}",
21+
token: '"${{ secrets.ACCESS_TOKEN }}"',
22+
},
23+
if: "${{ startsWith(github.head_ref, 'renovate/') && contains(github.event.pull_request.title, 'create-typescript-app') }}",
24+
name: "CTA Transitions",
25+
steps: [
26+
{ run: "pnpx create-typescript-app" },
27+
{
28+
uses: "stefanzweifel/git-auto-commit-action@v5",
29+
with: {
30+
commit_author: "The Friendly Bingo Bot <[email protected]>",
31+
commit_message:
32+
"Check in changes from re-running npx create-typescript-app",
33+
commit_user_email: "[email protected]",
34+
commit_user_name: "The Friendly Bingo Bot",
35+
},
36+
},
37+
{
38+
uses: "mshick/add-pr-comment@v2",
39+
with: {
40+
issue: "${{ github.event.pull_request.number }}",
41+
message: [
42+
"|",
43+
"🤖 Beep boop! I ran `npx create-typescript-app` and found same changes.",
44+
"Please review the latest commit to see if you want to merge it.",
45+
"Cheers! 💝",
46+
"",
47+
"> 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).",
48+
"> If you want to opt out of these automatic updates, delete the `.github/workflows/cta-transitions.yml` file on your `main` branch.",
49+
].join("\n"),
50+
"repo-token": "${{ secrets.ACCESS_TOKEN }}",
51+
},
52+
},
53+
],
54+
},
55+
],
56+
}),
57+
blockPackageJson({
58+
properties: {
59+
devDependencies: {
60+
"create-typescript-app": packageData.version,
61+
},
62+
},
63+
}),
64+
],
65+
};
66+
},
67+
});

src/blocks/blockGitHubActionsCI.ts

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ export const blockGitHubActionsCI = base.createBlock({
2424
jobs: z
2525
.array(
2626
z.object({
27+
checkoutWith: z.record(z.string(), z.string()).optional(),
28+
if: z.string().optional(),
2729
name: z.string(),
2830
steps: z.array(zActionStep),
2931
}),

src/blocks/files/createMultiWorkflowFile.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ export interface MultiWorkflowFileOptions {
77
}
88

99
export interface MultiWorkflowJobOptions {
10+
checkoutWith?: Record<string, string>;
11+
if?: string;
1012
name: string;
1113
steps: MultiWorkflowJobStep[];
1214
}
@@ -25,10 +27,11 @@ export function createMultiWorkflowFile({
2527
jobs.map((job) => [
2628
createJobName(job.name),
2729
{
30+
if: job.if,
2831
name: job.name,
2932
"runs-on": "ubuntu-latest",
3033
steps: [
31-
{ uses: "actions/checkout@v4" },
34+
{ uses: "actions/checkout@v4", with: job.checkoutWith },
3235
{ uses: "./.github/actions/prepare" },
3336
...job.steps,
3437
],

src/blocks/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export { blockCodecov } from "./blockCodecov.js";
9494
export { blockContributingDocs } from "./blockContributingDocs.js";
9595
export { blockContributorCovenant } from "./blockContributorCovenant.js";
9696
export { blockCSpell } from "./blockCSpell.js";
97+
export { blockCTATransitions } from "./blockCTATransitions.js";
9798
export { blockDevelopmentDocs } from "./blockDevelopmentDocs.js";
9899
export { blockESLint } from "./blockESLint.js";
99100
export { blockESLintComments } from "./blockESLintComments.js";

src/integration.test.ts

+4
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,15 @@ test("Producing the everything preset matches the files in this repository", asy
5353
"Anson",
5454
"apexskier",
5555
"attw",
56+
"boop",
5657
"dbaeumer",
5758
"infile",
5859
"joshuakgoldberg",
5960
"markdownlintignore",
61+
"mshick",
6062
"mtfoley",
6163
"npmjs",
64+
"stefanzweifel",
6265
],
6366
}),
6467
blockESLint({
@@ -93,6 +96,7 @@ If you're interested in learning more, see the 'getting started' docs on:
9396
"all-contributors-cli",
9497
"cspell-populate-words",
9598
"remove-dependencies",
99+
"trash-cli",
96100
],
97101
}),
98102
blockTSup({

0 commit comments

Comments
 (0)