Skip to content

Commit 429cc95

Browse files
committed
refactor(migrate): simplify setup-vp migration
1 parent 292f34c commit 429cc95

2 files changed

Lines changed: 12 additions & 23 deletions

File tree

packages/cli/src/migration/bin.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,9 +595,11 @@ function showMigrationSummary(options: {
595595
if (report.nodeVersionFileMigrated) {
596596
log(`${styleText('gray', '•')} Node version manager file migrated to .node-version`);
597597
}
598-
if (report.setupVpVersionUpdatedFileCount > 0) {
598+
const setupVpFileCount = report.setupVpVersionUpdatedFileCount;
599+
if (setupVpFileCount > 0) {
600+
const fileLabel = setupVpFileCount === 1 ? 'file' : 'files';
599601
log(
600-
`${styleText('gray', '•')} setup-vp updated to ${SETUP_VP_VERSION} in ${report.setupVpVersionUpdatedFileCount} GitHub Actions ${report.setupVpVersionUpdatedFileCount === 1 ? 'file' : 'files'}`,
602+
`${styleText('gray', '•')} setup-vp updated to ${SETUP_VP_VERSION} in ${setupVpFileCount} GitHub Actions ${fileLabel}`,
601603
);
602604
}
603605
if (report.wrappedPluginConfigCount > 0) {

packages/cli/src/migration/migrator/setup.ts

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { SETUP_VP_VERSION } from '../../utils/constants.ts';
1111
import { editJsonFile } from '../../utils/json.ts';
1212
import { detectConfigs } from '../detector.ts';
1313
import { type MigrationReport } from '../report.ts';
14-
import { warnMigration } from './shared.ts';
14+
import { isPlainRecord, warnMigration } from './shared.ts';
1515

1616
export function setPackageManager(
1717
projectDir: string,
@@ -134,40 +134,27 @@ const NODE_VERSION_FILE_NVMRC_RE = /(node-version-file:[ \t]*)(['"]?)(\.\/)?\.nv
134134
function isCompositeActionFile(filePath: string): boolean {
135135
try {
136136
const action = parseYaml(fs.readFileSync(filePath, 'utf8')) as unknown;
137-
if (typeof action !== 'object' || action === null || Array.isArray(action)) {
138-
return false;
139-
}
140-
const runs = (action as Record<string, unknown>).runs;
141-
return (
142-
typeof runs === 'object' &&
143-
runs !== null &&
144-
!Array.isArray(runs) &&
145-
(runs as Record<string, unknown>).using === 'composite'
146-
);
137+
return isPlainRecord(action) && isPlainRecord(action.runs) && action.runs.using === 'composite';
147138
} catch {
148139
return false;
149140
}
150141
}
151142

152143
/**
153-
* Collect GitHub Actions YAML files that migration may inspect: top-level
154-
* workflows (`.github/workflows/*.{yml,yaml}`, which GitHub runs only when flat
155-
* in that directory) and composite action definitions anywhere beneath
156-
* `.github`. Action metadata is included only when `runs.using` is `composite`.
157-
* Returns absolute paths. `nocase` keeps filename matching case-insensitive on
158-
* case-sensitive filesystems. Recursive discovery intentionally remains scoped
159-
* to the `.github` directory.
144+
* Collect top-level workflows and composite action definitions under `.github`.
145+
* Action metadata must declare `runs.using: composite`. Paths are absolute, and
146+
* filename matching is case-insensitive.
160147
*/
161148
function collectGithubActionFiles(projectPath: string): string[] {
162-
const options = {
149+
const globOptions = {
163150
cwd: path.join(projectPath, '.github'),
164151
absolute: true,
165152
nocase: true,
166153
nodir: true,
167154
} as const;
168-
const workflows = globSync('workflows/*.{yml,yaml}', options);
155+
const workflows = globSync('workflows/*.{yml,yaml}', globOptions);
169156
const compositeActions = globSync('**/action.{yml,yaml}', {
170-
...options,
157+
...globOptions,
171158
dot: true,
172159
}).filter(isCompositeActionFile);
173160

0 commit comments

Comments
 (0)