-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: extract codecov uploading to a blockCodecov (#1865)
## PR Checklist - [x] Addresses an existing open issue: fixes #1848 - [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 Also removes `addons.flags` from `blockVitest` since this repo won't use them after #1839. 💖
- Loading branch information
1 parent
66db26e
commit 444de1c
Showing
6 changed files
with
195 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import { testBlock } from "create-testers"; | ||
import { describe, expect, test } from "vitest"; | ||
|
||
import { blockCodecov } from "./blockCodecov.js"; | ||
import { optionsBase } from "./options.fakes.js"; | ||
|
||
describe("blockCodecov", () => { | ||
test("without addons or mode", () => { | ||
const creation = testBlock(blockCodecov, { | ||
options: optionsBase, | ||
}); | ||
|
||
expect(creation).toMatchInlineSnapshot(` | ||
{ | ||
"addons": [ | ||
{ | ||
"addons": { | ||
"apps": [ | ||
{ | ||
"name": "Codecov", | ||
"url": "https://github.com/apps/codecov", | ||
}, | ||
], | ||
}, | ||
"block": [Function], | ||
}, | ||
{ | ||
"addons": { | ||
"actionSteps": [ | ||
{ | ||
"if": "always()", | ||
"uses": "codecov/codecov-action@v3", | ||
}, | ||
], | ||
}, | ||
"block": [Function], | ||
}, | ||
], | ||
} | ||
`); | ||
}); | ||
|
||
test("migration mode", () => { | ||
const creation = testBlock(blockCodecov, { | ||
mode: "migrate", | ||
options: optionsBase, | ||
}); | ||
|
||
expect(creation).toMatchInlineSnapshot(` | ||
{ | ||
"addons": [ | ||
{ | ||
"addons": { | ||
"apps": [ | ||
{ | ||
"name": "Codecov", | ||
"url": "https://github.com/apps/codecov", | ||
}, | ||
], | ||
}, | ||
"block": [Function], | ||
}, | ||
{ | ||
"addons": { | ||
"actionSteps": [ | ||
{ | ||
"if": "always()", | ||
"uses": "codecov/codecov-action@v3", | ||
}, | ||
], | ||
}, | ||
"block": [Function], | ||
}, | ||
], | ||
"scripts": [ | ||
{ | ||
"commands": [ | ||
"rm .github/codecov.yml codecov.yml", | ||
], | ||
"phase": 0, | ||
}, | ||
], | ||
} | ||
`); | ||
}); | ||
|
||
test("with addons", () => { | ||
const creation = testBlock(blockCodecov, { | ||
addons: { | ||
env: { | ||
CODECOV_TOKEN: "${{ secrets.CODECOV_TOKEN }}", | ||
}, | ||
}, | ||
options: optionsBase, | ||
}); | ||
|
||
expect(creation).toMatchInlineSnapshot(` | ||
{ | ||
"addons": [ | ||
{ | ||
"addons": { | ||
"apps": [ | ||
{ | ||
"name": "Codecov", | ||
"url": "https://github.com/apps/codecov", | ||
}, | ||
], | ||
}, | ||
"block": [Function], | ||
}, | ||
{ | ||
"addons": { | ||
"actionSteps": [ | ||
{ | ||
"env": { | ||
"CODECOV_TOKEN": "\${{ secrets.CODECOV_TOKEN }}", | ||
}, | ||
"if": "always()", | ||
"uses": "codecov/codecov-action@v3", | ||
}, | ||
], | ||
}, | ||
"block": [Function], | ||
}, | ||
], | ||
} | ||
`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { z } from "zod"; | ||
|
||
import { base } from "../base.js"; | ||
import { blockGitHubApps } from "./blockGitHubApps.js"; | ||
import { blockVitest } from "./blockVitest.js"; | ||
import { CommandPhase } from "./phases.js"; | ||
|
||
export const blockCodecov = base.createBlock({ | ||
about: { | ||
name: "Codecov", | ||
}, | ||
addons: { env: z.record(z.string(), z.string()).optional() }, | ||
migrate() { | ||
return { | ||
scripts: [ | ||
{ | ||
commands: ["rm .github/codecov.yml codecov.yml"], | ||
phase: CommandPhase.Migrations, | ||
}, | ||
], | ||
}; | ||
}, | ||
produce({ addons }) { | ||
const { env } = addons; | ||
return { | ||
addons: [ | ||
blockGitHubApps({ | ||
apps: [ | ||
{ | ||
name: "Codecov", | ||
url: "https://github.com/apps/codecov", | ||
}, | ||
], | ||
}), | ||
blockVitest({ | ||
actionSteps: [ | ||
{ | ||
...(env && { env }), | ||
if: "always()", | ||
uses: "codecov/codecov-action@v3", | ||
}, | ||
], | ||
}), | ||
], | ||
}; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.