Skip to content

Commit f5e7187

Browse files
Only generate one change file if change type is none or prerelease (#4234)
1 parent 3de3899 commit f5e7187

3 files changed

Lines changed: 43 additions & 13 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"type": "none",
3+
"area": "improvement",
4+
"workstream": "",
5+
"comment": "Only generate one change file if change type is none or prerelease",
6+
"packageName": "@azure/communication-react",
7+
"email": "2684369+JamesBurnside@users.noreply.github.com",
8+
"dependentChangeType": "none"
9+
}

common/scripts/changelog/change.mjs

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,38 @@ async function main() {
3838
...args
3939
];
4040
await exec(cmd.join(' '));
41-
await duplicateChangeFiles();
41+
await duplicateChangeFile();
4242
}
4343

44-
async function duplicateChangeFiles() {
44+
async function duplicateChangeFile() {
4545
const gitLogStdout = await exec_output(`git log -1 --name-status`);
46-
const newChangeFiles = parseNewChangeFiles(gitLogStdout);
47-
if (newChangeFiles.length === 0) {
46+
const newChangeFilesFilenames = parseNewChangeFiles(gitLogStdout);
47+
if (newChangeFilesFilenames.length === 0) {
48+
console.log('No new change files detected. Nothing to duplicate.');
4849
return;
50+
} else if (newChangeFilesFilenames.length > 1) {
51+
throw new Error(`Expected only one change file, but found ${newChangeFilesFilenames.length} change files`);
4952
}
5053

51-
console.log(`Duplicating ${newChangeFiles.length} change files into ${CHANGE_DIR_BETA}`);
52-
for (const file of newChangeFiles) {
53-
fs.copyFileSync(path.join(CHANGE_DIR, file), path.join(CHANGE_DIR_BETA, file));
54+
const changeFilename = newChangeFilesFilenames[0];
55+
const filepath = path.join(CHANGE_DIR, changeFilename);
56+
const changeFile = JSON.parse(fs.readFileSync(filepath, 'utf-8'));
57+
58+
// if type is none, we don't need to duplicate the change file.
59+
if (changeFile.type !== "none") {
60+
console.log(`Duplicating ${filepath} change files into ${CHANGE_DIR_BETA}`);
61+
fs.copyFileSync(filepath, path.join(CHANGE_DIR_BETA, changeFilename));
62+
await exec(`git add ${CHANGE_DIR_BETA}`);
63+
await exec(`git commit -m 'Duplicate change files for beta release'`);
64+
}
65+
66+
// if the type is prerelease, we can delete the stable changefile that was created.
67+
if (changeFile.type === "prerelease") {
68+
console.log(`Deleting stable change file ${filepath}`);
69+
fs.unlinkSync(filepath);
70+
await exec(`git add ${CHANGE_DIR}`);
71+
await exec(`git commit -m 'Remove unecessary stable change file'`);
5472
}
55-
await exec(`git add ${CHANGE_DIR_BETA}`);
56-
await exec(`git commit -m 'Duplicate change files for beta release'`);
5773
}
5874

5975
await main();

common/scripts/changelog/check.mjs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,18 @@ import { parseNewChangeFiles } from "./utils.mjs";
1717

1818
async function main() {
1919
const [base, head] = parseArgs(process.argv);
20-
const gitLogStdout = await exec_output(`git log --name-status ${base}..${head} -- ${path.join(REPO_ROOT, 'change/')}`);
21-
const newChangeFiles = parseNewChangeFiles(gitLogStdout);
22-
if (!newChangeFiles?.length) {
20+
const gitLogStdoutStableChangeFiles = await exec_output(`git log --name-status ${base}..${head} -- ${path.join(REPO_ROOT, 'change/')}`);
21+
const gitLogStdoutBetaChangeFiles = await exec_output(`git log --name-status ${base}..${head} -- ${path.join(REPO_ROOT, 'change-beta/')}`);
22+
23+
const newStableChangeFiles = parseNewChangeFiles(gitLogStdoutStableChangeFiles);
24+
const newBetaChangeFiles = parseNewChangeFiles(gitLogStdoutBetaChangeFiles);
25+
const newChangeFilesCount = (newStableChangeFiles?.length ?? 0) + (newBetaChangeFiles?.length ?? 0);
26+
27+
if (newChangeFilesCount === 0) {
2328
console.error('No changefile detected! Please run `rush changelog` to document your change.');
2429
process.exit(1);
2530
}
26-
console.log(`Found ${newChangeFiles.length} changefiles. All is good!`)
31+
console.log(`Found ${newChangeFilesCount} changefiles. All is good!`)
2732
}
2833

2934
function parseArgs(args) {

0 commit comments

Comments
 (0)