From 0df181a5a1dd8ba998e4eae0bb2faff022a74b2a Mon Sep 17 00:00:00 2001 From: Lenvin Gonsalves <41874033+98lenvi@users.noreply.github.com> Date: Fri, 16 Sep 2022 03:33:40 +0530 Subject: [PATCH] tools: add timezone update workflow Fixes: https://github.com/nodejs/node/issues/43134 PR-URL: https://github.com/nodejs/node/pull/43988 Reviewed-By: Steven R Loomis --- .github/workflows/timezone-update.yml | 48 +++++++++++++++++++++++++++ tools/update-timezone.mjs | 39 ++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 .github/workflows/timezone-update.yml create mode 100755 tools/update-timezone.mjs diff --git a/.github/workflows/timezone-update.yml b/.github/workflows/timezone-update.yml new file mode 100644 index 00000000000000..9d567415f4b2a6 --- /dev/null +++ b/.github/workflows/timezone-update.yml @@ -0,0 +1,48 @@ +name: Timezone update +on: + schedule: + # Run once a week at 00:05 AM UTC on Sunday. + - cron: 5 0 * * 0 + + workflow_dispatch: + +jobs: + timezone_update: + if: github.repository == 'nodejs/node' + runs-on: ubuntu-latest + + steps: + - name: Checkout nodejs/node + uses: actions/checkout@v3 + with: + persist-credentials: false + + - name: Checkout unicode-org/icu-data + uses: actions/checkout@v3 + with: + path: icu-data + persist-credentials: false + repository: unicode-org/icu-data + + - run: ./tools/update-timezone.mjs + + - name: Open Pull Request + uses: gr2m/create-or-update-pull-request-action@6720400cad8e74d7adc64640e4e6ea6748b83d8f # Create a PR or update the Action's existing PR + env: + GITHUB_TOKEN: ${{ secrets.GH_USER_TOKEN }} + with: + author: Node.js GitHub Bot + body: | + This PR was generated by tools/timezone-update.yml. + + Updates the ICU files as per the instructions present in https://github.com/nodejs/node/blob/main/doc/contributing/maintaining-icu.md#time-zone-data + + To test, build node off this branch & log the version of tz using + ```js + console.log(process.versions.tz) + ``` + branch: actions/timezone-update + commit-message: 'deps: update timezone' + labels: dependencies + title: 'deps: update timezone' + reviewers: \@nodejs/i18n-api diff --git a/tools/update-timezone.mjs b/tools/update-timezone.mjs new file mode 100755 index 00000000000000..33da42f4e983fa --- /dev/null +++ b/tools/update-timezone.mjs @@ -0,0 +1,39 @@ +#!/usr/bin/env node +// Usage: tools/update-timezone.mjs +import { execSync, spawnSync } from 'node:child_process'; +import { renameSync, readdirSync, rmSync } from 'node:fs'; +import { exit } from 'node:process'; + +const fileNames = [ + 'zoneinfo64.res', + 'windowsZones.res', + 'timezoneTypes.res', + 'metaZones.res', +]; + +const availableVersions = readdirSync('icu-data/tzdata/icunew', { withFileTypes: true }) +.filter((dirent) => dirent.isDirectory()) +.map((dirent) => dirent.name); + +const currentVersion = process.versions.tz; +const latestVersion = availableVersions.sort().at(-1); + +if (latestVersion === currentVersion) { + console.log(`Terminating early, tz version is latest @ ${currentVersion}`); + exit(); +} + +execSync('bzip2 -d deps/icu-small/source/data/in/icudt*.dat.bz2'); +fileNames.forEach((file) => { + renameSync(`icu-data/tzdata/icunew/${latestVersion}/44/le/${file}`, `deps/icu-small/source/data/in/${file}`); + spawnSync( + 'icupkg', [ + '-a', + file, + 'icudt*.dat', + ], { cwd: 'deps/icu-small/source/data/in/' } + ); + rmSync(`deps/icu-small/source/data/in/${file}`); +}); +execSync('bzip2 -z deps/icu-small/source/data/in/icudt*.dat'); +rmSync('icu-data', { recursive: true });