@@ -4,15 +4,14 @@ import github from '@actions/github';
44import Eleventy from "@11ty/eleventy" ;
55import fs from "fs/promises" ;
66import playwright from "playwright" ;
7+ import { execSync } from 'child_process' ;
78
89const EDGE_OT_ROOT = "https://developer.microsoft.com/en-us" ;
910const 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.
1213const 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
1716async 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
4274async 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