Skip to content

feat: standalone CTA Transitions workflow #2012

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

Merged
merged 4 commits into from
Mar 25, 2025
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
148 changes: 87 additions & 61 deletions src/blocks/blockCTATransitions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { describe, expect, test } from "vitest";

import { packageData } from "../data/packageData.js";
import { blockCTATransitions } from "./blockCTATransitions.js";
import { blockGitHubActionsCI } from "./blockGitHubActionsCI.js";
import { blockPackageJson } from "./blockPackageJson.js";
import { blockRepositoryBranchRuleset } from "./blockRepositoryBranchRuleset.js";
import { optionsBase } from "./options.fakes.js";

describe("blockCTATransitions", () => {
Expand All @@ -13,67 +13,93 @@ describe("blockCTATransitions", () => {
options: optionsBase,
});

expect(creation).toEqual({
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: blockGitHubActionsCI,
},
{
addons: {
properties: {
devDependencies: {
"create-typescript-app": packageData.version,
},
},
expect(creation.addons).toEqual([
blockPackageJson({
properties: {
devDependencies: {
"create-typescript-app": packageData.version,
},
block: blockPackageJson,
},
],
});
}),
blockRepositoryBranchRuleset({
requiredStatusChecks: ["Transition"],
}),
]);
expect(creation.files).toMatchInlineSnapshot(`
{
".github": {
"actions": {
"transition": {
"action.yml": "description: Runs create-typescript-app in transition mode

name: Transition

runs:
steps:
- uses: ./.github/actions/prepare
- run: pnpx create-typescript-app
shell: bash
- id: auto-commit-action
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
- if: steps.auto-commit-action.outputs.changes_detected == 'true'
uses: mshick/add-pr-comment@v2
with:
issue: \${{ github.event.pull_request.number }}
message: >-
🤖 Beep boop! I ran \`pnpx create-typescript-app\` and it updated some
files.

I went ahead and checked those changes into this PR for you. Please
review the latest commit to see if you want to merge it.

Cheers!
— _The Friendly Bingo Bot_ 💝

> ℹ️ These automatic commits keep your repository up-to-date with new
versions of
[create-typescript-app](https://github.com/JoshuaKGoldberg/create-typescript-app).
If you want to opt out, delete your
\`.github/workflows/cta-transitions.yml\` file.
using: composite
",
},
},
"workflows": {
"cta.yml": "jobs:
transition:
name: Transition
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: \${{github.event.pull_request.head.ref}}
repository: \${{github.event.pull_request.head.repo.full_name}}
token: \${{ secrets.ACCESS_TOKEN }}
- id: check
if: (github.actor == 'test-owner' || github.actor == 'renovate[bot]') && startsWith(github.head_ref, 'renovate/') && contains(github.event.pull_request.title, 'create-typescript-app')
uses: ./.github/actions/transition
- if: steps.check.outcome == 'skipped'
run: echo 'Skipping transition mode because the PR does not appear to be an automated or owner-created update to create-typescript-app.'

name: CTA

on:
pull_request:
branches:
- main

permissions:
pull-requests: write
",
},
},
}
`);
});
});
137 changes: 89 additions & 48 deletions src/blocks/blockCTATransitions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { base } from "../base.js";
import { packageData } from "../data/packageData.js";
import { resolveUses } from "./actions/resolveUses.js";
import { blockGitHubActionsCI } from "./blockGitHubActionsCI.js";
import { blockPackageJson } from "./blockPackageJson.js";
import { blockRepositoryBranchRuleset } from "./blockRepositoryBranchRuleset.js";
import { createSoloWorkflowFile } from "./files/createSoloWorkflowFile.js";
import { formatYamlAction } from "./files/formatYamlAction.js";

export const blockCTATransitions = base.createBlock({
about: {
Expand All @@ -11,66 +13,105 @@ export const blockCTATransitions = base.createBlock({
produce({ options }) {
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 }}"',
blockPackageJson({
properties: {
devDependencies: {
"create-typescript-app": packageData.version,
},
},
}),
blockRepositoryBranchRuleset({
requiredStatusChecks: ["Transition"],
}),
],
files: {
".github": {
actions: {
transition: {
"action.yml": formatYamlAction({
description: "Runs create-typescript-app in transition mode",
name: "Transition",
runs: {
steps: [
{ uses: "./.github/actions/prepare" },
{
run: "pnpx create-typescript-app",
shell: "bash",
},
{
id: "auto-commit-action",
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",
},
},
{
if: "steps.auto-commit-action.outputs.changes_detected == 'true'",
uses: "mshick/add-pr-comment@v2",
with: {
issue: "${{ github.event.pull_request.number }}",
message: [
"🤖 Beep boop! I ran `pnpx create-typescript-app` and it updated some files.",
"I went ahead and checked those changes into this PR for you. Please review the latest commit to see if you want to merge it.",
"Cheers!",
" — _The Friendly Bingo Bot_ 💝",
"",
"> ℹ️ These automatic commits keep your repository up-to-date with new versions of [create-typescript-app](https://github.com/JoshuaKGoldberg/create-typescript-app). If you want to opt out, delete your `.github/workflows/cta-transitions.yml` file.",
].join("\n"),
},
},
],
using: "composite",
},
}),
},
},
workflows: {
"cta.yml": createSoloWorkflowFile({
jobName: "Transition",
name: "CTA",
on: {
pull_request: {
branches: ["main"],
},
},
permissions: {
"pull-requests": "write",
},
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: resolveUses(
"stefanzweifel/git-auto-commit-action",
"v5",
"actions/checkout",
"v4",
options.workflowsVersions,
),
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",
"fetch-depth": 0,
ref: "${{github.event.pull_request.head.ref}}",
repository:
"${{github.event.pull_request.head.repo.full_name}}",
token: "${{ secrets.ACCESS_TOKEN }}",
},
},
{
uses: resolveUses(
"mshick/add-pr-comment",
"v2",
options.workflowsVersions,
),
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 }}",
},
id: "check",
if: `(github.actor == '${options.owner}' || github.actor == 'renovate[bot]') && startsWith(github.head_ref, 'renovate/') && contains(github.event.pull_request.title, 'create-typescript-app')`,
uses: "./.github/actions/transition",
},
{
if: "steps.check.outcome == 'skipped'",
run: "echo 'Skipping transition mode because the PR does not appear to be an automated or owner-created update to create-typescript-app.'",
},
],
},
],
}),
blockPackageJson({
properties: {
devDependencies: {
"create-typescript-app": packageData.version,
},
}),
},
}),
],
},
},
};
},
});
Loading