E584 Merge pull request #3589 from MicrosoftDocs/user/pabrosse/relnotes-sc… · MicrosoftDocs/edge-developer@cbdf636 · GitHub
[go: up one dir, main page]

Skip to content

Commit cbdf636

Browse files
Merge pull request #3589 from MicrosoftDocs/user/pabrosse/relnotes-script
Create new branch names for relnotes and avoid re-opening issue if a relnote already exists
1 parent a030bbe commit cbdf636

File tree

2 files changed

+75
-30
lines changed

2 files changed

+75
-30
lines changed

.github/workflows/webplat-relnotes.yaml

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,4 @@ jobs:
3030
- name: Generate release notes
3131
run: |
3232
cd scripts
33-
token=${{ secrets.GITHUB_TOKEN }} node web-platform-release-notes.js
34-
35-
- name: Commit changes if needed
36-
run: |
37-
files=$(git ls-files --others --exclude-standard)
38-
if [ -n "$files" ]; then
39-
echo "Committing the new release notes file."
40-
git config --local user.email "${{ github.actor }}@users.noreply.github.com"
41-
git config --local user.name "${{ github.actor }}"
42-
git checkout -b web-platform-release-notes
43-
git add .
44-
git commit -m "New beta web platform release notes"
45-
git push origin web-platform-release-notes
46-
else
47-
echo "No new files to add."
48-
fi
33+
actor=${{ github.actor }} token=${{ secrets.GITHUB_TOKEN }} node web-platform-release-notes.js

scripts/web-platform-release-notes.js

Lines changed: 74 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ import github from '@actions/github';
44
import Eleventy from "@11ty/eleventy";
55
import fs from "fs/promises";
66
import playwright from "playwright";
7+
import { execSync } from 'child_process';
78

89
const EDGE_OT_ROOT = "https://developer.microsoft.com/en-us";
910
const EDGE_OT_PAGE = `${EDGE_OT_ROOT}/microsoft-edge/origin-trials/trials`;
1011
// If Beta becomes stable within the next N coming days, generate the release notes for Canary.
1112
// This way, the release notes are ready for when Canary becomes Beta.
1213
const DAYS_NUMBER_BEFORE_RELNOTES_NOTICE = 15;
13-
// The Git branch name where the release notes will be generated.
14-
// Keep this in sync with thge webplat-releasenotes.yaml workflow file.
15-
const BRANCH_NAME = "web-platform-release-notes";
14+
const BRANCH_NAME_PREFIX = "web-platform-release-notes-";
1615

1716
async function fetchChromeStatusAPI(url) {
1817
const response = await fetch(url);
@@ -31,12 +30,45 @@ function longDate(dateString) {
3130
});
3231
}
3332

