Setup full-icu dataset for the Node.js runtime GitHub Actions uses.
GitHub Actions now supports node16
runtime
for JavaScript actions and Node.js 16 has full-icu
support by default.
Consider migrating your actions to use node16
.
GitHub Actions' JavaScript action supports only Node.js 12 as a runtime.
As Node.js 12 is built with --with-intl=small-icu
option by default, it
contains only English locales.
This gonna be problematic when we want to use ICU dependent features[^1] with non-English locales:
const options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }
// Works properly for English locales
// want: "Friday, September 25, 2020", actual: "Friday, September 25, 2020"
console.log((new Date()).toLocaleDateString('en-US', options))
// NOT WORKING FOR NON-ENGLISH LOCALES!
// want: "2020年9月25日金曜日", actual: "Friday, September 25, 2020"
console.log((new Date()).toLocaleDateString('ja-JP', options))
This action fixes locale-related issues by installing full ICU datasets and setting
NODE_ICU_DATA
environment variable properly to let Node.js use them.
Just run sarisia/setup-icu@v1
once in a job.
steps:
- uses: sarisia/setup-icu@v1
- uses: sarisia/action-uses-icu-function@v2
If your workflow has steps that run node
command from shell, it may fail because of
ICU version mismatch.
This may fail:
steps:
- uses: actions/setup-node@v1
with:
node-version: 10
- uses: sarisia/setup-icu@v1
# THIS MAY FAIL!
- run: node script.js
To avoid that, set noexport
to true
and set NODE_ICU_DATA
to outputs.icu-data-dir
manually:
steps:
- uses: actions/setup-node@v1
with:
node-version: 10
- uses: sarisia/setup-icu@v1
id: setup-icu
with:
noexport: true
- uses: sarisia/action-uses-icu-function@v2
env:
NODE_ICU_DATA: ${{ steps.setup-icu.outputs.icu-data-dir }}
noexport
: Set true to avoid exportingNODE_ICU_DATA
environment variable. Default:false
icu-data-dir
: Path of the directory contains ICU data.
[^1] see documentation for full lists