GitLab component: commit what the run wrote, and open the first merge request - #13
Merged
Merged
Conversation
… request Two defects, both since the template was written. The first run opened no merge request. The guard was `! git diff --quiet` evaluated BEFORE staging, and `git diff` looks only at tracked files - on a first run every translation is a new file, so it reported "nothing changed", the push was skipped, and the job went green having produced nothing. The second run worked, which is why this survived. `git add -A` committed the whole working directory. Anything the caller's job dirtied before us - an install rewriting a lockfile, a build, a codegen - shipped inside a merge request titled "Update translations from PTC". The GitHub half lost that behaviour; this one had kept it. The working tree is now recorded before the CLI runs and compared afterwards, and only what differs is staged - by content, because the CLI unpacks from a ZIP and unzip restores mtimes from the archive, so a fresh translation can carry a timestamp from before the run began. Nothing written means no commit and no push, rather than an empty branch. Paths are staged one at a time under GIT_LITERAL_PATHSPECS: `git add -- <path>` takes a pathspec, so a translation written to messages[1].json would otherwise stage the caller's messages1.json instead, and exit 0 doing it. The shell lives in lib/gitlab-scope.sh, which is where it is tested, and the template inlines it - a component ships YAML only and cannot vendor a sibling file. A test fails if the two drift apart. POSIX throughout: the component runs on alpine, which is busybox ash until before_script installs bash. The suite runs under bash, dash and ash; CI runs the first two.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two defects in
templates/translate/template.yml, both there since it was written. The GitHub half lost the second one in #11; this one had kept both.1. The first run opened no merge request
The guard was
! git diff --quiet, evaluated before staging.git difflooks only at tracked files, and on a first run every translation is a new file:So the block was skipped, nothing was pushed, and the job went green having produced nothing. The second run worked — which is why it survived this long. Same defect the CLI fixed upstream in ptc-cli #15.
2.
git add -Acommitted the whole working directoryAnything the caller's job dirtied before us shipped inside a merge request titled "Update translations from PTC".
What replaces them
The working tree is recorded before the CLI runs and compared afterwards; only what differs is staged. By content, not timestamps — the CLI unpacks from a ZIP, and unzip restores mtimes from the archive, so a translation written moments ago can be dated before the run began.
A run that wrote nothing commits nothing and pushes nothing, instead of pushing an empty branch. Paths are staged one at a time under
GIT_LITERAL_PATHSPECS, becausegit add -- <path>takes a pathspec: a translation written tomessages[1].jsonwould otherwise stage the caller'smessages1.jsonand exit 0.Where the shell lives
lib/gitlab-scope.sh— that is where it is tested. A component ships YAML only and cannot vendor a sibling file, so the template inlines it, and one of the tests fails if the two drift apart.POSIX throughout: the component runs on
alpine:3.22, i.e. busybox ash untilbefore_scriptinstalls bash.Verification
tests/gitlab-scope.test.sh— 8 cases: first run, a workspace dirtied beforehand, nothing written, a rewritten file next to an untouched one, ignored files, a path with a space, a glob metacharacter, and the template/library drift check.Green under bash, dash and busybox ash (the last in a real
alpine:3.22container). CI runs bash and dash.Mutation-checked: restoring the old
git diff --quietguard fails 5 of 8; restoringgit add -Afails 6 of 8.Unchanged and re-run: 19 unit cases, 5 act jobs, shellcheck clean, the component template still parses.