Skip to content

Commit 4b03708

Browse files
committed
Call the generate changelog workflow from the create release
1 parent a0550a6 commit 4b03708

File tree

4 files changed

+59
-33
lines changed

4 files changed

+59
-33
lines changed

.github/workflow-scripts/__tests__/generateChangelog-test.js

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
* @format
88
*/
99

10-
const { generateChangelog,
10+
const {
11+
generateChangelog,
1112
_computePreviousVersionFrom,
1213
_generateChangelog,
1314
_pushCommit,
14-
_createPR } = require('../generateChangelog');
15+
_createPR,
16+
} = require('../generateChangelog');
1517

1618
const silence = () => {};
1719
const mockGetNpmPackageInfo = jest.fn();
@@ -40,27 +42,29 @@ describe('Generate Changelog', () => {
4042
const receivedVersion = await _computePreviousVersionFrom(currentVersion);
4143

4244
expect(receivedVersion).toEqual(expectedVersion);
43-
})
45+
});
4446

45-
it('returns previous rc version when rc is > 1', async () => {
47+
it('returns previous rc version when rc is > 1', async () => {
4648
const currentVersion = '0.78.0-rc.5';
4749
const expectedVersion = '0.78.0-rc.4';
4850

4951
const receivedVersion = await _computePreviousVersionFrom(currentVersion);
5052

5153
expect(receivedVersion).toEqual(expectedVersion);
52-
})
54+
});
5355

5456
it('returns previous patch version when rc is 0', async () => {
5557
const currentVersion = '0.78.0-rc.0';
5658
const expectedVersion = '0.77.1';
5759

58-
mockGetNpmPackageInfo.mockReturnValueOnce(Promise.resolve({version: '0.77.1'}));
60+
mockGetNpmPackageInfo.mockReturnValueOnce(
61+
Promise.resolve({version: '0.77.1'}),
62+
);
5963

6064
const receivedVersion = await _computePreviousVersionFrom(currentVersion);
6165

6266
expect(receivedVersion).toEqual(expectedVersion);
63-
})
67+
});
6468

6569
it('returns patch 0 when patch is 1', async () => {
6670
const currentVersion = '0.78.1';
@@ -88,10 +92,12 @@ describe('Generate Changelog', () => {
8892
expect(receivedVersion).toBeNull();
8993
});
9094

91-
it('throws an error when the version can\'t be parsed', async () => {
95+
it("throws an error when the version can't be parsed", async () => {
9296
const currentVersion = '0.78.0-rc0';
9397

94-
await expect(_computePreviousVersionFrom(currentVersion)).rejects.toThrow();
98+
await expect(
99+
_computePreviousVersionFrom(currentVersion),
100+
).rejects.toThrow();
95101
});
96102
});
97103

@@ -121,7 +127,10 @@ describe('Generate Changelog', () => {
121127
expect(mockRun).toHaveBeenNthCalledWith(1, 'git checkout main');
122128
expect(mockRun).toHaveBeenNthCalledWith(2, 'git fetch');
123129
expect(mockRun).toHaveBeenNthCalledWith(3, 'git pull origin main');
124-
expect(mockRun).toHaveBeenNthCalledWith(4, `npx ${expectedCommandArgs.join(' ')}`);
130+
expect(mockRun).toHaveBeenNthCalledWith(
131+
4,
132+
`npx ${expectedCommandArgs.join(' ')}`,
133+
);
125134
});
126135
});
127136

@@ -132,10 +141,19 @@ describe('Generate Changelog', () => {
132141
_pushCommit(currentVersion);
133142

134143
expect(mockRun).toHaveBeenCalledTimes(4);
135-
expect(mockRun).toHaveBeenNthCalledWith(1, `git checkout -b changelog/v${currentVersion}`);
144+
expect(mockRun).toHaveBeenNthCalledWith(
145+
1,
146+
`git checkout -b changelog/v${currentVersion}`,
147+
);
136148
expect(mockRun).toHaveBeenNthCalledWith(2, 'git add CHANGELOG.md');
137-
expect(mockRun).toHaveBeenNthCalledWith(3, `git commit -m "[RN][Changelog] Add changelog for v${currentVersion}"`);
138-
expect(mockRun).toHaveBeenNthCalledWith(4, `git push origin changelog/v${currentVersion}`);
149+
expect(mockRun).toHaveBeenNthCalledWith(
150+
3,
151+
`git commit -m "[RN][Changelog] Add changelog for v${currentVersion}"`,
152+
);
153+
expect(mockRun).toHaveBeenNthCalledWith(
154+
4,
155+
`git push origin changelog/v${currentVersion}`,
156+
);
139157
});
140158
});
141159

