Skip to content

Commit d88332a

Browse files
feat: add intake method to blockCodecov (#2078)
## PR Checklist - [x] Addresses an existing open issue: fixes #2076 - [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 Attempts to load an existing `ci.yml` as JSON and find the Codecov step. If that step exists and has an `env`, hooray! 🎁
1 parent 2167b9d commit d88332a

8 files changed

+347
-53
lines changed

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
"*": "prettier --ignore-unknown --write"
3838
},
3939
"dependencies": {
40-
"bingo": "^0.5.11",
41-
"bingo-fs": "^0.5.4",
42-
"bingo-stratum": "^0.5.8",
40+
"bingo": "^0.5.12",
41+
"bingo-fs": "^0.5.5",
42+
"bingo-stratum": "^0.5.9",
4343
"cached-factory": "^0.1.0",
4444
"cspell-populate-words": "^0.3.0",
4545
"execa": "^9.5.2",
@@ -86,7 +86,7 @@
8686
"@vitest/eslint-plugin": "1.1.38",
8787
"all-contributors-cli": "6.26.1",
8888
"bingo-requests": "0.5.5",
89-
"bingo-stratum-testers": "0.5.7",
89+
"bingo-stratum-testers": "0.5.8",
9090
"bingo-testers": "0.5.7",
9191
"console-fail-test": "0.5.0",
9292
"cspell": "8.17.5",

pnpm-lock.yaml

+45-45
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/blocks/blockCodecov.test.ts

+140-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { testBlock } from "bingo-stratum-testers";
2-
import { describe, expect, test } from "vitest";
1+
import { testBlock, testIntake } from "bingo-stratum-testers";
2+
import jsYaml from "js-yaml";
3+
import { describe, expect, it, test } from "vitest";
34

45
import { blockCodecov } from "./blockCodecov.js";
56
import { optionsBase } from "./options.fakes.js";
@@ -52,7 +53,7 @@ describe("blockCodecov", () => {
5253
`);
5354
});
5455

55-
test("transition mode", () => {
56+
test("transition mode without files", () => {
5657
const creation = testBlock(blockCodecov, {
5758
mode: "transition",
5859
options: optionsBase,
@@ -163,4 +164,140 @@ describe("blockCodecov", () => {
163164
}
164165
`);
165166
});
167+
168+
describe("intake", () => {
169+
it("returns undefined when ci.yml does not exist", () => {
170+
const actual = testIntake(blockCodecov, {
171+
files: {
172+
".github": {
173+
workflows: {},
174+
},
175+
},
176+
});
177+
178+
expect(actual).toBeUndefined();
179+
});
180+
181+
it("returns undefined when ci.yml contains invalid yml", () => {
182+
const actual = testIntake(blockCodecov, {
183+
files: {
184+
".github": {
185+
workflows: {
186+
"ci.yml": ["invalid yml!"],
187+
},
188+
},
189+
},
190+
});
191+
192+
expect(actual).toBeUndefined();
193+
});
194+
195+
it("returns undefined when ci.yml does not contain a test job", () => {
196+
const actual = testIntake(blockCodecov, {
197+
files: {
198+
".github": {
199+
workflows: {
200+
"ci.yml": [
201+
jsYaml.dump({
202+
jobs: {
203+
other: {
204+
name: "Other",
205+
steps: [],
206+
},
207+
},
208+
}),
209+
],
210+
},
211+
},
212+
},
213+
});
214+
215+
expect(actual).toBeUndefined();
216+
});
217+
218+
it("returns undefined when ci.yml contains a test job with only non-string uses", () => {
219+
const actual = testIntake(blockCodecov, {
220+
files: {
221+
".github": {
222+
workflows: {
223+
"ci.yml": [
224+
jsYaml.dump({
225+
jobs: {
226+
test: {
227+
name: "Test",
228+
steps: [
229+
{
230+
uses: { not: "a string" },
231+
},
232+
],
233+
},
234+
},
235+
}),
236+
],
237+
},
238+
},
239+
},
240+
});
241+
242+
expect(actual).toBeUndefined();
243+
});
244+
245+
it("returns undefined env when ci.yml contains a test job with no env in its codecov step", () => {
246+
const actual = testIntake(blockCodecov, {
247+
files: {
248+
".github": {
249+
workflows: {
250+
"ci.yml": [
251+
jsYaml.dump({
252+
jobs: {
253+
test: {
254+
name: "Test",
255+
steps: [
256+
{
257+
uses: "codecov/codecov-action@v3",
258+
},
259+
],
260+
},
261+
},
262+
}),
263+
],
264+
},
265+
},
266+
},
267+
});
268+
269+
expect(actual).toEqual({ env: undefined });
270+
});
271+
272+
it("returns env when ci.yml contains a test job with env in its codecov step", () => {
273+
const env = {
274+
CODECOV_TOKEN: "${{ secrets.CODECOV_TOKEN }}",
275+
};
276+
const actual = testIntake(blockCodecov, {
277+
files: {
278+
".github": {
279+
workflows: {
280+
"ci.yml": [
281+
jsYaml.dump({
282+
jobs: {
283+
test: {
284+
name: "Test",
285+
steps: [
286+
{
287+
env,
288+
uses: "codecov/codecov-action@v3",
289+
},
290+
],
291+
},
292+
},
293+
}),
294+
],
295+
},
296+
},
297+
},
298+
});
299+
300+
expect(actual).toEqual({ env });
301+
});
302+
});
166303
});

0 commit comments

Comments
 (0)