Skip to content

Commit e87e67d

Browse files
authored
Merge pull request #2566 from hey-api/ci/changelog-2
ci: add custom bot
2 parents 646252e + 5ccb8c0 commit e87e67d

File tree

3 files changed

+198
-158
lines changed

3 files changed

+198
-158
lines changed

.changeset/__tests__/changelog.test.ts

Lines changed: 0 additions & 156 deletions
This file was deleted.

.github/workflows/release.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,27 @@ jobs:
2828
node-version: 20.x
2929
cache: 'pnpm'
3030

31-
- name: Install dependencies
31+
- name: Install Dependencies
3232
run: pnpm install
3333

3434
- name: Build
3535
run: pnpm build
3636

37+
- name: Generate GitHub App Token
38+
id: app-token
39+
uses: actions/[email protected]
40+
with:
41+
app-id: ${{ secrets.GIT_APP_CLIENT_ID }}
42+
private-key: ${{ secrets.GIT_APP_PRIVATE_KEY }}
43+
3744
- name: Create Release Pull Request
3845
uses: changesets/[email protected]
3946
with:
47+
commit: '[ci] release'
4048
publish: pnpm changeset publish
49+
title: '[ci] release'
4150
version: pnpm changeset version
4251
env:
43-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52+
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
4453
NPM_CONFIG_PROVENANCE: true
4554
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

