Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Rush] Add .changeignore file support #2279

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
28 changes: 18 additions & 10 deletions apps/rush-lib/src/cli/actions/ChangeAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as os from 'os';
import * as path from 'path';
import * as child_process from 'child_process';
import colors from 'colors';
import ignore, { Ignore } from 'ignore';

import {
CommandLineFlagParameter,
Expand All @@ -31,6 +32,8 @@ import {
import * as inquirerTypes from 'inquirer';
const inquirer: typeof inquirerTypes = Import.lazy('inquirer', require);

const CHANGE_IGNORE_FILE_NAME: string = '.changeignore';
mmkal marked this conversation as resolved.
Show resolved Hide resolved

export class ChangeAction extends BaseRushAction {
private _verifyParameter!: CommandLineFlagParameter;
private _noFetchParameter!: CommandLineFlagParameter;
Expand All @@ -47,7 +50,9 @@ export class ChangeAction extends BaseRushAction {
const documentation: string[] = [
'Asks a series of questions and then generates a <branchname>-<timestamp>.json file ' +
'in the common folder. The `publish` command will consume these files and perform the proper ' +
'version bumps. Note these changes will eventually be published in a changelog.md file in each package.',
'version bumps. Files will be excluded from change detection if they match an entry in a ' +
`"${CHANGE_IGNORE_FILE_NAME}" file in their package's root directory. The changes will eventually be ` +
'published in a CHANGELOG.md file in each package.',
'',
'The possible types of changes are: ',
'',
Expand Down Expand Up @@ -312,11 +317,11 @@ export class ChangeAction extends BaseRushAction {
}

private _getChangedPackageNames(): string[] {
const changedFolders: (string | undefined)[] | undefined = VersionControl.getChangedFolders(
const changedFiles: string[] = VersionControl.getChangedFiles(
mmkal marked this conversation as resolved.
Show resolved Hide resolved
this._targetBranch,
this._noFetchParameter.value
);
if (!changedFolders) {
if (changedFiles.length === 0) {
mmkal marked this conversation as resolved.
Show resolved Hide resolved
return [];
}
const changedPackageNames: Set<string> = new Set<string>();
Expand All @@ -331,7 +336,7 @@ export class ChangeAction extends BaseRushAction {
const projectFolder: string = repoRootFolder
? path.relative(repoRootFolder, project.projectFolder)
: project.projectRelativeFolder;
return this._hasProjectChanged(changedFolders, projectFolder);
return this._hasProjectChanged(changedFiles, projectFolder);
})
.forEach((project) => {
const hostName: string | undefined = projectHostMap.get(project.packageName);
Expand All @@ -354,14 +359,17 @@ export class ChangeAction extends BaseRushAction {
});
}

private _hasProjectChanged(changedFolders: (string | undefined)[], projectFolder: string): boolean {
for (const folder of changedFolders) {
if (folder && Path.isUnderOrEqual(folder, projectFolder)) {
return true;
}
private _hasProjectChanged(changedFiles: string[], projectFolder: string): boolean {
const relevantFiles: string[] = changedFiles.filter((file) => Path.isUnderOrEqual(file, projectFolder));

const changeIgnoreFile: string = path.join(projectFolder, CHANGE_IGNORE_FILE_NAME);
mmkal marked this conversation as resolved.
Show resolved Hide resolved

const ignoreConfig: Ignore = ignore();
if (relevantFiles.length > 0 && FileSystem.exists(changeIgnoreFile)) {
mmkal marked this conversation as resolved.
Show resolved Hide resolved
ignoreConfig.add(FileSystem.readFile(changeIgnoreFile));
}

return false;
return relevantFiles.some(ignoreConfig.createFilter());
}

/**
Expand Down
11 changes: 11 additions & 0 deletions common/changes/@microsoft/rush/changeignore_2020-10-13-19-25.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@microsoft/rush",
"comment": "Add .changeignore file support",
mmkal marked this conversation as resolved.
Show resolved Hide resolved
"type": "minor"
}
],
"packageName": "@microsoft/rush",
"email": "[email protected]"
}