@@ -147,10 +165,10 @@ describe('Generate Changelog', () => {
147165
mockFetch.mockReturnValueOnce(Promise.resolve({status: 401}));
148166

149167
const headers = {
150-
'Accept': 'Accept: application/vnd.github+json',
168+
Accept: 'Accept: application/vnd.github+json',
151169
'X-GitHub-Api-Version': '2022-11-28',
152170
Authorization: `Bearer ${token}`,
153-
}
171+
};
154172

155173
const content = `
156174
## Summary
@@ -160,7 +178,7 @@ Add Changelog for ${currentVersion}
160178
[Internal] - Add Changelog for ${currentVersion}
161179
162180
## Test Plan:
163-
N/A`
181+
N/A`;
164182

165183
const body = {
166184
title: `[RN][Changelog] Add changelog for v${currentVersion}`,
@@ -178,25 +196,26 @@ N/A`
178196
method: 'POST',
179197
headers: headers,
180198
body: JSON.stringify(body),
181-
}
199+
},
182200
);
183201
});
184202
it('Returns the pr url', async () => {
185203
const currentVersion = '0.79.0-rc5';
186204
const token = 'token';
187-
const expectedPrURL = 'https://github.com/facebook/react-native/pulls/1234';
205+
const expectedPrURL =
206+
'https://github.com/facebook/react-native/pulls/1234';
188207

189208
const returnedObject = {
190209
status: 201,
191210
json: () => Promise.resolve({html_url: expectedPrURL}),
192-
}
211+
};
193212
mockFetch.mockReturnValueOnce(Promise.resolve(returnedObject));
194213

195214
const headers = {
196-
'Accept': 'Accept: application/vnd.github+json',
215+
Accept: 'Accept: application/vnd.github+json',
197216
'X-GitHub-Api-Version': '2022-11-28',
198217
Authorization: `Bearer ${token}`,
199-
}
218+
};
200219

201220
const content = `
202221
## Summary
@@ -206,7 +225,7 @@ Add Changelog for ${currentVersion}
206225
[Internal] - Add Changelog for ${currentVersion}
207226
208227
## Test Plan:
209-
N/A`
228+
N/A`;
210229

211230
const body = {
212231
title: `[RN][Changelog] Add changelog for v${currentVersion}`,
@@ -215,7 +234,7 @@ N/A`
215234
body: content,
216235
};
217236

218-
const receivedPrURL = await _createPR(currentVersion, token)
237+
const receivedPrURL = await _createPR(currentVersion, token);
219238

220239
expect(mockFetch).toHaveBeenCalledTimes(1);
221240
expect(mockFetch).toHaveBeenCalledWith(
@@ -224,7 +243,7 @@ N/A`
224243
method: 'POST',
225244
headers: headers,
226245
body: JSON.stringify(body),
227-
}
246+
},
228247
);
229248
expect(receivedPrURL).toEqual(expectedPrURL);
230249
});

.github/workflow-scripts/generateChangelog.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ async function _computePreviousVersionFrom(version) {
3131
} else {
3232
if (Number(patch) === 0) {
3333
// No need to generate the changelog for 0.X.0 as we already generated it from RCs
34-
log(`Skipping changelog generation for ${version} as we already have it from the RCs`);
34+
log(
35+
`Skipping changelog generation for ${version} as we already have it from the RCs`,
36+
);
3537
return null;
3638
}
3739
return `0.${minor}.${Number(patch) - 1}`;
@@ -43,8 +45,7 @@ function _generateChangelog(previousVersion, version, token) {
4345
run('git checkout main');
4446
run('git fetch');
4547
run('git pull origin main');
46-
const generateChangelogComand =
47-
`npx @rnx-kit/rn-changelog-generator --base v${previousVersion} --compare v${version} --repo . --changelog ./CHANGELOG.md --token ${token}`;
48+
const generateChangelogComand = `npx @rnx-kit/rn-changelog-generator --base v${previousVersion} --compare v${version} --repo . --changelog ./CHANGELOG.md --token ${token}`;
4849
run(generateChangelogComand);
4950
}
5051

@@ -67,12 +68,12 @@ Add Changelog for ${version}
6768
[Internal] - Add Changelog for ${version}
6869
6970
## Test Plan:
70-
N/A`
71+
N/A`;
7172

7273
const response = await fetch(url, {
7374
method: 'POST',
7475
headers: {
75-
'Accept': 'Accept: application/vnd.github+json',
76+
Accept: 'Accept: application/vnd.github+json',
7677
'X-GitHub-Api-Version': '2022-11-28',
7778
Authorization: `Bearer ${token}`,
7879
},
@@ -85,7 +86,9 @@ N/A`
8586
});
8687

8788
if (response.status !== 201) {
88-
throw new Error(`Failed to create PR: ${response.status} ${response.statusText}`);
89+
throw new Error(
90+
`Failed to create PR: ${response.status} ${response.statusText}`,
91+
);
8992
}
9093

9194
const data = await response.json();
@@ -114,4 +117,4 @@ module.exports = {
114117
_generateChangelog,
115118
_pushCommit,
116119
_createPR,
117-
}
120+
};

.github/workflows/create-changelog.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
name: Generate Changelog
22

33
on:
4-
pull_request:
54
workflow_call:
65

76
jobs:
@@ -25,5 +24,5 @@ jobs:
2524
with:
2625
script: |
2726
const {generateChangelog} = require('./.github/workflow-scripts/generateChangelog');
28-
const version = 'v0.79.0-rc.3' //"${{ github.ref_name }}";
27+
const version = '${{ github.ref_name }}';
2928
await generateChangelog(version, '${{secrets.REACT_NATIVE_BOT_GITHUB_TOKEN}}');

.github/workflows/publish-release.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,3 +237,8 @@ jobs:
237237
const {verifyArtifactsAreOnMaven} = require('./.github/workflow-scripts/verifyArtifactsAreOnMaven.js');
238238
const version = "${{ github.ref_name }}";
239239
await verifyArtifactsAreOnMaven(version);
240+
241+
create_changelog:
242+
needs: build_npm_package
243+
uses: ./.github/workflows/create-changelog.yml
244+
secrets: inherit

0 commit comments

Comments
 (0)