__tests__/changelog.test.ts

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
import type * as getGitHubInfo from '@changesets/get-github-info';
2+
import parse from '@changesets/parse';
3+
import type {
4+
ModCompWithPackage,
5+
NewChangesetWithCommit,
6+
VersionType,
7+
} from '@changesets/types';
8+
import { describe, expect, it, vi } from 'vitest';
9+
10+
import changelog from '../.changeset/changelog.js';
11+
12+
type GetGitHubInfo = typeof getGitHubInfo;
13+
14+
const data = {
15+
commit: 'a085003',
16+
pull: 1613,
17+
repo: 'hey-api/openapi-ts',
18+
user: 'someone',
19+
};
20+
21+
vi.mock(
22+
'@changesets/get-github-info',
23+
(): GetGitHubInfo => ({
24+
async getInfo({ commit, repo }) {
25+
const { pull, user } = data;
26+
const links = {
27+
commit: `[\`${commit}\`](https://github.com/${repo}/commit/${commit})`,
28+
pull: `[#${pull}](https://github.com/${repo}/pull/${pull})`,
29+
user: `[@${user}](https://github.com/${user})`,
30+
};
31+
return {
32+
links,
33+
pull,
34+
user,
35+
};
36+
},
37+
async getInfoFromPullRequest({ pull, repo }) {
38+
const { commit, user } = data;
39+
const links = {
40+
commit: `[\`${commit}\`](https://github.com/${repo}/commit/${commit})`,
41+
pull: `[#${pull}](https://github.com/${repo}/pull/${pull})`,
42+
user: `[@${user}](https://github.com/${user})`,
43+
};
44+
return {
45+
commit,
46+
links,
47+
user,
48+
};
49+
},
50+
}),
51+
);
52+
53+
const getChangeset = (
54+
content: string,
55+
commit: string | undefined,
56+
): [NewChangesetWithCommit, VersionType, null | Record<string, any>] => [
57+
{
58+
...parse(
59+
`---
60+
pkg: "minor"
61+
---
62+
63+
something
64+
${content}
65+
`,
66+
),
67+
commit,
68+
id: 'some-id',
69+
},
70+
'minor',
71+
{ repo: data.repo },
72+
];
73+
74+
describe('changelog', () => {
75+
it('formats dependency release lines', async () => {
76+
const changesets: NewChangesetWithCommit[] = [
77+
{
78+
commit: 'abc123',
79+
id: 'fake-id',
80+
releases: [],
81+
summary: 'update deps',
82+
},
83+
];
84+
const deps: ModCompWithPackage[] = [
85+
{
86+
changesets: ['fake-id'],
87+
dir: '/fake/path',
88+
name: '@hey-api/openapi-ts',
89+
newVersion: '0.0.2',
90+
oldVersion: '0.0.1',
91+
packageJson: {
92+
name: '@hey-api/openapi-ts',
93+
version: '0.0.1',
94+
},
95+
type: 'patch',
96+
},
97+
];
98+
99+
const line = await changelog.getDependencyReleaseLine(changesets, deps, {
100+
repo: 'org/repo',
101+
});
102+
103+
expect(line).toEqual(
104+
'### Updated Dependencies:\n - @hey-api/[email protected]',
105+
);
106+
});
107+
108+
it('formats regular release lines', async () => {
109+
const changeset: NewChangesetWithCommit = {
110+
commit: 'abc123',
111+
id: 'fake-id',
112+
releases: [],
113+
summary: 'Fixed bug in parser',
114+
};
115+
116+
const line = await changelog.getReleaseLine(changeset, 'patch', {
117+
repo: 'org/repo',
118+
});
119+
120+
expect(line).toContain('Fixed bug in parser');
121+
expect(line).toContain('abc123');
122+
});
123+
124+
it('with multiple authors', async () => {
125+
expect(
126+
await changelog.getReleaseLine(
127+
...getChangeset(
128+
['author: @one', 'author: @two'].join('\n'),
129+
data.commit,
130+
),
131+
),
132+
).toEqual(
133+
`\n- something ([#1613](https://github.com/hey-api/openapi-ts/pull/1613)) ([\`a085003\`](https://github.com/hey-api/openapi-ts/commit/a085003)) by [@one](https://github.com/one), [@two](https://github.com/two)`,
134+
);
135+
});
136+
137+
describe.each(['author', 'user'])(
138+
'override author with %s keyword',
139+
(keyword) => {
140+
it.each(['with @', 'without @'])('%s', async (kind) => {
141+
expect(
142+
await changelog.getReleaseLine(
143+
...getChangeset(
144+
`${keyword}: ${kind === 'with @' ? '@' : ''}other`,
145+
data.commit,
146+
),
147+
),
148+
).toEqual(
149+
`\n- something ([#1613](https://github.com/hey-api/openapi-ts/pull/1613)) ([\`a085003\`](https://github.com/hey-api/openapi-ts/commit/a085003)) by [@other](https://github.com/other)`,
150+
);
151+
});
152+
},
153+
);
154+
155+
describe.each([data.commit, 'wrongcommit', undefined])(
156+
'with commit from changeset of %s',
157+
(commitFromChangeset) => {
158+
describe.each(['pr', 'pull request', 'pull'])(
159+
'override pr with %s keyword',
160+
(keyword) => {
161+
it.each(['with #', 'without #'])('%s', async (kind) => {
162+
expect(
163+
await changelog.getReleaseLine(
164+
...getChangeset(
165+
`${keyword}: ${kind === 'with #' ? '#' : ''}${data.pull}`,
166+
commitFromChangeset,
167+
),
168+
),
169+
).toEqual(
170+
`\n- something ([#1613](https://github.com/hey-api/openapi-ts/pull/1613)) ([\`a085003\`](https://github.com/hey-api/openapi-ts/commit/a085003)) by [@someone](https://github.com/someone)`,
171+
);
172+
});
173+
},
174+
);
175+
176+
it('override commit with commit keyword', async () => {
177+
expect(
178+
await changelog.getReleaseLine(
179+
...getChangeset(`commit: ${data.commit}`, commitFromChangeset),
180+
),
181+
).toEqual(
182+
`\n- something ([#1613](https://github.com/hey-api/openapi-ts/pull/1613)) ([\`a085003\`](https://github.com/hey-api/openapi-ts/commit/a085003)) by [@someone](https://github.com/someone)`,
183+
);
184+
});
185+
},
186+
);
187+
});

0 commit comments

Comments
 (0)