Repository navigation
feat: write-env-state records a deploy in argocd-state - #79
Conversation
Sets tag and revision in <env>/<service>.yaml and pushes with the release-train App's token, retrying when another deploy lands first. The file has to exist already. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Argo CD's notifier only ever sets that status to success or failure, so a sync that never starts left the commit with no status at all. Set pending first and a stuck sync shows as a pending that never clears; a failed push sets it to error with the run as its link. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
lucas-koontz
left a comment
There was a problem hiding this comment.
I reviewed write-env-state, its script and tests, the new pending status, and the build-push-ecr change. The state edit, the input checks, and the retry loop hold up, including on the shallow checkout and after a force-push on the remote.
Three fixes are worth making, and none blocks: the gha cache flags never take effect from a run: step, a push the server refuses gets retried as if it were a race, and the pending status sticks when the state file already matches. The rest is optional or polish.
| if [ "$REMOTE_BUILDER" = "false" ]; then | ||
| # setup-buildx-action gave this runner a builder of its own; the | ||
| # GitHub Actions cache stands in for the agent's layer cache. | ||
| CACHE_ARGS="--cache-from type=gha --cache-to type=gha,mode=max" |
There was a problem hiding this comment.
issue: These flags do nothing. buildx reads the cache's token and URL from ACTIONS_RUNTIME_TOKEN and ACTIONS_RESULTS_URL, a run: step never gets them, and buildx then drops type=gha without a warning. A hosted build on this branch logged no cache import or export. The gain would be small, so I'd drop CACHE_ARGS and the cache wording on line 32. To keep it, add crazy-max/ghaction-github-runtime and a per-image scope=.
There was a problem hiding this comment.
Dropped in 260d84e: CACHE_ARGS and the cache wording are gone, and remote-builder: "false" now only skips the remote builder. The input is read from env:.
| if "rejected" not in push.stderr and "fetch first" not in push.stderr and "non-fast-forward" not in push.stderr: | ||
| raise StateError(f"push to {branch} failed: {push.stderr.strip()}") |
There was a problem hiding this comment.
issue: "rejected" also matches ! [remote rejected] HEAD -> main (push declined due to repository rule violations). A ruleset or hook refusal then gets pushed five times and reported as "main kept moving", and git's reason is lost. These markers match only a race, client side or server side. A test with a failing hooks/pre-receive in the bare fixture would pin it:
| if "rejected" not in push.stderr and "fetch first" not in push.stderr and "non-fast-forward" not in push.stderr: | |
| raise StateError(f"push to {branch} failed: {push.stderr.strip()}") | |
| if not any(m in push.stderr for m in ("(fetch first)", "(non-fast-forward)", "(incorrect old value provided)", "cannot lock ref")): | |
| raise StateError(f"push to {branch} failed: {push.stderr.strip()}") |
There was a problem hiding this comment.
Taken in 936ad10, with the pre-receive test: a refused push raises with git's own text after one attempt; only the four race markers are retried.
| def git(repo_dir: Path, *args: str, check: bool = True) -> subprocess.CompletedProcess: | ||
| return subprocess.run(["git", "-C", str(repo_dir), *args], capture_output=True, text=True, check=check) |
There was a problem hiding this comment.
optional: A failed fetch, reset, add, or commit raises CalledProcessError, and capture_output swallows git's message, so the log shows a traceback with only the exit status. Raising StateError gives the ::error:: line with the reason:
| def git(repo_dir: Path, *args: str, check: bool = True) -> subprocess.CompletedProcess: | |
| return subprocess.run(["git", "-C", str(repo_dir), *args], capture_output=True, text=True, check=check) | |
| def git(repo_dir: Path, *args: str, check: bool = True) -> subprocess.CompletedProcess: | |
| result = subprocess.run(["git", "-C", str(repo_dir), *args], capture_output=True, text=True) | |
| if check and result.returncode != 0: | |
| raise StateError(f"git {args[0]} failed: {result.stderr.strip()}") | |
| return result |
| path: argocd-state | ||
| persist-credentials: true | ||
|
|
||
| - name: Mark the commit as waiting for Argo CD |
There was a problem hiding this comment.
issue: When the state file already records this sha, the script returns without a commit, so Argo CD never syncs and nothing replaces this pending. A rerun, or any new label on an already-deployed PR when the caller reruns on labeled, does exactly that, and the commit's earlier success turns into a pending that never clears. Setting pending only after the script reports a commit avoids it.
There was a problem hiding this comment.
Moved in 8dadb04: the script writes pushed=true|false to GITHUB_OUTPUT and the pending step runs after it, only on true. The error step went with the reordering; a failed push has the red job on the commit.
| runs: | ||
| using: composite | ||
| steps: | ||
| - uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.0.1 |
There was a problem hiding this comment.
nit: Three small ones. The pin comment says v5.0.1, but fbc6f39 is v5.1.0. build-push-ecr line 63 puts ${{ inputs.remote-builder }} straight into the script, which zizmor flags; an env: entry avoids it. updated_text drops a trailing # comment on the tag: and revision: lines, where the state repository's README template puts them.
buildx takes the Actions cache token and URL from variables a run: step never has, so --cache-to type=gha was dropped without a word: the hosted build on this branch logged no cache import or export. remote-builder "false" now only skips the remote builder; "true", the default, is the same command as before. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
"rejected" also matched a push a ruleset or hook refused, so that was tried five times and reported as the branch moving. Only git's race messages are retried now; a refusal raises with git's own text after one attempt, and so does any other failed git command. A comment after the tag or revision value stays. record() says whether it pushed, and main writes pushed=true|false to --github-output for the action. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
A rerun whose file already matched set the pending before the script returned without a commit, and nothing ever cleared it. The pending step now follows the script and runs on its pushed output; the error step went with the reordering. Checkout pin comment corrected to v5.1.0. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The deploy half of the Argo CD move (KFS 208, argocd-state 1): a composite action that sets
tagandrevisioninargocd-state<env>/<service>.yamland pushes. Argo CD polls that repository and syncs the service, so the calling job needs no cluster credential.scripts/write_env_state.pyedits the two lines in place, so the keys set when the service was added keep their order and comments. Values are checked against the same shapes argocd-state's validator accepts. A missing file is refused, not created: adding a service is a reviewed change there.mindsdb-release-traininstallation token (minted by the caller withactions/create-github-app-token), which that repo's ruleset lets push tomain.Inputs are
sha, the commit Argo CD renders the chart from, andtag, the imagebuild-push-ecrpushed for it. On a pull_request run callers pass the PR head sha and its<build environment>-head-<sha>tag, not$GITHUB_SHA: that is the synthetic merge commit, which GitHub drops once the PR closes.When it pushed a commit, the action sets commit status
argocd/<env>to pending onshain the calling repository, linking to the Argo CD app. Argo CD's notifier (KFS 208) only ever sets that status to success or failure, so without this a sync that never started left the commit with no status at all; now it is a pending that never clears. A rerun that finds the file already up to date sets nothing, since nothing will sync. The calling job needsstatuses: write;status-tokendefaults togithub.token,argocd-urlto newdev's.build-push-ecrgainsremote-builder:"false"skips the in-cluster BuildKit agent, which only a runner inside newdev can reach, and builds on the buildersetup-buildx-actionmade on the runner. The default keeps every existing caller as it is.Tests in
tests/test_write_env_state.pyrun the script against a local bare repository: the edit, the no-op, the missing file, a stale clone, a push rejected mid-attempt, a push a pre-receive hook refuses, and giving up. actionlint and zizmor report nothing on the action.🤖 Generated with Claude Code