From baef8d8b21182b74598c178e6ffa1617a032cce6 Mon Sep 17 00:00:00 2001 From: Yansong Yang Date: Wed, 20 Mar 2024 14:34:49 -0500 Subject: [PATCH] [Release Notes Automation] Set the default time zone to PST (#533) * Set the default time zone to Central Time before running the scripts * fix typo * update the default time zone to PST * update comments * update logs --------- Co-authored-by: calebk1 <74737634+calebk1@users.noreply.github.com> --- .github/scripts/release_notes/index.js | 9 +++++++++ .../scripts/release_notes/update-release-notes.js | 12 ++++++------ .github/scripts/release_notes/utils.js | 6 +++--- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/.github/scripts/release_notes/index.js b/.github/scripts/release_notes/index.js index 45ff7a27e5..3c8291483b 100644 --- a/.github/scripts/release_notes/index.js +++ b/.github/scripts/release_notes/index.js @@ -21,6 +21,15 @@ if (token == undefined) { throw new Error("token is undefined") } +//before running the script, make sure the default time zone is set to PST in the GitHub action +process.env.TZ = "America/Los_Angeles" + +const offset = new Date().getTimezoneOffset() + +if (offset != 420) { + throw new Error("The default time zone is not set to PST") +} + run() async function run() { diff --git a/.github/scripts/release_notes/update-release-notes.js b/.github/scripts/release_notes/update-release-notes.js index fdd7eaf428..aa0627b3f1 100644 --- a/.github/scripts/release_notes/update-release-notes.js +++ b/.github/scripts/release_notes/update-release-notes.js @@ -12,7 +12,7 @@ governing permissions and limitations under the License. const { fetchReleaseInfo } = require('./github-release'); const { fetchAndroidReleaseInfo } = require('./android-release'); -const { capitalizeFirstLetter, convertIOSDateToRleaseDateFormat, extractReleaseNotes } = require('./utils'); +const { capitalizeFirstLetter, convertISODateToRleaseDateFormat, extractReleaseNotes } = require('./utils'); const lodashTemplate = require('lodash.template'); const fs = require("fs"); @@ -102,12 +102,12 @@ function extractBOMTableContent(releaseNote) { return newLines } -function generateReleaseNoteSection(IOSDateString, platform, extension, version, releaseNote) { +function generateReleaseNoteSection(ISODateString, platform, extension, version, releaseNote) { let array = extractReleaseNotes(releaseNote) // remove the empty lines array = array.filter(line => line.trim() != '') let releaseNoteSection = releaseNoteTemplateGenerator({ - date: convertIOSDateToRleaseDateFormat(IOSDateString), + date: convertISODateToRleaseDateFormat(ISODateString), title: `${platform} ${extension} ${version}`, note: array.join('\n') }) @@ -125,10 +125,10 @@ function generateReleaseNoteSectionWithoutDateLine(platform, extension, version, return releaseNoteSection } -function generateBOMReleaseNoteSection(IOSDateString, platform, extension, version, releaseNote) { +function generateBOMReleaseNoteSection(ISODateString, platform, extension, version, releaseNote) { let array = extractBOMTableContent(releaseNote) let releaseNoteSection = BOMreleaseNoteTemplateGenerator({ - date: convertIOSDateToRleaseDateFormat(IOSDateString), + date: convertISODateToRleaseDateFormat(ISODateString), title: generateReleaseTitle(platform, extension, version), note: array.join('\n') }) @@ -199,7 +199,7 @@ async function updateReleaseNotesPage(filePath, releaseInfoArray) { console.error(`Already updated: ${titleLine}`) continue } - let dateStr = convertIOSDateToRleaseDateFormat(releaseInfo.published_at) + let dateStr = convertISODateToRleaseDateFormat(releaseInfo.published_at) let dateLine = `## ${dateStr}` // If the date line exists in the file, find the index of the date line and add the release notes after it. if (hasLineStartWith(dateLine, contentLines)) { diff --git a/.github/scripts/release_notes/utils.js b/.github/scripts/release_notes/utils.js index f4e2106247..3f46095b12 100644 --- a/.github/scripts/release_notes/utils.js +++ b/.github/scripts/release_notes/utils.js @@ -65,8 +65,8 @@ function capitalizeFirstLetter(string) { } // TODO: consider using dayjs to handle date format -function convertIOSDateToRleaseDateFormat(ios1086DateStr) { - const date = new Date(ios1086DateStr) +function convertISODateToRleaseDateFormat(iso8601DateStr) { + const date = new Date(iso8601DateStr) const month = date.getMonth() const day = date.getDate() const year = date.getFullYear() @@ -80,6 +80,6 @@ module.exports = { releaseFileContainsLineStartWith, saveJsonObjToFile, extractReleaseNotes, - convertIOSDateToRleaseDateFormat, + convertISODateToRleaseDateFormat, capitalizeFirstLetter } \ No newline at end of file