34-
function getReleaseNoteMDFilePath(version) {
35-
return `https://github.com/MicrosoftDocs/edge-developer/blob/${BRANCH_NAME}/microsoft-edge/web-platform/release-notes/${version}.md`;
33+
async function execute(cmd) {
34+
try {
35+
const stdout = await execSync(cmd);
36+
return stdout.toString();
37+
} catch (error) {
38+
console.error(`Error executing command "${cmd}": ${error.message}`);
39+
console.log(error.stdout.toString());
40+
process.exit(1);
41+
}
42+
}
43+
44+
async function releaseNotesAlreadyExists(version) {
45+
const response = await fetch(`https://raw.githubusercontent.com/MicrosoftDocs/edge-developer/refs/heads/main/microsoft-edge/web-platform/release-notes/${version}.md`);
46+
47+
// Github.com normally responds with 404 if the file doesn't exist. So this should catch it.
48+
if (response.status !== 200) {
49+
return false;
50+
}
51+
52+
// Just in case it doesn't, check the content too.
53+
const text = await response.text();
54+
return text.includes(`Microsoft Edge ${version} web platform release notes`);
3655
}
3756

38-
function getReleaseNoteRawMDFilePath(version) {
39-
return `https://raw.githubusercontent.com/MicrosoftDocs/edge-developer/refs/heads/${BRANCH_NAME}/microsoft-edge/web-platform/release-notes/${version}.md`;
57+
async function releaseNotesDraftAlreadyExists(version, branchName) {
58+
const response = await fetch(`https://raw.githubusercontent.com/MicrosoftDocs/edge-developer/refs/heads/${branchName}/microsoft-edge/web-platform/release-notes/${version}.md`);
59+
60+
// Github.com normally responds with 404 if the file doesn't exist. So this should catch it.
61+
if (response.status !== 200) {
62+
return false;
63+
}
64+
65+
// Just in case it doesn't, check the content too.
66+
const text = await response.text();
67+
return text.includes(`Microsoft Edge ${version} web platform release notes`);
68+
}
69+
70+
function getReleaseNoteMDFilePath(version, branchName) {
71+
return `https://github.com/MicrosoftDocs/edge-developer/blob/${branchName}/microsoft-edge/web-platform/release-notes/${version}.md`;
4072
}
4173

4274
async function getActiveEdgeOTs() {
@@ -162,13 +194,21 @@ async function main() {
162194
`Preparing the beta release notes for ${nextBetaVersion} (to be released on ${nextBetaReleaseDate}).`
163195
);
164196

197+
const branchName = BRANCH_NAME_PREFIX + nextBetaVersion;
198+
165199
// --------------------------------------------------
166-
// 2. Check if there isn't already a release notes draft for the next beta version.
200+
// 2. Check if there isn't already a published or draft release notes for the next beta version.
167201
// --------------------------------------------------
168202

169-
const rawFileResponse = await fetch(getReleaseNoteRawMDFilePath(nextBetaVersion));
170-
if (rawFileResponse.status === 200) {
171-
console.error(`A PR is already open for the next beta release notes. File exists: ${getReleaseNoteMDFilePath(nextBetaVersion)}.`);
203+
const alreadyExists = await releaseNotesAlreadyExists(nextBetaVersion);
204+
if (alreadyExists) {
205+
console.error(`Release notes for the next beta version ${nextBetaVersion} already exist.`);
206+
process.exit(0);
207+
}
208+
209+
const draftAlreadyExists = await releaseNotesDraftAlreadyExists(nextBetaVersion, branchName);
210+
if (draftAlreadyExists) {
211+
console.error(`Draft release notes for the next beta version ${nextBetaVersion} already exist on the ${branchName} branch.`);
172212
process.exit(0);
173213
}
174214

@@ -287,15 +327,35 @@ async function main() {
287327
await fs.writeFile(releaseNotesPath, releaseNotesContent);
288328

289329
// --------------------------------------------------
290-
// 8. Open an issue on the repo to notify the team about the new release notes draft.
330+
// 8. Commit the new file to a new branch.
331+
// --------------------------------------------------
332+
333+
console.log(`Committing the new file to branch ${branchName}...`);
334+
335+
console.log(`Configuring git with ${ process.env.actor }`);
336+
await execute(`git config --local user.email "${ process.env.actor }@users.noreply.github.com"`);
337+
await execute(`git config --local user.name "${ process.env.actor }"`);
338+
339+
console.log(`Creating branch ${branchName}`);
340+
await execute(`git checkout -b ${branchName}`);
341+
342+
console.log(`Adding and committing the new file`);
343+
await execute(`git add ${releaseNotesPath}`);
344+
await execute(`git commit -m "New web platform release notes for ${nextBetaVersion}"`);
345+
346+
console.log(`Pushing the file to the remote repo`);
347+
await execute(`git push origin ${branchName}`);
348+
349+
// --------------------------------------------------
350+
// 9. Open an issue on the repo to notify the team about the new release notes draft.
291351
// --------------------------------------------------
292352

293353
console.log("Opening an issue to notify the team about the new release notes draft.");
294354
const title = `Microsoft Edge Beta ${nextBetaVersion} web platform release notes ready for review`;
295-
const body = `The release notes draft for the next Microsoft Edge beta version ${nextBetaVersion} has been generated in [${nextBetaVersion}.md](${getReleaseNoteMDFilePath(nextBetaVersion)}) on the ${BRANCH_NAME} branch.\n\nPlease [create a pull request](https://github.com/MicrosoftDocs/edge-developer/compare/main...${BRANCH_NAME}), update the content as needed, and close this issue.`;
355+
const body = `The release notes draft for the next Microsoft Edge beta version ${nextBetaVersion} has been generated in [${nextBetaVersion}.md](${getReleaseNoteMDFilePath(nextBetaVersion, branchName)}) on the ${branchName} branch.\n\nPlease [create a pull request](https://github.com/MicrosoftDocs/edge-developer/compare/main...${branchName}), update the content as needed, and close this issue.`;
296356

297357
const octokit = github.getOctokit(process.env.token);
298-
const { data: issue } = await octokit.rest.issues.create({
358+
await octokit.rest.issues.create({
299359
owner: "MicrosoftDocs",
300360
repo: "edge-developer",
301361
title,

0 commit comments

Comments
 (0)
0