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

test(ci): add tests for release process #241

Merged
merged 4 commits into from
Mar 10, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
239 changes: 239 additions & 0 deletions scripts/release/__tests__/create-release-issue.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
import {
parseCommit,
getVersionChangesText,
decideReleaseStrategy,
} from '../create-release-issue';

describe('create release issue', () => {
it('parses commit', () => {
expect(parseCommit(`abcdefg fix(javascript): fix the thing`)).toEqual({
hash: 'abcdefg',
lang: 'javascript',
message: 'fix the thing',
raw: 'abcdefg fix(javascript): fix the thing',
type: 'fix',
});
});

it('returns error when language scope is missing', () => {
expect(parseCommit(`abcdefg fix: fix the thing`)).toEqual({
error: 'missing-language-scope',
});
});

it('returns error when language scope is unknown', () => {
expect(parseCommit(`abcdefg fix(basic): fix the thing`)).toEqual({
error: 'unknown-language-scope',
});
});
Comment on lines +18 to +28
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't it be a throw or we handle this error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It returns error and prints some warning logs.

https://github.com/algolia/api-clients-automation/blob/d68ccee283af203e0e562c1cfb6ed0064b80b2d9/scripts/release/create-release-issue.ts#L204:L213

Assuming most of the commits follow semantic rules, some of commits might slip through (like "Merge ...."), and it shouldn't fail the release process. We can just ignore those commits and exclude from the changelogs, and versioning process.

Copy link
Member

Choose a reason for hiding this comment

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

Yep that make sense, but I believe it would also make sense to have an error log in that case (maybe a file like yarn does for example, or a commit, or msg to slack).

Otherwise, we might not see the error and have release with missing commits, it might be intended to skip that commit in particular but it could also be a mistake on our side.

Copy link
Member

Choose a reason for hiding this comment

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

Oh I'm dumb it's in the issue then ._.

Copy link
Contributor Author

@eunjae-lee eunjae-lee Mar 10, 2022

Choose a reason for hiding this comment

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

Oh, it's not in the issue, but we should definitely include them in the issue, like

Expand to see skipped commit messages:

lack of language scope

abcdefg fix: fix this

unknown language scope

abcdefg fix(blah): fix this

I can do this in a separate PR.

Copy link
Member

Choose a reason for hiding this comment

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

Yep it make sense then, we definitely need to track those


it('generates text for version changes', () => {
expect(
getVersionChangesText({
javascript: {
current: '0.0.1',
next: '0.0.2',
},
php: {
current: '0.0.1',
next: '0.0.2',
},
java: {
current: '0.0.1',
next: '0.0.2',
},
})
).toMatchInlineSnapshot(`
"- [x] javascript: v0.0.1 -> v0.0.2
- [x] java: v0.0.1 -> v0.0.2
- [x] php: v0.0.1 -> v0.0.2"
`);
});

it('generates text for version changes with a language with no commit', () => {
expect(
getVersionChangesText({
javascript: {
current: '0.0.1',
next: '0.0.2',
},
php: {
current: '0.0.1',
next: '0.0.1',
noCommit: true,
},
java: {
current: '0.0.1',
next: '0.0.2',
},
})
).toMatchInlineSnapshot(`
"- [x] javascript: v0.0.1 -> v0.0.2
- [x] java: v0.0.1 -> v0.0.2
- ~php: v0.0.1 (no commit)~"
`);
});

it('generates text for version changes with a language to skip', () => {
expect(
getVersionChangesText({
javascript: {
current: '0.0.1',
next: '0.0.2',
},
php: {
current: '0.0.1',
next: '0.0.1',
},
java: {
current: '0.0.1',
next: '0.0.2',
skipRelease: true,
},
})
).toMatchInlineSnapshot(`
"- [x] javascript: v0.0.1 -> v0.0.2
- [ ] java: v0.0.1 -> v0.0.2
- No \`feat\` or \`fix\` commit, thus unchecked by default.
- [x] php: v0.0.1 -> v0.0.1"
`);
});

it('bumps major version for BREAKING CHANGE', () => {
const versions = decideReleaseStrategy({
versions: {
javascript: {
current: '0.0.1',
},
java: {
current: '0.0.1',
},
php: {
current: '0.0.1',
},
},
commits: [
{
hash: 'abcdefg',
type: 'feat',
lang: 'javascript',
message: 'update the API (BREAKING CHANGE)',
raw: 'abcdefg feat(javascript): update the API (BREAKING CHANGE)',
},
],
});

expect(versions.javascript.next).toEqual('1.0.0');
});

it('bumps minor version for feat', () => {
const versions = decideReleaseStrategy({
versions: {
javascript: {
current: '0.0.1',
},
java: {
current: '0.0.1',
},
php: {
current: '0.0.1',
},
},
commits: [
{
hash: 'abcdefg',
type: 'feat',
lang: 'php',
message: 'update the API',
raw: 'abcdefg feat(php): update the API',
},
],
});

expect(versions.php.next).toEqual('0.1.0');
});

it('bumps patch version for fix', () => {
const versions = decideReleaseStrategy({
versions: {
javascript: {
current: '0.0.1',
},
java: {
current: '0.0.1',
},
php: {
current: '0.0.1',
},
},
commits: [
{
hash: 'abcdefg',
type: 'fix',
lang: 'java',
message: 'fix some bug',
raw: 'abcdefg fix(java): fix some bug',
},
],
});

expect(versions.java.next).toEqual('0.0.2');
});

it('marks noCommit for languages without any commit', () => {
const versions = decideReleaseStrategy({
versions: {
javascript: {
current: '0.0.1',
},
java: {
current: '0.0.1',
},
php: {
current: '0.0.1',
},
},
commits: [
{
hash: 'abcdefg',
type: 'fix',
lang: 'java',
message: 'fix some bug',
raw: 'abcdefg fix(java): fix some bug',
},
],
});

expect(versions.javascript.noCommit).toEqual(true);
expect(versions.php.noCommit).toEqual(true);
expect(versions.java.noCommit).toBeUndefined();
});

it('marks skipRelease for patch upgrade without fix commit', () => {
const versions = decideReleaseStrategy({
versions: {
javascript: {
current: '0.0.1',
},
java: {
current: '0.0.1',
},
php: {
current: '0.0.1',
},
},
commits: [
{
hash: 'abcdefg',
type: 'chore',
lang: 'javascript',
message: 'update devDevpendencies',
raw: 'abcdefg chore(javascript): update devDevpendencies',
},
],
});
expect(versions.javascript.skipRelease).toEqual(true);
expect(versions.java.skipRelease).toBeUndefined();
expect(versions.php.skipRelease).toBeUndefined();
});
});
31 changes: 31 additions & 0 deletions scripts/release/__tests__/process-release.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { getVersionsToRelease, getLangsToUpdateRepo } from '../process-release';

describe('process release', () => {
it('gets versions to release', () => {
const versions = getVersionsToRelease(`
## Version Changes

- [x] javascript: v1.0.0 -> v1.1.0
- [x] php: v2.0.0 -> v2.0.1
- [ ] java: v3.0.0 -> v3.0.1
`);

expect(Object.keys(versions)).toEqual(['javascript', 'php']);
expect(versions.javascript.current).toEqual('1.0.0');
expect(versions.javascript.next).toEqual('1.1.0');
expect(versions.php.current).toEqual('2.0.0');
expect(versions.php.next).toEqual('2.0.1');
});

it('gets langs to update', () => {
expect(
getLangsToUpdateRepo(`
## Version Changes

- [ ] javascript: v1.0.0 -> v1.1.0
- [x] php: v2.0.0 -> v2.0.1
- [ ] java: v3.0.0 -> v3.0.1
`)
).toEqual(['javascript', 'java']);
});
});
Loading