Skip to content

Commit 19cf076

Browse files
authored
Fix Fail-Slow / exit-code masking (#59)
* propagate submodule and clone failures through finalize exit codes * fix the coderabbitai review comments * run the code-cleanup tool * fix the coderabbitai review comments * run the code-review tool * fix the first reviewer comment
1 parent db330b6 commit 19cf076

22 files changed

Lines changed: 374 additions & 297 deletions

.github/workflows/assets/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ PR is merged into a `local-{lang_code}` branch.
1313
**Condition:** PR must be merged (`github.event.pull_request.merged == true`) and the head
1414
branch must start with `translation-` (Weblate-created branches).
1515

16-
**Bot identity:** The “Create and push tag” step sets
17-
`user.email` to `Boost-Translation-CI-Bot@cppalliance.local`, matching the
18-
orchestration bot pattern in [`env.sh`](env.sh) for the mirror’s GitHub org.
16+
**Bot identity:** The “Create and push tag” step sources [`env.sh`](env.sh) and
17+
[`lib.sh`](lib.sh), then calls **`set_git_bot_config "$GITHUB_WORKSPACE"`** so
18+
`user.name` / `user.email` match the orchestration bot pattern:
19+
**`BOT_EMAIL="Boost-Translation-CI-Bot@$ORG.local"`** (with **`ORG`** derived from
20+
**`GITHUB_REPOSITORY`** in the mirror repo).
1921

2022
**How it works:**
2123

.github/workflows/assets/add_submodules.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ create_new_repo_and_push() {
3030
git -C "$sub_clone" remote remove origin 2>/dev/null || true
3131
git -C "$sub_clone" remote add origin "$repo_url" || return 2
3232
git -C "$sub_clone" push -u origin "$MASTER_BRANCH" || return 2
33-
git -C "$sub_clone" push origin "$MASTER_BRANCH" || return 2
3433
for lang_code in "${lang_codes_arr[@]}"; do
3534
local local_br="${LOCAL_BRANCH_PREFIX}${lang_code}"
3635
git -C "$sub_clone" checkout -B "$local_br" "$MASTER_BRANCH" || return 2

.github/workflows/assets/create-tag.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ jobs:
6161
echo "Tag $TAGNAME already exists, skipping."
6262
exit 0
6363
fi
64-
git config user.name "Boost-Translation-CI-Bot"
65-
git config user.email "Boost-Translation-CI-Bot@cppalliance.local"
64+
# shellcheck source=assets/env.sh
65+
source "$GITHUB_WORKSPACE/.github/workflows/assets/env.sh"
66+
# shellcheck source=assets/lib.sh
67+
source "$GITHUB_WORKSPACE/.github/workflows/assets/lib.sh"
68+
set_git_bot_config "$GITHUB_WORKSPACE"
6669
git tag "$TAGNAME"
6770
git push origin "$TAGNAME"

.github/workflows/assets/lib.sh

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ has_open_translation_pr() {
7272
# Clone repo at branch/tag into $3. Pass "keep" as $4 to preserve .git.
7373
clone_repo() {
7474
mkdir -p "$3"
75-
git clone --branch "$2" "$1" "$3"
75+
git clone --branch "$2" "$1" "$3" || return 2
7676
[[ "${4:-}" == "keep" ]] || rm -rf "$3/.git"
7777
}
7878

@@ -236,9 +236,10 @@ commit_and_push_translations_branch() {
236236
# Update one branch of the translations super-repo (checkout → update pointers → push).
237237
sync_translations_branch() {
238238
local dir="$1" branch="$2" libs_ref="$3" force="${4:-false}"
239+
local sub
239240
git -C "$dir" checkout -B "$branch" "origin/$branch"
240241
for sub in "${UPDATES[@]}"; do
241-
update_translations_submodule "$dir" "$MODULE_ORG" "$sub" "$branch"
242+
update_translations_submodule "$dir" "$MODULE_ORG" "$sub" "$branch" || return 2
242243
done
243244
commit_and_push_translations_branch "$dir" "$branch" "$libs_ref" "$force"
244245
}
@@ -350,16 +351,10 @@ record_submodule_fatal() {
350351
}
351352

352353
# Summary bucket globals; filled by sync_one_submodule before print_submodule_processing_summary.
353-
# add-submodules uses init_add_submodule_summary_buckets for REPO_EXISTS_SKIP.
354354
init_submodule_summary_buckets() {
355355
META_MISSING=()
356356
NO_DOC_PATHS=()
357357
ORG_REPO_MISSING=()
358-
}
359-
360-
init_add_submodule_summary_buckets() {
361-
META_MISSING=()
362-
NO_DOC_PATHS=()
363358
REPO_EXISTS_SKIP=()
364359
}
365360

.github/workflows/assets/submodule_ops.sh

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
# Per-submodule batch return convention (see docs/ARCHITECTURE.md §6):
1111
# 0 = success, 1 = non-fatal skip, 2 = fatal error.
1212
# process_submodule_list collapses 2 → submodule_fatal; combine_batch_and_finalize_rc
13-
# maps submodule_fatal to job exit 1 (finalize_rc wins when non-zero).
14-
# shellcheck disable=SC2034,SC2154
13+
# maps submodule_fatal to job exit 1 (finalize_rc wins when non-zero; optional weblate_rc
14+
# overrides both when non-zero).
15+
# shellcheck disable=SC2034,SC2154,SC2153
1516

1617
# Create temp workspace dirs. Pass "with_org_work" to also set ORG_WORK.
1718
init_translation_work_dirs() {
@@ -46,11 +47,11 @@ libs_submodule_names_from_gitmodules_file() {
4647
| sed 's|^libs/||'
4748
}
4849

49-
# Fetch boostorg/boost .gitmodules at ref; print raw content. Return 1 on failure.
50+
# Fetch ${BOOST_ORG}/boost .gitmodules at ref; print raw content. Return 1 on failure.
5051
fetch_boost_gitmodules_at_ref() {
5152
local ref="$1"
5253
gh api \
53-
"repos/boostorg/boost/contents/.gitmodules?ref=$ref" \
54+
"repos/${BOOST_ORG}/boost/contents/.gitmodules?ref=$ref" \
5455
-H "Accept: application/vnd.github.v3.raw" 2>/dev/null
5556
}
5657

@@ -64,7 +65,7 @@ resolve_add_submodules_names() {
6465
echo "Using ${#submodule_names[@]} submodules from input." >&2
6566
return 0
6667
fi
67-
echo "Fetching .gitmodules from boostorg/boost at ${libs_ref_for_fetch}..." >&2
68+
echo "Fetching .gitmodules from ${BOOST_ORG}/boost at ${libs_ref_for_fetch}..." >&2
6869
local gitmodules_content
6970
gitmodules_content=$(fetch_boost_gitmodules_at_ref "$libs_ref_for_fetch") || {
7071
phase_err "Failed to fetch .gitmodules"
@@ -115,12 +116,14 @@ process_submodule_list() {
115116
return 0
116117
}
117118

118-
# Combine submodule_fatal count with finalize_rc; return combined exit code.
119+
# Combine submodule_fatal count with finalize_rc and optional weblate_rc; return combined exit code.
119120
combine_batch_and_finalize_rc() {
120121
local finalize_rc="${1:-0}"
122+
local weblate_rc="${2:-0}"
121123
local exit_rc=0
122124
[[ "${submodule_fatal:-0}" -gt 0 ]] && exit_rc=1
123125
[[ "$finalize_rc" -ne 0 ]] && exit_rc=$finalize_rc
126+
[[ "$weblate_rc" -ne 0 ]] && exit_rc=$weblate_rc
124127
return "$exit_rc"
125128
}
126129

@@ -129,7 +132,7 @@ add_submodules_main() {
129132
local rc finalize_rc exit_rc
130133

131134
init_translation_state
132-
init_add_submodule_summary_buckets
135+
init_submodule_summary_buckets
133136

134137
begin_phase "$PHASE_SETUP" "Validate inputs and prepare workspace"
135138
validate_secrets

.github/workflows/assets/translation.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,6 @@ trigger_weblate() {
219219
add_or_update_json=$(jq -n --arg lc "$lang_code" --argjson s "$subs_json" \
220220
'{($lc): $s}')
221221

222-
[[ "$add_or_update_json" == "{}" ]] && {
223-
echo "Weblate skipped: no translations to update." >&2; return
224-
}
225-
226222
local payload
227223
payload=$(jq -n \
228224
--arg org "$MODULE_ORG" --arg ver "$libs_ref" \

.github/workflows/start-translation.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ jobs:
5959
source "$GITHUB_WORKSPACE/.github/workflows/assets/lib.sh"
6060
begin_phase "$PHASE_SETUP" "Validate language matrix"
6161
parse_and_validate_lang_codes
62-
langs_json=$(printf '%s\n' "${lang_codes_arr[@]}" | jq -R . | jq -s -c .)
62+
langs_json=$(submodule_names_to_json "${lang_codes_arr[@]}")
6363
echo "json=$langs_json" >> "$GITHUB_OUTPUT"
6464
echo "Lang codes: ${lang_codes_arr[*]}" >&2
6565
end_phase
@@ -282,10 +282,6 @@ jobs:
282282
echo "Skipping Weblate add-or-update: finalize_translations_local failed (rc=$rc)." >&2
283283
fi
284284
285-
exit_rc=0
286-
[[ $submodule_fatal -gt 0 ]] && exit_rc=1
287-
[[ $rc -ne 0 ]] && exit_rc=$rc
288-
[[ $weblate_rc -ne 0 ]] && exit_rc=$weblate_rc
289-
[[ $exit_rc -ne 0 ]] && exit $exit_rc
285+
combine_batch_and_finalize_rc "$rc" "$weblate_rc" || exit $?
290286
291287
echo "Done." >&2

.github/workflows/sync-translation.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ jobs:
7474
done
7575
validate_lang_codes "${lang_codes_arr[@]}"
7676
77-
langs_json=$(printf '%s\n' "${lang_codes_arr[@]}" | jq -R . | jq -s -c .)
77+
langs_json=$(submodule_names_to_json "${lang_codes_arr[@]}")
7878
echo "json=$langs_json" >> "$GITHUB_OUTPUT"
7979
end_phase
8080
@@ -111,8 +111,7 @@ jobs:
111111
# shellcheck source=assets/lib.sh
112112
source "$GITHUB_WORKSPACE/.github/workflows/assets/lib.sh"
113113
114-
git config user.name "$BOT_NAME"
115-
git config user.email "$BOT_EMAIL"
114+
set_git_bot_config "$GITHUB_WORKSPACE"
116115
117116
branch="${LOCAL_BRANCH_PREFIX}${SYNC_LANG}"
118117
begin_phase "$PHASE_SYNC_POINTERS" "Sync pointers on $branch"

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,28 @@ are a separate namespace — see [README](README.md#releases) and
2525

2626
### Changed
2727

28+
- Extracted shared dispatch helpers into
29+
[`scripts/trigger-dispatch-common.sh`](scripts/trigger-dispatch-common.sh)
30+
(`DEFAULT_REPO`, `DEFAULT_VERSION`, JSON build, `POST …/dispatches`); both
31+
`trigger-*.sh` wrappers source it.
32+
- Mirror **`create-tag.yml`** bot identity now uses **`set_git_bot_config`** from
33+
**`env.sh`** / **`lib.sh`** instead of a hardcoded org email.
2834
- Renamed and expanded operator quick reference to
2935
[GETTING-STARTED.md](docs/GETTING-STARTED.md): end-to-end walkthrough with
3036
per-step verification and create-tag coverage.
3137
- [endpoint-contract.md](docs/endpoint-contract.md) Outbound Weblate section:
3238
request schema is now the source of truth for payload fields.
3339

40+
### Fixed
41+
42+
- Clone and finalize steps now fail fast: **`clone_repo`**, **`sync_translations_branch`**,
43+
and **`finalize_translations_*`** propagate non-zero status instead of continuing with
44+
incomplete state.
45+
- **`combine_batch_and_finalize_rc`** collapses all three exit sources—batch
46+
**`submodule_fatal`**, **`finalize_rc`**, and optional **`weblate_rc`**—with documented
47+
last-wins priority; **`start-translation.yml`** **`start-local`** delegates to it instead
48+
of inline collapse logic.
49+
3450
## [1.0.0] - 2026-07-07
3551

3652
Initial semver baseline for the orchestration repo. Summarizes the operator and

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ From a clone of this repo:
182182
- **`scripts/trigger-add-submodules.sh`** — fires **`add-submodules`**.
183183
- **`scripts/trigger-start-translation.sh`** — fires **`start-translation`** (optional
184184
**`--version`**, **`--lang-codes`**, **`--extensions`**).
185+
- **`scripts/trigger-dispatch-common.sh`** — shared by both triggers: **`DEFAULT_REPO`**,
186+
**`DEFAULT_VERSION`**, JSON payload build, and **`POST …/dispatches`**.
185187

186188
These wrappers use only **`exit 0`** (success, including **`--help`**) and **`exit 1`**
187189
(all errors); they do not implement the asset-script 0/1/2 batch return convention
@@ -207,7 +209,7 @@ documented below.
207209
| Variable | Used by | Description |
208210
| ---------------- | ------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
209211
| `LANG_CODES` | `add-submodules`, `start-translation` | Default language codes when **`client_payload.lang_codes`** is omitted (comma- or bracket-list, e.g. `zh_Hans,ja`). Must be set here or passed in the dispatch payload. |
210-
| `SUBMODULES_ORG` | `add-submodules`, `start-translation` | Optional. GitHub org for **`boostorg`** mirror repos (e.g. `CppDigest`). If unset, the org is the same as this repository’s owner. **`sync-translation`** relies on **`.gitmodules`** URLs already pointing at the correct hosts. |
212+
| `SUBMODULES_ORG` | `add-submodules`, `start-translation` | Optional. GitHub org for per-library mirror repos under **`MODULE_ORG`** (e.g. `CppDigest`). If unset, **`MODULE_ORG`** defaults to this repository’s owner. Upstream Boost libraries are cloned from **`boostorg`**. **`sync-translation`** relies on **`.gitmodules`** URLs already pointing at the correct hosts. |
211213

212214
## Development
213215

0 commit comments

Comments
 (0)