|
| 1 | +name: Update CLDR |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: "0 3 * * 1" # every Monday at 3AM UTC |
| 6 | + workflow_dispatch: # manual trigger |
| 7 | + |
| 8 | +jobs: |
| 9 | + update-cldr: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + |
| 12 | + steps: |
| 13 | + - uses: actions/checkout@v4 |
| 14 | + |
| 15 | + - name: Get latest CLDR release tag |
| 16 | + id: cldr |
| 17 | + run: | |
| 18 | + latest=$(curl -fsSL -H "Authorization: Bearer ${{ github.token }}" \ |
| 19 | + https://api.github.com/repos/unicode-org/cldr-json/releases/latest \ |
| 20 | + | jq -r .tag_name) |
| 21 | + if [ -z "$latest" ] || [ "$latest" = "null" ]; then |
| 22 | + echo "Failed to get latest CLDR release tag" |
| 23 | + exit 1 |
| 24 | + fi |
| 25 | + echo "tag=$latest" >> $GITHUB_OUTPUT |
| 26 | +
|
| 27 | + - name: Check current version in repo |
| 28 | + id: local |
| 29 | + run: | |
| 30 | + if [ -f jsondata/likelySubtags.json ]; then |
| 31 | + local_version=$(jq -r '.supplemental.version._cldrVersion // "none"' jsondata/likelySubtags.json 2>/dev/null || echo "none") |
| 32 | + else |
| 33 | + local_version="none" |
| 34 | + fi |
| 35 | + echo "version=$local_version" >> $GITHUB_OUTPUT |
| 36 | +
|
| 37 | + - name: Compare versions |
| 38 | + id: compare |
| 39 | + run: | |
| 40 | + remote_tag="${{ steps.cldr.outputs.tag }}" |
| 41 | + remote_version="${remote_tag#v}" # strip leading v in shell |
| 42 | + local_version="${{ steps.local.outputs.version }}" |
| 43 | +
|
| 44 | + echo "Remote: $remote_version" |
| 45 | + echo "Local: $local_version" |
| 46 | +
|
| 47 | + if [ "$remote_version" = "$local_version" ]; then |
| 48 | + echo "up_to_date=true" >> $GITHUB_OUTPUT |
| 49 | + else |
| 50 | + echo "up_to_date=false" >> $GITHUB_OUTPUT |
| 51 | + echo "remote_version=$remote_version" >> $GITHUB_OUTPUT |
| 52 | + fi |
| 53 | +
|
| 54 | + - name: Download likelySubtags.json |
| 55 | + if: steps.compare.outputs.up_to_date == 'false' |
| 56 | + run: | |
| 57 | + url="https://raw.githubusercontent.com/unicode-org/cldr-json/refs/tags/${{ steps.cldr.outputs.tag }}/cldr-core/supplemental/likelySubtags.json" |
| 58 | + curl -fsSL "$url" -o jsondata/likelySubtags.json |
| 59 | + # Validate downloaded file is valid JSON |
| 60 | + if ! jq empty jsondata/likelySubtags.json 2>/dev/null; then |
| 61 | + echo "Downloaded likelySubtags.json is not valid JSON" |
| 62 | + exit 1 |
| 63 | + fi |
| 64 | +
|
| 65 | + - name: Commit changes |
| 66 | + if: steps.compare.outputs.up_to_date == 'false' |
| 67 | + uses: peter-evans/create-pull-request@v6 |
| 68 | + with: |
| 69 | + commit-message: "Update CLDR likelySubtags to ${{ steps.cldr.outputs.tag }}" |
| 70 | + title: "Update CLDR likelySubtags to ${{ steps.cldr.outputs.tag }}" |
| 71 | + body: | |
| 72 | + This PR updates the CLDR likelySubtags data from version ${{ steps.local.outputs.version }} to ${{ steps.compare.outputs.remote_version }}. |
| 73 | +
|
| 74 | + Release notes: https://github.com/unicode-org/cldr-json/releases/tag/${{ steps.cldr.outputs.tag }} |
| 75 | + labels: dependencies, automated |
| 76 | + branch: update-cldr |
| 77 | + delete-branch: true |
0 commit comments