Skip to content

Commit e920b94

Browse files
committed
Create sync-dataset-json-changes-to-js-utils.yml
1 parent 3ec89cb commit e920b94

1 file changed

Lines changed: 82 additions & 0 deletions

File tree

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Sync <dataset>/**/<dataset>.json → adamlui/python-utils/<dataset>
2+
3+
on:
4+
push:
5+
branches: [main]
6+
paths:
7+
- "**/computer-languages.json"
8+
- "**/data-languages.json"
9+
- "**/latin-locales.json"
10+
- "**/markup-languages.json"
11+
- "**/non-latin-locales.json"
12+
- "**/project-markers.json"
13+
- "**/programming-languages.json"
14+
- "**/prose-languages.json"
15+
16+
jobs:
17+
build:
18+
if: (github.repository == 'adamlui/js-utils') && !contains(github.event.head_commit.message, '[auto-sync')
19+
runs-on: ubuntu-24.04
20+
permissions:
21+
contents: read
22+
env:
23+
TZ: PST8PDT
24+
25+
steps:
26+
- name: Checkout adamlui/python-utils
27+
uses: actions/checkout@v6.0.2
28+
with:
29+
token: ${{ secrets.REPO_SYNC_PAT }}
30+
path: adamlui/python-utils
31+
fetch-depth: 2
32+
33+
- name: Checkout adamlui/js-utils
34+
uses: actions/checkout@v6.0.2
35+
with:
36+
token: ${{ secrets.REPO_SYNC_PAT }}
37+
repository: adamlui/js-utils
38+
path: adamlui/js-utils
39+
40+
- name: Determine changed dataset
41+
env:
42+
GH_TOKEN: ${{ github.token }}
43+
run: |
44+
SHA="${{ github.sha }}"
45+
REPO="${{ github.repository }}"
46+
changed_file=$(gh api repos/$REPO/commits/$SHA | grep -oP '"filename":\s*"\K[^"]+' | grep '\.json$' | head -n 1)
47+
changed_file="${changed_file//%2F//}" # decode URL-encoded slashes (%2F → /)
48+
changed_file="${changed_file%%\?*}" # remove any query string (?ref=...)
49+
dataset=$(basename "$changed_file" .json)
50+
echo "DATASET=$dataset" >> $GITHUB_ENV
51+
echo "Extracted dataset: $dataset"
52+
53+
- name: Config committer
54+
env:
55+
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
56+
GPG_PRIVATE_ID: ${{ secrets.GPG_PRIVATE_ID }}
57+
run: |
58+
gpg --batch --import <(echo "$GPG_PRIVATE_KEY")
59+
git config --global commit.gpgsign true
60+
git config --global user.name "kudo-sync-bot"
61+
git config --global user.email "auto-sync@kudoai.com"
62+
git config --global user.signingkey "$GPG_PRIVATE_ID"
63+
64+
- name: Sync <dataset>.json → adamlui/js-utils/<dataset>
65+
env:
66+
RAW_COMMIT_MSG: ${{ github.event.head_commit.message }}
67+
run: |
68+
dataset="${{ env.DATASET }}"
69+
echo "Syncing $dataset.json"
70+
src_file=$(find "${GITHUB_WORKSPACE}/adamlui/js-utils" -name "$dataset.json" -type f | head -n 1)
71+
if [[ -z "$src_file" ]] ; then echo "No source file found for $dataset" ; exit 1 ; fi
72+
snake_dataset=$(echo "$dataset" | tr '-' '_')
73+
dest_dir="${GITHUB_WORKSPACE}/adamlui/js-utils/$dataset"
74+
mkdir -p "$dest_dir"
75+
cp -f "$src_file" "$dest_dir/$dataset.json"
76+
COMMIT_MSG="${RAW_COMMIT_MSG:-Update $dataset.json} ↞ [auto-sync from https://github.com/adamlui/python-utils/tree/main/$dataset]"
77+
ESCAPED_MSG=$(printf '%q' "$COMMIT_MSG")
78+
cd "${GITHUB_WORKSPACE}/adamlui/js-utils"
79+
git add "$dataset/$dataset.json"
80+
git commit -n -m "$COMMIT_MSG" || echo "Nothing to commit"
81+
git pull --rebase
82+
git push

0 commit comments

Comments
 (0)