Skip to content

Commit

Permalink
start adding tests and update config setup
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardfoyle committed Apr 4, 2024
1 parent ea09245 commit c099471
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 23 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/deprecate_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,8 @@ jobs:
fetch-depth: 0
- uses: ./.github/actions/setup_node
- uses: ./.github/actions/restore_install_cache
- name: Start local proxy
if: !inputs.useNpmRegistry
run: npm run start:npm-proxy
- name: Deprecate release versions
run: npx tsx scripts/deprecate_release.ts
3 changes: 3 additions & 0 deletions .github/workflows/restore_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,8 @@ jobs:
fetch-depth: 0
- uses: ./.github/actions/setup_node
- uses: ./.github/actions/restore_install_cache
- name: Start local proxy
if: !inputs.useNpmRegistry
run: npm run start:npm-proxy
- name: Restore release versions
run: npx tsx scripts/restore_release.ts
15 changes: 6 additions & 9 deletions scripts/components/git_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,23 +218,20 @@ class GitClient {
);

// eslint-disable-next-line spellcheck/spell-checker
await $`git config ${userEmailKey} "github-actions[bot]@users.noreply.github.com"`;
await $`git config ${userNameKey} "github-actions[bot]"`;

await $`git config --unset-all ${autoSetupRemoteKey}`;
await $`git config ${autoSetupRemoteKey} true`;
await $`git config --replace-all ${userEmailKey} "github-actions[bot]@users.noreply.github.com"`;
await $`git config --replace-all ${userNameKey} "github-actions[bot]"`;
await $`git config --replace-all ${autoSetupRemoteKey} true`;

this.registerCleanup(async () => {
// reset config on exit
if (originalEmail) {
await $`git config user.email ${originalEmail}`;
await $`git config --replace-all ${userEmailKey} ${originalEmail}`;
}
if (originalName) {
await $`git config ${userNameKey} ${originalName}`;
await $`git config --replace-all ${userNameKey} ${originalName}`;
}
if (originalAutoSetupRemote) {
await $`git config --unset-all ${autoSetupRemoteKey}`;
await $`git config ${autoSetupRemoteKey} ${originalAutoSetupRemote}`;
await $`git config --replace-all ${autoSetupRemoteKey} ${originalAutoSetupRemote}`;
}
});
this.isConfigured = true;
Expand Down
36 changes: 36 additions & 0 deletions scripts/components/release_lifecycle_manager.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { after, before, beforeEach, describe, it } from 'node:test';

/**
* This test suite is more of an integration test than a unit test.
* It uses the real file system and git repo but mocks the GitHub API client
* It spins up verdaccio to test updating package metadata locally
*
* Since all of these tests are sharing the same git tree, we're running concurrently to avoid conflicts (mostly around duplicate tag names)
*/
void describe('ReleaseLifecycleManager', { concurrency: 1 }, () => {
before(async () => {
await import('../start_npm_proxy.js');
});

after(async () => {
await import('../stop_npm_proxy.js');
});

beforeEach(async () => {
// checkout test branch
// add changeset that releases minor of package A
// run changeset version && publish
// add changeset that releases minor of package A and B
// run changeset version && publish
});
void describe('deprecateRelease', () => {
void it('deprecates expected versions and updates dist-tags', async () => {});

void it('does not update dist-tags when deprecating a past release');
});
void describe('restoreRelease', () => {
void it('un-deprecates expected versions and updates dist-tags', async () => {});

void it('does not update dist-tags when restoring a past release', async () => {});
});
});
15 changes: 1 addition & 14 deletions scripts/components/release_lifecycle_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { EOL } from 'os';
import { gitClient as _gitClient } from './git_client.js';
import { npmClient as _npmClient } from './npm_client.js';
import { getDistTagFromReleaseTag } from './get_dist_tag_from_release_tag.js';
import { execa } from 'execa';
import { githubClient as _githubClient } from './github_client.js';

/**
Expand Down Expand Up @@ -107,12 +106,6 @@ export class ReleaseLifecycleManager {
// if anything fails before this point, we haven't actually modified anything on NPM yet.
// now we actually update the npm dist tags and mark the packages as deprecated

if (this.registryTarget === 'local-proxy') {
await execa('npm', ['run', 'start:npm-proxy'], { stdio: 'inherit' });
}

await this.npmClient.configureNpmRc({ target: this.registryTarget });

for (const releaseTag of releaseTagsToRestoreDistTagPointers) {
const distTag = getDistTagFromReleaseTag(releaseTag);
console.log(
Expand Down Expand Up @@ -196,12 +189,6 @@ export class ReleaseLifecycleManager {
// if anything fails before this point, we haven't actually modified anything on NPM yet.
// now we actually update the npm dist tags and mark the packages as un-deprecated

if (this.registryTarget === 'local-proxy') {
await execa('npm', ['run', 'start:npm-proxy'], { stdio: 'inherit' });
}

await this.npmClient.configureNpmRc({ target: this.registryTarget });

for (const releaseTag of releaseTagsToRestoreDistTagPointers) {
const distTag = getDistTagFromReleaseTag(releaseTag);
console.log(
Expand All @@ -225,6 +212,6 @@ export class ReleaseLifecycleManager {
The release deprecation workflow requires a clean working tree to create the rollback PR.
`);
}
await this.gitClient.fetchTags();
await this.npmClient.configureNpmRc({ target: this.registryTarget });
};
}

0 comments on commit c099471

Please sign in to comment.