-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from pipelinit/feat/include-version
Include a header in generated files
- Loading branch information
Showing
5 changed files
with
82 additions
and
10 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,48 @@ | ||
import { context } from "../../../src/plugin/mod.ts"; | ||
import { assertEquals, deepMerge } from "../../../deps.ts"; | ||
import { RenderedTemplate } from "../../../src/platform/plugin.ts"; | ||
|
||
import { github } from "./mod.ts"; | ||
|
||
const FAKE_VERSION = "v10.10.10"; | ||
|
||
// FIXME | ||
// This doesn't work: | ||
// deepMerge(context, { version: FAKE_VERSION }); | ||
// Why? | ||
const fakeContext = deepMerge(context, {}); | ||
fakeContext.version = FAKE_VERSION; | ||
|
||
const fakeYaml = ` | ||
name: Runner check | ||
on: pull_request | ||
jobs: | ||
stage: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- run: ls | ||
`; | ||
|
||
const fakeYamlWithHeader = `# Generated with pipelinit ${FAKE_VERSION} | ||
# https://pipelinit.com/ | ||
${fakeYaml}`; | ||
|
||
Deno.test("Plugins > GitHub - prepends a header to generated files", async () => { | ||
async function* templatesFixture(): AsyncIterableIterator<RenderedTemplate> { | ||
yield { | ||
name: "pipelinit.stage", | ||
content: fakeYaml, | ||
}; | ||
return; | ||
} | ||
const result = await github(fakeContext, templatesFixture()); | ||
assertEquals(result.length, 1); | ||
assertEquals( | ||
result, | ||
[{ | ||
path: ".github/workflows/pipelinit.stage.yaml", | ||
content: fakeYamlWithHeader, | ||
}], | ||
); | ||
}); |
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 |
---|---|---|
@@ -1,12 +1,17 @@ | ||
import { ensureFile, log, PlatformWriterFn } from "../deps.ts"; | ||
import { PlatformWriterFn } from "../deps.ts"; | ||
|
||
export const github: PlatformWriterFn = async (templates) => { | ||
const logger = log.getLogger("main"); | ||
export const github: PlatformWriterFn = async (context, templates) => { | ||
const header = ` | ||
# Generated with pipelinit ${context.version} | ||
# https://pipelinit.com/ | ||
`.trimStart(); | ||
const configurationFiles = []; | ||
for await (const template of templates) { | ||
const { name, content } = template; | ||
const filename = `.github/workflows/${name}.yaml`; | ||
logger.info(`Writing ${filename}`); | ||
await ensureFile(filename); | ||
await Deno.writeTextFile(filename, content); | ||
configurationFiles.push({ | ||
path: `.github/workflows/${name}.yaml`, | ||
content: `${header}${content}`, | ||
}); | ||
} | ||
return configurationFiles; | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,16 @@ | ||
import { Context } from "../plugin/mod.ts"; | ||
|
||
export interface RenderedTemplate { | ||
name: string; | ||
content: string; | ||
} | ||
|
||
export interface CiConfigurationFile { | ||
path: string; | ||
content: string; | ||
} | ||
|
||
export type PlatformWriterFn = ( | ||
context: Context, | ||
templates: AsyncIterableIterator<RenderedTemplate>, | ||
) => Promise<void>; | ||
) => Promise<Array<CiConfigurationFile>>; |
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