-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsync-dataset-json-changes-to-js-utils.yml
More file actions
90 lines (82 loc) · 3.21 KB
/
sync-dataset-json-changes-to-js-utils.yml
File metadata and controls
90 lines (82 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
name: Sync <dataset>/**/<dataset>.json → adamlui/js-utils/<dataset>
on:
push:
branches: [main]
paths:
- "**/computer-languages.json"
- "**/data-languages.json"
- "**/latin-locales.json"
- "**/markup-languages.json"
- "**/non-latin-locales.json"
- "**/project-markers.json"
- "**/programming-languages.json"
- "**/prose-languages.json"
jobs:
build:
if: (github.repository == 'adamlui/python-utils') && !contains(github.event.head_commit.message, '[auto-sync')
runs-on: ubuntu-24.04
permissions:
contents: read
env:
TZ: PST8PDT
steps:
- name: Checkout adamlui/python-utils
uses: actions/checkout@v6.0.2
with:
token: ${{ secrets.REPO_SYNC_PAT }}
path: adamlui/python-utils
fetch-depth: 2
- name: Checkout adamlui/js-utils
uses: actions/checkout@v6.0.2
with:
token: ${{ secrets.REPO_SYNC_PAT }}
repository: adamlui/js-utils
path: adamlui/js-utils
- name: Determine changed dataset
env:
GH_TOKEN: ${{ github.token }}
run: |
SHA="${{ github.sha }}"
REPO="${{ github.repository }}"
changed_file=$(gh api repos/$REPO/commits/$SHA \
| grep -oP '"filename":\s*"\K[^"]+' \
| grep '\.json$' \
| head -n 1)
changed_file="${changed_file//%2F//}"
changed_file="${changed_file%%\?*}"
dataset=$(basename "$changed_file" .json)
echo "DATASET=$dataset" >> $GITHUB_ENV
echo "Extracted dataset: $dataset"
- name: Config committer
env:
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
GPG_PRIVATE_ID: ${{ secrets.GPG_PRIVATE_ID }}
run: |
gpg --batch --import <(echo "$GPG_PRIVATE_KEY")
git config --global commit.gpgsign true
git config --global user.name "kudo-sync-bot"
git config --global user.email "auto-sync@kudoai.com"
git config --global user.signingkey "$GPG_PRIVATE_ID"
- name: Escape commit message
env:
RAW_COMMIT_MSG: ${{ github.event.head_commit.message }}
run: |
dataset="${{ env.DATASET }}"
msg="${RAW_COMMIT_MSG:-Update $dataset.json}"
printf '%s ↞ [auto-sync from https://github.com/adamlui/python-utils/tree/main/%s]\n' \
"$msg" "$dataset" > commit_msg.txt
- name: Sync <dataset>.json → adamlui/js-utils/<dataset>
run: |
dataset="${{ env.DATASET }}"
echo "Syncing $dataset.json"
snake_dataset=$(echo "$dataset" | tr '-' '_')
src_file="${GITHUB_WORKSPACE}/adamlui/python-utils/$dataset/src/$snake_dataset/$dataset.json"
if [[ ! -f "$src_file" ]] ; then echo "No source file found for $dataset at $src_file" ; exit 1 ; fi
dest_dir="${GITHUB_WORKSPACE}/adamlui/js-utils/$dataset"
mkdir -p "$dest_dir"
cp -f "$src_file" "$dest_dir/$dataset.json"
cd "${GITHUB_WORKSPACE}/adamlui/js-utils"
git add "$dataset/$dataset.json"
git commit -n -F "${GITHUB_WORKSPACE}/commit_msg.txt" || echo "Nothing to commit"
git pull --rebase
git push