Skip to content

Commit

Permalink
chore(scripts): add the contrib in the github release (#4390)
Browse files Browse the repository at this point in the history
  • Loading branch information
millotp authored Jan 22, 2025
1 parent d91947d commit 0e98f08
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 21 deletions.
21 changes: 21 additions & 0 deletions scripts/ci/codegen/__tests__/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## [5.20.0](https://github.com/algolia/algoliasearch-client-javascript/compare/5.19.0...5.20.0)

- [22167b8e68](https://github.com/algolia/api-clients-automation/commit/22167b8e68) fix(specs): extend Analytics descriptions ([#4360](https://github.com/algolia/api-clients-automation/pull/4360)) by [@gazconroy](https://github.com/gazconroy/)
- [5b14906c1e](https://github.com/algolia/api-clients-automation/commit/5b14906c1e) fix(specs): remove the processing outcome ([#4359](https://github.com/algolia/api-clients-automation/pull/4359)) by [@millotp](https://github.com/millotp/)
- [952639f0fb](https://github.com/algolia/api-clients-automation/commit/952639f0fb) fix(specs): adjust style for banner descriptions ([#4362](https://github.com/algolia/api-clients-automation/pull/4362)) by [@kai687](https://github.com/kai687/)
- [4ae9ccd89f](https://github.com/algolia/api-clients-automation/commit/4ae9ccd89f) chore(deps): dependencies 2025-01-20 ([#4365](https://github.com/algolia/api-clients-automation/pull/4365)) by [@algolia-bot](https://github.com/algolia-bot/)
- [83f188d333](https://github.com/algolia/api-clients-automation/commit/83f188d333) feat(specs): rename composition to composition-full (private) and add composition (public) ([#4357](https://github.com/algolia/api-clients-automation/pull/4357)) by [@e-krebs](https://github.com/e-krebs/)
- [e842e63d4e](https://github.com/algolia/api-clients-automation/commit/e842e63d4e) fix(javascript): use beta version ([#4385](https://github.com/algolia/api-clients-automation/pull/4385)) by [@shortcuts](https://github.com/shortcuts/)

## [5.19.0](https://github.com/algolia/algoliasearch-client-javascript/compare/5.18.0...5.19.0)

- [f9d890bbc4](https://github.com/algolia/api-clients-automation/commit/f9d890bbc4) chore(deps): dependencies 2024-12-23 ([#4258](https://github.com/algolia/api-clients-automation/pull/4258)) by [@algolia-bot](https://github.com/algolia-bot/)

## [5.18.0](https://github.com/algolia/algoliasearch-client-javascript/compare/5.17.1...5.18.0)

- [966fe05ae6](https://github.com/algolia/api-clients-automation/commit/966fe05ae6) chore(deps): dependencies 2024-12-16 ([#4235](https://github.com/algolia/api-clients-automation/pull/4235)) by [@algolia-bot](https://github.com/algolia-bot/)
- [0481473fe0](https://github.com/algolia/api-clients-automation/commit/0481473fe0) chore: trigger auto close pr ([#4250](https://github.com/algolia/api-clients-automation/pull/4250)) by [@shortcuts](https://github.com/shortcuts/)

## [5.17.1](https://github.com/algolia/algoliasearch-client-javascript/compare/5.17.0...5.17.1)

- [cd59f445e](https://github.com/algolia/api-clients-automation/commit/cd59f445e) fix(specs): enable watcher for push ([#4229](https://github.com/algolia/api-clients-automation/pull/4229)) by [@shortcuts](https://github.com/shortcuts/)
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`createGithubRelease > generates a release 1`] = `
[MockFunction spy] {
"calls": [
[
{
"body": "
# New version released!
## What's Changed
* [22167b8e68](https://github.com/algolia/api-clients-automation/commit/22167b8e68) fix(specs): extend Analytics descriptions ([#4360](https://github.com/algolia/api-clients-automation/pull/4360)) by @gazconroy
* [5b14906c1e](https://github.com/algolia/api-clients-automation/commit/5b14906c1e) fix(specs): remove the processing outcome ([#4359](https://github.com/algolia/api-clients-automation/pull/4359)) by @millotp
* [952639f0fb](https://github.com/algolia/api-clients-automation/commit/952639f0fb) fix(specs): adjust style for banner descriptions ([#4362](https://github.com/algolia/api-clients-automation/pull/4362)) by @kai687
* [4ae9ccd89f](https://github.com/algolia/api-clients-automation/commit/4ae9ccd89f) chore(deps): dependencies 2025-01-20 ([#4365](https://github.com/algolia/api-clients-automation/pull/4365)) by @algolia-bot
* [83f188d333](https://github.com/algolia/api-clients-automation/commit/83f188d333) feat(specs): rename composition to composition-full (private) and add composition (public) ([#4357](https://github.com/algolia/api-clients-automation/pull/4357)) by @e-krebs
* [e842e63d4e](https://github.com/algolia/api-clients-automation/commit/e842e63d4e) fix(javascript): use beta version ([#4385](https://github.com/algolia/api-clients-automation/pull/4385)) by @shortcuts
**Full Changelog**: https://github.com/algolia/algoliasearch-client-dart/compare/5.19.0...5.20.0
→ [Browse the Algolia documentation](https://www.algolia.com/doc/libraries/dart)
",
"name": "5.20.0",
"owner": "algolia",
"repo": "algoliasearch-client-dart",
"tag_name": "5.20.0",
},
],
],
"results": [
{
"type": "return",
"value": Promise {},
},
],
}
`;
7 changes: 3 additions & 4 deletions scripts/ci/codegen/__tests__/codegen.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ import { describe, expect, it, vi } from 'vitest';
import { pushGeneratedCode } from '../pushGeneratedCode.ts';

vi.mock('../../../common.ts', async (importOriginal) => {
// eslint-disable-next-line
const mod = await importOriginal<typeof import('../../../common.ts')>();
return {
...mod,
// eslint-disable-next-line
...(await importOriginal<typeof import('../../../common.ts')>()),
run: vi.fn().mockResolvedValue(''),
};
});

describe('pushGeneratedCode', () => {
it('throws without GITHUB_TOKEN environment variable', async () => {
process.env.GITHUB_TOKEN = '';
vi.stubEnv('GITHUB_TOKEN', '');
await expect(pushGeneratedCode()).rejects.toThrow('Environment variable `GITHUB_TOKEN` does not exist.');
});
});
39 changes: 39 additions & 0 deletions scripts/ci/codegen/__tests__/createGithubReleases.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { afterAll, describe, expect, it, vi } from 'vitest';
import { createGitHubRelease } from '../createGitHubReleases.ts';

describe('createGithubRelease', () => {
afterAll(() => {
vi.clearAllMocks();
});

it('generates a release', async () => {
vi.stubEnv('GITHUB_TOKEN', 'token');

const createRelease = vi.fn().mockResolvedValue(undefined);
const octokit = {
repos: {
createRelease,
},
} as any;

vi.mock('../../utils.ts', async (importOriginal) => {
return {
// eslint-disable-next-line
...(await importOriginal<typeof import('../../utils.ts')>()),
cloneRepository: vi.fn().mockResolvedValue({ tempGitDir: __dirname }),
};
});

vi.mock('../../../common.ts', async (importOriginal) => {
return {
// eslint-disable-next-line
...(await importOriginal<typeof import('../../../common.ts')>()),
run: vi.fn().mockResolvedValue('5.20.0\n5.19.0\n5.18.0\n5.17.1'),
};
});

await expect(createGitHubRelease(octokit, 'dart')).resolves.toBeUndefined();

expect(createRelease).toMatchSnapshot();
});
});
15 changes: 10 additions & 5 deletions scripts/ci/codegen/createGitHubReleases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import { isPreRelease } from '../../release/versionsHistory.ts';
import type { Language } from '../../types.ts';
import { cloneRepository } from '../utils.ts';

import type { Octokit } from '@octokit/rest';
import { resolve } from 'path';
import { stripCommitMessage } from '../../release/common.ts';
import { commitStartRelease } from './text.ts';

async function createGitHubRelease(lang: Language): Promise<void> {
export async function createGitHubRelease(octokit: Octokit, lang: Language): Promise<void> {
// **Full Changelog**:

const githubToken = ensureGitHubToken();
Expand All @@ -30,7 +31,7 @@ async function createGitHubRelease(lang: Language): Promise<void> {
}

const newVersion = tags[0];
const isMajor = newVersion.endsWith('0.0');
const isMajor = newVersion.endsWith('.0.0');
let previousVersion = '';

// if we are not on the major, we create a release for the last version, otherwise we get every versions of the pre release
Expand All @@ -49,7 +50,11 @@ async function createGitHubRelease(lang: Language): Promise<void> {
throw new Error('unable to find changelog');
}

const changelog = [...fullChangelog][0][1].trim().replaceAll(/- \[/g, '* [');
// extract the last changelog block, and format it to make the contribution visible in the release
const changelog = [...fullChangelog][0][1]
.trim()
.replaceAll(/- \[/g, '* [')
.replaceAll(/by \[(.*?)\]\(https:\/\/github\.com.*?\)/g, 'by $1');

const repository = `algoliasearch-client-${lang}`;
const repositoryLink = `https://github.com/${OWNER}/${repository}`;
Expand All @@ -64,7 +69,7 @@ ${stripCommitMessage(changelog)}
`;

try {
await getOctokit().repos.createRelease({
await octokit.repos.createRelease({
owner: OWNER,
repo: repository,
tag_name: newVersion,
Expand Down Expand Up @@ -95,7 +100,7 @@ async function createGitHubReleases(languagesReleased: Language[]): Promise<void
languagesReleased.map(async (lang) => {
console.log(`> creating GitHub release for ${lang}`);

return await createGitHubRelease(lang);
return await createGitHubRelease(getOctokit(), lang);
}),
);
}
Expand Down
20 changes: 8 additions & 12 deletions scripts/release/__tests__/createReleasePR.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ const buildTestCommit = (

// Mock `getOctokit` to bypass the API call and credential requirements
vi.mock('../../common.ts', async (importOriginal) => {
// eslint-disable-next-line
const mod = await importOriginal<typeof import('../../common.ts')>();
return {
...mod,
// eslint-disable-next-line
...(await importOriginal<typeof import('../../common.ts')>()),
getOctokit: vi.fn().mockReturnValue({
pulls: {
get: (): any => ({
Expand All @@ -49,32 +48,29 @@ vi.mock('../../common.ts', async (importOriginal) => {
});

vi.mock('../../ci/utils.ts', async (importOriginal) => {
// eslint-disable-next-line
const mod = await importOriginal<typeof import('../../ci/utils.ts')>();
return {
...mod,
// eslint-disable-next-line
...(await importOriginal<typeof import('../../ci/utils.ts')>()),
getNbGitDiff: vi.fn().mockResolvedValue(1),
};
});

vi.mock('../common.ts', async (importOriginal) => {
// eslint-disable-next-line
const mod = await importOriginal<typeof import('../common.ts')>();
const getFileChangesMockFn = vi.fn();

return {
...mod,
// eslint-disable-next-line
...(await importOriginal<typeof import('../common.ts')>()),
getLastReleasedTag: vi.fn().mockResolvedValue('foobar'),
getFileChanges: getFileChangesMockFn,
getFileChangesMock: getFileChangesMockFn,
};
});

vi.mock('../../config.ts', async (importOriginal) => {
// eslint-disable-next-line
const mod = await importOriginal<typeof import('../../config.ts')>();
return {
...mod,
// eslint-disable-next-line
...(await importOriginal<typeof import('../../config.ts')>()),
getPackageVersionDefault: vi.fn().mockReturnValue('0.1.2'),
};
});
Expand Down

0 comments on commit 0e98f08

Please sign in to comment.