-
-
Notifications
You must be signed in to change notification settings - Fork 39
119 lines (99 loc) · 4.9 KB
/
sync-chatgpt-infinity-changes-to-repos.yml
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
name: Sync _locales/* between chatgpt-infinity/<chrome|firefox>/extension/, then chatgpt-infinity/* to adamlui/chatgpt-infinity/*, then chatgpt-infinity/greasemonkey/* to adamlui/userscripts/chatgpt/chatgpt-infinity/*
on:
push:
branches: [main]
paths: [chatgpt-infinity/**]
permissions:
contents: read
jobs:
build:
if: (github.repository == 'adamlui/ai-web-extensions') && (github.event.commits[0].committer.username != 'kudo-sync-bot')
runs-on: ubuntu-latest
env:
TZ: PST8PDT
steps:
- name: Checkout adamlui/ai-web-extensions
uses: actions/checkout@v4
with:
token: ${{ secrets.REPO_SYNC_PAT }}
repository: adamlui/ai-web-extensions
path: adamlui/ai-web-extensions
fetch-depth: 2
- name: Checkout adamlui/chatgpt-infinity
uses: actions/checkout@v4
with:
token: ${{ secrets.REPO_SYNC_PAT }}
repository: adamlui/chatgpt-infinity
path: adamlui/chatgpt-infinity
- name: Checkout adamlui/userscripts
uses: actions/checkout@v4
with:
token: ${{ secrets.REPO_SYNC_PAT }}
repository: adamlui/userscripts
path: adamlui/userscripts
- name: Sync _locales/ between chatgpt-infinity/<chrome|firefox>/extension/
run: |
cd ${{ github.workspace }}/adamlui/ai-web-extensions/chatgpt-infinity
ff_dir="firefox/extension/_locales"
chromium_dir="chrome/extension/_locales"
# Loop thru all lang dirs in firefox
for locale in $(find "$ff_dir" -mindepth 1 -maxdepth 1 -type d -exec basename {} \;) ; do
ff_file="$ff_dir/$locale/messages.json"
chromium_file="$chromium_dir/$locale/messages.json"
if [[ -f "$ff_file" && -f "$chromium_file" ]] ; then
# Get the latest commit timestamps for both files
ff_timestamp=$(git log -1 --format="%ct" -- "$ff_file" 2>/dev/null || echo 0)
chromium_timetsamp=$(git log -1 --format="%ct" -- "$chromium_file" 2>/dev/null || echo 0)
# Sync the most recently updated messages.json to the other dir
if [[ $ff_timestamp -ne $chromium_timestamp ]] ; then
if (( $ff_timestamp > $chromium_timestamp )) ; then
cp -f "$ff_file" "$chromium_file" ; sync_src="${ff_dir%%/*}"
else cp -f "$chromium_file" "$ff_file" ; sync_src="${chromium_dir%%/*}" ; fi
fi
fi
done
# Expose sync src for commit msg in self-push step
echo "SYNC_SRC=$sync_src" >> $GITHUB_ENV
- name: Sync chatgpt-infinity/ to adamlui/chatgpt-infinity/
run: |
rsync -avhr --delete --filter='P /.*' \
${{ github.workspace }}/adamlui/ai-web-extensions/chatgpt-infinity/ \
${{ github.workspace }}/adamlui/chatgpt-infinity/
- name: Sync chatgpt-infinity/greasemonkey/ to adamlui/userscripts/chatgpt/chatgpt-infinity/
run: |
rsync -avhr --delete \
${{ github.workspace }}/adamlui/ai-web-extensions/chatgpt-infinity/greasemonkey/ \
${{ github.workspace }}/adamlui/userscripts/chatgpt/chatgpt-infinity/
- name: Escape backticks in commit msg
env:
COMMIT_MSG: ${{ github.event.head_commit.message }}
run: |
echo "ESCAPED_MSG<<EOF" >> $GITHUB_ENV
echo "$COMMIT_MSG" | sed 's/`/\`/g' >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Config committer
run: |
gpg --batch --import <(echo "${{ secrets.GPG_PRIVATE_KEY }}")
git config --global commit.gpgsign true
git config --global user.name "kudo-sync-bot"
git config --global user.email "[email protected]"
git config --global user.signingkey "${{ secrets.GPG_PRIVATE_ID }}"
- name: Push changes to adamlui/ai-web-extensions
if: env.SYNC_SRC
run: |
cd ${{ github.workspace }}/adamlui/ai-web-extensions
git pull # again to sync w/ concurrent workflow updates
git add . && git commit -n -m "$ESCAPED_MSG ↞ [auto-sync from chatgpt-infinity/${{ env.SYNC_SRC }}]" || true
git push
- name: Push changes to adamlui/chatgpt-infinity
run: |
cd ${{ github.workspace }}/adamlui/chatgpt-infinity
git pull # again to sync w/ concurrent workflow updates
git add . && git commit -n -m "$ESCAPED_MSG ↞ [auto-sync from https://github.com/adamlui/ai-web-extensions/tree/main/chatgpt-infinity]" || true
git push
- name: Push changes to adamlui/userscripts
run: |
cd ${{ github.workspace }}/adamlui/userscripts
git pull # again to sync w/ concurrent workflow updates
git add . && git commit -n -m "$ESCAPED_MSG ↞ [auto-sync from https://github.com/adamlui/ai-web-extensions/tree/main/chatgpt-infinity]" || true
git push