Skip to content

[#662] Use sun position calculations to show partly cloudy night label/icons #67

[#662] Use sun position calculations to show partly cloudy night label/icons

[#662] Use sun position calculations to show partly cloudy night label/icons #67

Workflow file for this run

name: Validate localization files
on:
pull_request:
paths:
- 'src/localize/languages/*.json'
jobs:
find-new-languages:
runs-on: ubuntu-latest
outputs:
languages: ${{ steps.get-languages.outputs.result }}
steps:
- name: Get new language(s) being added
id: get-languages
uses: actions/github-script@v7
with:
script: |
const pullInfo = context.issue;
pullInfo.pull_number = pullInfo.number;
delete pullInfo.number;
const files = await github.rest.pulls.listFiles(pullInfo);
const newLanguages = files.data.filter(file => {
if (!file.filename.startsWith('src/localize/languages/')) {
return false;
}
if (file.status !== 'added') {
return false;
}
return true;
});
const langCodes = newLanguages.map(l => l.filename.replace('src/localize/languages/', '').replace('.json', ''));
console.log('New languages added:', langCodes.join(', '));
return langCodes.length > 0 ? langCodes : null;
validate-added-languages:
needs: find-new-languages
runs-on: ubuntu-latest
if: ${{ fromJSON(needs.find-new-languages.outputs.languages) != null }}
strategy:
fail-fast: true
matrix:
language: ${{ fromJSON(needs.find-new-languages.outputs.languages) }}
steps:
- uses: actions/checkout@v4
- name: Ensure src/localize/localize.ts imports new language
env:
LANGUAGE: ${{ matrix.language }}
run: |
export NORMALIZED_LANG=${LANGUAGE/-/_}
grep "^import \* as $NORMALIZED_LANG from './languages/$LANGUAGE.json';" src/localize/localize.ts || \
(echo "src/localize/localize.ts does not import $LANGUAGE.json" && exit 1)
- name: Ensure src/localize/localize.ts consumes new language
env:
LANGUAGE: ${{ matrix.language }}
run: |
export NORMALIZED_LANG=${LANGUAGE/-/_}
grep "^\s*$NORMALIZED_LANG," src/localize/localize.ts || \
(echo "src/localize/localize.ts does not consume $NORMALIZED_LANG in languages variable" && exit 1)
- name: Check if language needs to be in translation workflow
id: needs-translate-yml
env:
LANGUAGE: ${{ matrix.language }}
run: |
if [[ $LANGUAGE == *"-"* ]];
then
# See supported language list at https://cloud.google.com/translate/docs/languages
if [[ $LANGUAGE == "zh-TW" || $LANGUAGE == "zh-CN" ]];
then
echo "::set-output name=result::true";
else
echo "::set-output name=result::false";
fi;
else
echo "::set-output name=result::true";
fi
- name: Ensure .github/workflows/translate.yml updated
if: ${{ steps.needs-translate-yml.outputs.result == 'true' }}
env:
LANGUAGE: ${{ matrix.language }}
run: |
grep "to: '.*$LANGUAGE" .github/workflows/translate.yml || \
(echo ".github/workflows/translate.yml missing entry for $LANGUAGE" && exit 1)
- name: Ensure cypress/e2e/localization.cy.ts updated
env:
LANGUAGE: ${{ matrix.language }}
run: |
grep -E "^\s*'?$LANGUAGE'?: '" cypress/e2e/localization.cy.ts || \
(echo "cypress/e2e/localization.cy.ts expectedTranslations missing entry for $LANGUAGE" && exit 1)