Skip to content

Commit

Permalink
Patch Pipelines and Dockerfiles (#1534)
Browse files Browse the repository at this point in the history
  • Loading branch information
samchungy authored Jun 20, 2024
1 parent d88e3c5 commit 306c3a0
Show file tree
Hide file tree
Showing 17 changed files with 728 additions and 109 deletions.
5 changes: 5 additions & 0 deletions .changeset/unlucky-books-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'skuba': minor
---

lint: Patch installing specific pnpm version via Corepack
8 changes: 8 additions & 0 deletions src/cli/__snapshots__/format.int.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Patch skipped: Move .npmrc out of the .gitignore managed section - no .gitignore
Patch skipped: Move .npmrc out of the .dockerignore managed section - no .dockerignore file found
Patch skipped: Ensure the pnpm package manager version specified in package.json is used in Dockerfiles - no packageManager declaration in package.json found
skuba update complete.
Refreshed .eslintignore. refresh-config-files
Expand Down Expand Up @@ -90,6 +92,8 @@ Patch skipped: Move .npmrc out of the .gitignore managed section - no .gitignore
Patch skipped: Move .npmrc out of the .dockerignore managed section - no .dockerignore file found
Patch skipped: Ensure the pnpm package manager version specified in package.json is used in Dockerfiles - no packageManager declaration in package.json found
skuba update complete.
Refreshed .eslintignore. refresh-config-files
Expand Down Expand Up @@ -160,6 +164,8 @@ Patch skipped: Move .npmrc out of the .gitignore managed section - no .gitignore
Patch skipped: Move .npmrc out of the .dockerignore managed section - no .dockerignore file found
Patch skipped: Ensure the pnpm package manager version specified in package.json is used in Dockerfiles - no packageManager declaration in package.json found
skuba update complete.
Refreshed .eslintignore. refresh-config-files
Expand Down Expand Up @@ -199,6 +205,8 @@ Patch skipped: Move .npmrc out of the .gitignore managed section - not ignored
Patch skipped: Move .npmrc out of the .dockerignore managed section - no .dockerignore file found
Patch skipped: Ensure the pnpm package manager version specified in package.json is used in Dockerfiles - no packageManager declaration in package.json found
skuba update complete.
Refreshed .eslintignore. refresh-config-files
Expand Down
18 changes: 17 additions & 1 deletion src/cli/init/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { createInclusionFilter } from '../../utils/dir';
import { createExec, ensureCommands } from '../../utils/exec';
import { createLogger, log } from '../../utils/logging';
import { showLogoAndVersionInfo } from '../../utils/logo';
import { getConsumerManifest } from '../../utils/manifest';
import { detectPackageManager } from '../../utils/packageManager';
import {
BASE_TEMPLATE_DIR,
ensureTemplateConfigDeletion,
Expand Down Expand Up @@ -87,8 +89,22 @@ export const init = async (args = process.argv.slice(2)) => {
log.newline();
await initialiseRepo(destinationDir, templateData);

const [manifest, packageManagerConfig] = await Promise.all([
getConsumerManifest(),
detectPackageManager(),
]);

if (!manifest) {
throw new Error("Repository doesn't contain a package.json file.");
}

// Patch in a baseline Renovate preset based on the configured Git owner.
await tryPatchRenovateConfig('format', destinationDir);
await tryPatchRenovateConfig({
mode: 'format',
dir: destinationDir,
manifest,
packageManager: packageManagerConfig,
});

const skubaSlug = `skuba@${skubaVersionInfo.local}`;

Expand Down
85 changes: 64 additions & 21 deletions src/cli/lint/internalLints/patchRenovateConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import memfs, { vol } from 'memfs';
import * as Git from '../../../api/git';

import { tryPatchRenovateConfig } from './patchRenovateConfig';
import type { PatchConfig } from './upgrade';

jest.mock('fs-extra', () => memfs);

Expand Down Expand Up @@ -51,7 +52,9 @@ describe('patchRenovateConfig', () => {

vol.fromJSON({ '.git': null, 'renovate.json': JSON });

await expect(tryPatchRenovateConfig('format')).resolves.toEqual({
await expect(
tryPatchRenovateConfig({ mode: 'format' } as PatchConfig),
).resolves.toEqual({
result: 'apply',
});

Expand All @@ -77,7 +80,9 @@ describe('patchRenovateConfig', () => {

vol.fromJSON({ 'foo/.git': null, 'foo/renovate.json': JSON });

await expect(tryPatchRenovateConfig('format', 'foo')).resolves.toEqual({
await expect(
tryPatchRenovateConfig({ mode: 'format', dir: 'foo' } as PatchConfig),
).resolves.toEqual({
result: 'apply',
});

Expand All @@ -103,7 +108,9 @@ describe('patchRenovateConfig', () => {

vol.fromJSON({ '.git': null, '.github/renovate.json5': JSON5 });

await expect(tryPatchRenovateConfig('format')).resolves.toEqual({
await expect(
tryPatchRenovateConfig({ mode: 'format' } as PatchConfig),
).resolves.toEqual({
result: 'apply',
});

Expand Down Expand Up @@ -137,7 +144,9 @@ describe('patchRenovateConfig', () => {

vol.fromJSON(files);

await expect(tryPatchRenovateConfig('format')).resolves.toEqual({
await expect(
tryPatchRenovateConfig({ mode: 'format' } as PatchConfig),
).resolves.toEqual({
result: 'skip',
reason: 'no config found',
});
Expand All @@ -159,7 +168,9 @@ describe('patchRenovateConfig', () => {

vol.fromJSON(files);

await expect(tryPatchRenovateConfig('format')).resolves.toEqual({
await expect(
tryPatchRenovateConfig({ mode: 'format' } as PatchConfig),
).resolves.toEqual({
result: 'skip',
reason: 'due to an error',
});
Expand All @@ -181,7 +192,9 @@ describe('patchRenovateConfig', () => {

vol.fromJSON(files);

await expect(tryPatchRenovateConfig('format')).resolves.toEqual({
await expect(
tryPatchRenovateConfig({ mode: 'format' } as PatchConfig),
).resolves.toEqual({
result: 'skip',
reason: 'no Git root found',
});
Expand All @@ -198,7 +211,9 @@ describe('patchRenovateConfig', () => {

vol.fromJSON(files);

await expect(tryPatchRenovateConfig('format')).resolves.toEqual({
await expect(
tryPatchRenovateConfig({ mode: 'format' } as PatchConfig),
).resolves.toEqual({
result: 'skip',
reason: 'owner does not map to a SEEK preset',
});
Expand All @@ -218,7 +233,9 @@ describe('patchRenovateConfig', () => {

vol.fromJSON(files);

await expect(tryPatchRenovateConfig('format')).resolves.toEqual({
await expect(
tryPatchRenovateConfig({ mode: 'format' } as PatchConfig),
).resolves.toEqual({
result: 'skip',
reason: 'owner does not map to a SEEK preset',
});
Expand All @@ -238,7 +255,9 @@ describe('patchRenovateConfig', () => {

vol.fromJSON(files);

await expect(tryPatchRenovateConfig('format')).resolves.toEqual({
await expect(
tryPatchRenovateConfig({ mode: 'format' } as PatchConfig),
).resolves.toEqual({
result: 'apply',
});

Expand All @@ -260,7 +279,9 @@ describe('patchRenovateConfig', () => {

vol.fromJSON(files);

await expect(tryPatchRenovateConfig('format')).resolves.toEqual({
await expect(
tryPatchRenovateConfig({ mode: 'format' } as PatchConfig),
).resolves.toEqual({
result: 'skip',
reason: 'config already has a SEEK preset',
});
Expand All @@ -280,7 +301,9 @@ describe('patchRenovateConfig', () => {

vol.fromJSON(files);

await expect(tryPatchRenovateConfig('format')).resolves.toEqual({
await expect(
tryPatchRenovateConfig({ mode: 'format' } as PatchConfig),
).resolves.toEqual({
result: 'skip',
reason: 'config already has a SEEK preset',
});
Expand All @@ -300,7 +323,9 @@ describe('patchRenovateConfig', () => {

vol.fromJSON({ '.git': null, 'renovate.json': JSON });

await expect(tryPatchRenovateConfig('lint')).resolves.toEqual({
await expect(
tryPatchRenovateConfig({ mode: 'lint' } as PatchConfig),
).resolves.toEqual({
result: 'apply',
});

Expand All @@ -315,7 +340,9 @@ describe('patchRenovateConfig', () => {

vol.fromJSON({ 'foo/.git': null, 'foo/renovate.json': JSON });

await expect(tryPatchRenovateConfig('lint', 'foo')).resolves.toEqual({
await expect(
tryPatchRenovateConfig({ mode: 'lint', dir: 'foo' } as PatchConfig),
).resolves.toEqual({
result: 'apply',
});

Expand All @@ -333,7 +360,9 @@ describe('patchRenovateConfig', () => {

vol.fromJSON({ '.git': null, '.github/renovate.json5': JSON5 });

await expect(tryPatchRenovateConfig('lint')).resolves.toEqual({
await expect(
tryPatchRenovateConfig({ mode: 'lint' } as PatchConfig),
).resolves.toEqual({
result: 'apply',
});

Expand All @@ -354,7 +383,9 @@ describe('patchRenovateConfig', () => {

vol.fromJSON(files);

await expect(tryPatchRenovateConfig('lint')).resolves.toEqual({
await expect(
tryPatchRenovateConfig({ mode: 'lint' } as PatchConfig),
).resolves.toEqual({
result: 'skip',
reason: 'no config found',
});
Expand All @@ -371,7 +402,9 @@ describe('patchRenovateConfig', () => {

vol.fromJSON(files);

await expect(tryPatchRenovateConfig('lint')).resolves.toEqual({
await expect(
tryPatchRenovateConfig({ mode: 'lint' } as PatchConfig),
).resolves.toEqual({
result: 'skip',
reason: 'no Git root found',
});
Expand All @@ -388,7 +421,9 @@ describe('patchRenovateConfig', () => {

vol.fromJSON(files);

await expect(tryPatchRenovateConfig('lint')).resolves.toEqual({
await expect(
tryPatchRenovateConfig({ mode: 'lint' } as PatchConfig),
).resolves.toEqual({
result: 'skip',
reason: 'owner does not map to a SEEK preset',
});
Expand All @@ -408,7 +443,9 @@ describe('patchRenovateConfig', () => {

vol.fromJSON(files);

await expect(tryPatchRenovateConfig('lint')).resolves.toEqual({
await expect(
tryPatchRenovateConfig({ mode: 'lint' } as PatchConfig),
).resolves.toEqual({
result: 'skip',
reason: 'owner does not map to a SEEK preset',
});
Expand All @@ -428,7 +465,9 @@ describe('patchRenovateConfig', () => {

vol.fromJSON(files);

await expect(tryPatchRenovateConfig('lint')).resolves.toEqual({
await expect(
tryPatchRenovateConfig({ mode: 'lint' } as PatchConfig),
).resolves.toEqual({
result: 'apply',
});

Expand All @@ -450,7 +489,9 @@ describe('patchRenovateConfig', () => {

vol.fromJSON(files);

await expect(tryPatchRenovateConfig('lint')).resolves.toEqual({
await expect(
tryPatchRenovateConfig({ mode: 'lint' } as PatchConfig),
).resolves.toEqual({
result: 'skip',
reason: 'config already has a SEEK preset',
});
Expand All @@ -470,7 +511,9 @@ describe('patchRenovateConfig', () => {

vol.fromJSON(files);

await expect(tryPatchRenovateConfig('lint')).resolves.toEqual({
await expect(
tryPatchRenovateConfig({ mode: 'lint' } as PatchConfig),
).resolves.toEqual({
result: 'skip',
reason: 'config already has a SEEK preset',
});
Expand Down
6 changes: 3 additions & 3 deletions src/cli/lint/internalLints/patchRenovateConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ const patchRenovateConfig = async (
return { result: 'apply' };
};

export const tryPatchRenovateConfig = (async (
mode: 'format' | 'lint',
export const tryPatchRenovateConfig = (async ({
mode,
dir = process.cwd(),
) => {
}) => {
try {
// In a monorepo we may be invoked within a subdirectory, but we are working
// with Renovate config that should be relative to the repository root.
Expand Down
Loading

0 comments on commit 306c3a0

Please sign in to comment.