-
Notifications
You must be signed in to change notification settings - Fork 4
150 lines (129 loc) · 5.25 KB
/
Copy pathsync-translation.yml
File metadata and controls
150 lines (129 loc) · 5.25 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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# Sync submodule pointers on all "local-*" branches to the tip of each submodule's
# corresponding "local-*" branch.
#
# Jobs:
# discover — list remote local-* branches and emit matrix JSON.
# sync-local (matrix per lang) — advance submodule pointers on one local-* branch.
#
# Workflow lives on master (default). Trigger: repository_dispatch (event_type
# EVENT_SYNC_TRANSLATION / sync-translation) or schedule (every day).
#
# Manual trigger: POST /repos/{owner}/{repo}/dispatches
# Body: {"event_type": "sync-translation"}
#
# Required secret: SYNC_TOKEN — PAT with repo push to this repository.
# Submodule remotes in .gitmodules point at per-library org (set when running add-submodules / start-translation with SUBMODULES_ORG).
name: Sync translation
on:
repository_dispatch:
# Must match EVENT_SYNC_TRANSLATION in assets/env.sh
types: [sync-translation]
schedule:
- cron: "0 0 * * *"
permissions:
contents: read
jobs:
discover:
runs-on: ubuntu-latest
outputs:
json: ${{ steps.branches.outputs.json }}
steps:
- name: Checkout repository (master)
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
token: ${{ secrets.SYNC_TOKEN }}
persist-credentials: false
- name: Discover local-* branches
id: branches
env:
GITHUB_TOKEN: ${{ secrets.SYNC_TOKEN }}
run: |
set -euo pipefail
gh auth setup-git
# shellcheck source=assets/env.sh
source "$GITHUB_WORKSPACE/.github/workflows/assets/env.sh"
# shellcheck source=assets/lib.sh
source "$GITHUB_WORKSPACE/.github/workflows/assets/lib.sh"
begin_phase "$PHASE_DISCOVER" "Discover local-* branches"
trap '[[ -n "$CURRENT_PHASE" ]] && end_phase' EXIT ERR
mapfile -t local_branches < <(
git ls-remote --heads origin "refs/heads/${LOCAL_BRANCH_PREFIX}*" \
| awk '{print $2}' | sed 's|refs/heads/||'
)
if [[ ${#local_branches[@]} -eq 0 ]]; then
echo "No local-* branches found." >&2
echo 'json=[]' >> "$GITHUB_OUTPUT"
end_phase
exit 0
fi
echo "Found ${#local_branches[@]} local-* branch(es): ${local_branches[*]}" >&2
lang_codes_arr=()
for branch in "${local_branches[@]}"; do
lang_codes_arr+=("${branch#"${LOCAL_BRANCH_PREFIX}"}")
done
validate_lang_codes "${lang_codes_arr[@]}"
langs_json=$(submodule_names_to_json "${lang_codes_arr[@]}")
echo "json=$langs_json" >> "$GITHUB_OUTPUT"
end_phase
sync-local:
needs: discover
if: needs.discover.outputs.json != '[]'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
lang: ${{ fromJson(needs.discover.outputs.json) }}
concurrency:
group: local-branch-${{ matrix.lang }}
cancel-in-progress: false
steps:
- name: Checkout repository (master)
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
token: ${{ secrets.SYNC_TOKEN }}
fetch-depth: 0
persist-credentials: false
- name: Sync local-${{ matrix.lang }}
env:
GITHUB_TOKEN: ${{ secrets.SYNC_TOKEN }}
SYNC_LANG: ${{ matrix.lang }}
run: |
set -euo pipefail
gh auth setup-git
# shellcheck source=assets/env.sh
source "$GITHUB_WORKSPACE/.github/workflows/assets/env.sh"
# shellcheck source=assets/lib.sh
source "$GITHUB_WORKSPACE/.github/workflows/assets/lib.sh"
set_git_bot_config "$GITHUB_WORKSPACE"
branch="${LOCAL_BRANCH_PREFIX}${SYNC_LANG}"
begin_phase "$PHASE_SYNC_POINTERS" "Sync pointers on $branch"
trap '[[ -n "$CURRENT_PHASE" ]] && end_phase' EXIT ERR
git fetch origin "$branch"
git checkout -B "$branch" "origin/$branch"
git submodule update --init
updated=0
while IFS= read -r sub_path; do
[[ -z "$sub_path" ]] && continue
if [[ ! -d "$sub_path" ]]; then
echo " Warning: submodule path missing after init, skipping: $sub_path" >&2
continue
fi
git config "submodule.${sub_path}.branch" "$branch"
git -C "$sub_path" fetch origin \
"refs/heads/${branch}:refs/remotes/origin/${branch}"
git submodule update --remote "$sub_path"
git add "$sub_path"
echo " Updated $sub_path -> $(git -C "$sub_path" rev-parse --short HEAD)" >&2
updated=1
done < <(git config -f .gitmodules --get-regexp 'submodule\..*\.path' \
2>/dev/null | sed 's/^[^ ]* //')
if [[ $updated -eq 1 ]] && ! git diff --staged --quiet; then
# Commit + push through the shared helper so this path gets the same
# bounded retry and --force-if-includes safety as the finalize flow.
commit_and_push_translations_branch "$GITHUB_WORKSPACE" "$branch" "$branch" true
echo " Pushed to origin/$branch" >&2
else
echo " No pointer changes for $branch." >&2
fi
end_phase
echo "Done." >&2