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

fix(ng-dev/release): run yarn integrity check before performing a release #264

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions ng-dev/release/publish/external-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,35 @@ export async function invokeYarnInstallCommand(projectDir: string): Promise<void
throw new FatalReleaseActionError();
}
}

/**
* Invokes the `yarn check --integrity` command in order to verify up to date dependencies.
*/
export async function invokeYarnIntegryCheck(projectDir: string): Promise<void> {
try {
await spawn('yarn', ['check', '--integrity'], {cwd: projectDir, mode: 'silent'});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually need https://classic.yarnpkg.com/en/docs/cli/check/#toc-yarn-check-verify-tree?

seems like the integrity check just checks the package json against the lock file unless I misunderstand the documentation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need both, now that I read it closer.

Because we want to make sure that our package.json matches installed deps and we want to make sure that our package.json matches our yarn.lock.

Does that make sense?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that makes sense, yeah 👍

info(green(' ✓ Confirmed dependencies from package.json match those in yarn.lock.'));
} catch (e) {
error(red(' ✘ Failed yarn integrity check, your installed dependencies are likely out of'));
error(red(' date. Please run `yarn install` to update your installed dependencies.'));
throw new FatalReleaseActionError();
}
}

/**
* Invokes the `yarn check --verify-tree` command in order to verify up to date dependencies.
*/
export async function invokeYarnVerifyTreeCheck(projectDir: string): Promise<void> {
try {
await spawn('yarn', ['check', '--verify-tree'], {cwd: projectDir, mode: 'silent'});
info(
green(
' ✓ Confirmed installed installed dependencies match those defined in package.json.',
josephperrott marked this conversation as resolved.
Show resolved Hide resolved
),
);
} catch (e) {
error(red(' ✘ Failed yarn verify tree check, your installed dependencies are likely out'));
error(red(' of date. Please run `yarn install` to update your installed dependencies.'));
throw new FatalReleaseActionError();
}
}
19 changes: 18 additions & 1 deletion ng-dev/release/publish/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {getNextBranchName, ReleaseRepoWithApi} from '../versioning/version-branc
import {ReleaseAction} from './actions';
import {FatalReleaseActionError, UserAbortedReleaseActionError} from './actions-error';
import {actions} from './actions/index';
import {invokeYarnIntegryCheck, invokeYarnVerifyTreeCheck} from './external-commands';

export enum CompletionState {
SUCCESS,
Expand Down Expand Up @@ -51,7 +52,8 @@ export class ReleaseTool {
if (
!(await this._verifyNoUncommittedChanges()) ||
!(await this._verifyRunningFromNextBranch(nextBranchName)) ||
!(await this._verifyNoShallowRepository())
!(await this._verifyNoShallowRepository()) ||
!(await this._verifyInstalledDependenciesAreUpToDate())
) {
return CompletionState.FATAL_ERROR;
}
Expand Down Expand Up @@ -144,6 +146,21 @@ export class ReleaseTool {
return true;
}

/**
* Verifiy that the install dependencies match the the versions defined in the package.json and
* yarn.lock files.
* @returns a boolean indicating success or failure.
*/
private async _verifyInstalledDependenciesAreUpToDate(): Promise<boolean> {
try {
await invokeYarnVerifyTreeCheck(this._projectRoot);
await invokeYarnIntegryCheck(this._projectRoot);
return true;
} catch {
return false;
}
}

/**
* Verifies that the local repository is not configured as shallow.
* @returns a boolean indicating success or failure.
Expand Down