@@ -4,15 +4,14 @@ import github from '@actions/github';
4
4
import Eleventy from "@11ty/eleventy" ;
5
5
import fs from "fs/promises" ;
6
6
import playwright from "playwright" ;
7
+ import { execSync } from 'child_process' ;
7
8
8
9
const EDGE_OT_ROOT = "https://developer.microsoft.com/en-us" ;
9
10
const EDGE_OT_PAGE = `${ EDGE_OT_ROOT } /microsoft-edge/origin-trials/trials` ;
10
11
// If Beta becomes stable within the next N coming days, generate the release notes for Canary.
11
12
// This way, the release notes are ready for when Canary becomes Beta.
12
13
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-" ;
16
15
17
16
async function fetchChromeStatusAPI ( url ) {
18
17
const response = await fetch ( url ) ;
@@ -31,12 +30,45 @@ function longDate(dateString) {
31
30
} ) ;
32
31
}
33
32
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` ) ;
36
55
}
37
56
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` ;
40
72
}
41
73
42
74
async function getActiveEdgeOTs ( ) {
@@ -162,13 +194,21 @@ async function main() {
162
194
`Preparing the beta release notes for ${ nextBetaVersion } (to be released on ${ nextBetaReleaseDate } ).`
163
195
) ;
164
196
197
+ const branchName = BRANCH_NAME_PREFIX + nextBetaVersion ;
198
+
165
199
// --------------------------------------------------
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.
167
201
// --------------------------------------------------
168
202
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.` ) ;
172
212
process . exit ( 0 ) ;
173
213
}
174
214
@@ -287,15 +327,35 @@ async function main() {
287
327
await fs . writeFile ( releaseNotesPath , releaseNotesContent ) ;
288
328
289
329
// --------------------------------------------------
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.
291
351
// --------------------------------------------------
292
352
293
353
console . log ( "Opening an issue to notify the team about the new release notes draft." ) ;
294
354
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.` ;
296
356
297
357
const octokit = github . getOctokit ( process . env . token ) ;
298
- const { data : issue } = await octokit . rest . issues . create ( {
358
+ await octokit . rest . issues . create ( {
299
359
owner : "MicrosoftDocs" ,
300
360
repo : "edge-developer" ,
301
361
title,
0 commit comments