ci: build and publish brainless as the rolling latest release #18

Merged
sam merged 3 commits from feat/ci-build-release into main 2026-09-30 19:56:51 +00:00
Collaborator

Adds .forgejo/workflows/build.yml: on every push to main it builds ./cmd/brainless (CGO_ENABLED=0, -trimpath -ldflags '-s -w' -> static, ~37 MB) and publishes the binary as the repository's single rolling latest release.

Only one artifact is ever kept. Each successful build deletes the previous latest release — and with it the git tag — and then creates the release again at the pushed commit, attaching the binary. That is what keeps the Raspberry Pi running Forgejo from accumulating one binary per push. The delete happens after the build succeeded and before the new release exists, so a failed build never leaves a stale artifact that looks current. The download URL is stable:

https://git.norobo.chat/sam/brainless/releases/download/latest/brainless

Why plain git clone instead of actions/checkout: runs-on: linux is the linux:host label of the runner configured in sam/pi-deploy (data/runner/runner-config.yml), so steps run directly inside the forgejo-runner container. That image is Alpine plus git, bash and dumb-init — no Node.js — so JavaScript actions such as actions/checkout cannot run there. The clone authenticates with the automatic FORGEJO_TOKEN (masked in the log) and is --depth 1.

Dependency on a runner image change: the same container must provide the Go toolchain, curl and jq. That is the companion PR against sam/pi-deploy (feat/runner-go-toolchain), which needs an operator to rebuild the runner once:

cd /home/sam/git/sam/pi-deploy/forgejo/runner
docker compose build runner && docker compose up -d runner

Until that rebuild happens the job fails at the build step with go: not found. workflow_dispatch is enabled so the pipeline can be re-run without pushing a commit.

Adds `.forgejo/workflows/build.yml`: on every push to `main` it builds `./cmd/brainless` (CGO_ENABLED=0, `-trimpath -ldflags '-s -w'` -> static, ~37 MB) and publishes the binary as the repository's single rolling `latest` release. **Only one artifact is ever kept.** Each successful build deletes the previous `latest` release — and with it the git tag — and then creates the release again at the pushed commit, attaching the binary. That is what keeps the Raspberry Pi running Forgejo from accumulating one binary per push. The delete happens after the build succeeded and before the new release exists, so a failed build never leaves a stale artifact that looks current. The download URL is stable: ``` https://git.norobo.chat/sam/brainless/releases/download/latest/brainless ``` **Why plain `git clone` instead of `actions/checkout`:** `runs-on: linux` is the `linux:host` label of the runner configured in `sam/pi-deploy` (`data/runner/runner-config.yml`), so steps run directly inside the `forgejo-runner` container. That image is Alpine plus git, bash and dumb-init — no Node.js — so JavaScript actions such as `actions/checkout` cannot run there. The clone authenticates with the automatic `FORGEJO_TOKEN` (masked in the log) and is `--depth 1`. **Dependency on a runner image change:** the same container must provide the Go toolchain, curl and jq. That is the companion PR against `sam/pi-deploy` (`feat/runner-go-toolchain`), which needs an operator to rebuild the runner once: ``` cd /home/sam/git/sam/pi-deploy/forgejo/runner docker compose build runner && docker compose up -d runner ``` Until that rebuild happens the job fails at the build step with `go: not found`. `workflow_dispatch` is enabled so the pipeline can be re-run without pushing a commit.
Build ./cmd/brainless on every push to main and publish the binary as the
repository's single rolling 'latest' release: each successful build deletes
the previous latest release (and its git tag) before publishing its own, so
the Raspberry Pi running Forgejo and its runner stores one artifact, never a
history of them.

Runs on the host-backend runner (runs-on: linux -> the linux:host label),
which has no Node.js, so the repository is cloned with git instead of
actions/checkout.
DELETE /releases/tags/latest removes the release but leaves the git tag
behind, and a release created for a tag that already exists keeps that tag's
commit and ignores target_commitish. Without deleting the tag as well, the
latest release would keep pointing at the commit of the first build forever
while carrying the newest binary.

Also drop --fail-with-body from the release creation: its body was captured
into a variable, so a rejection printed only 'curl: (22) ... 404'. Parse the
id with jq instead and print the response when it has none.

Verified against the running instance with a throwaway tag: fresh run, re-run
(tag moved from 92a6dda to ec6cfd9, release target_commitish followed), one
asset of the expected size, byte-identical download.
Author
Collaborator

What was verified, and what was not

I could not run the pipeline itself: the runner container is still the old image (no go, no curl, no jq), so the job would stop at the build step with go: not found. What I could test, I tested.

Verified locally: CGO_ENABLED=0 go build -trimpath -ldflags '-s -w' -o brainless ./cmd/brainless on the go1.27.1 toolchain produces a 37,683,360-byte static executable that runs (-h prints its usage).

Verified against this live Forgejo instance: the publish step was extracted verbatim from build.yml and run four times against a throwaway tag (ci-verbatim-smoke), with a local stand-in for jq because this container has no jq installed. Results:

run condition outcome
1 no release, no tag both deletes 404 -> release created, asset uploaded, stable download URL printed
2-3 release and tag exist both deletes 204 -> recreated
4 a different commit git tag moved 92a6dda -> ec6cfd9, release target_commitish followed, exactly one release and one asset in the repository
- download of the uploaded asset HTTP 200, 37,683,360 bytes, byte-identical to the uploaded file

That last row is what caught a real bug. DELETE /repos/{owner}/{repo}/releases/tags/{tag} deletes the release but leaves the git tag, and a release created for a tag that already exists keeps that tag's commit and ignores target_commitish. Without deleting the tag as well, the very first build would have pinned latest to its commit permanently while serving newer binaries from it. Fixed in b9831e1: the step now deletes releases/tags/latest and then tags/latest.

The test released a temporary tag and asset; both were deleted afterwards and the repository is back to zero releases and zero tags. My scratch files under /tmp are removed.

Still unverified, and unavoidably so: the runner-side mechanics — whether runs-on: linux host-mode steps get the FORGEJO_* environment variables and the automatic FORGEJO_TOKEN, whether the default shell really is bash, and whether that token may create releases. All of it is documented in the Forgejo Actions reference, none of it can be exercised before the runner image is rebuilt. Once it is:

cd /home/sam/git/sam/pi-deploy/forgejo/runner
docker compose build runner && docker compose up -d runner

the job can be triggered from this branch without merging, via the Actions tab or:

curl -X POST -H "Authorization: token $TOKEN" \
  https://git.norobo.chat/api/v1/repos/sam/brainless/actions/workflows/build.yml/dispatches \
  -d '{"ref":"feat/ci-build-release"}'
### What was verified, and what was not I could not run the pipeline itself: the runner container is still the old image (no `go`, no `curl`, no `jq`), so the job would stop at the build step with `go: not found`. What I could test, I tested. **Verified locally:** `CGO_ENABLED=0 go build -trimpath -ldflags '-s -w' -o brainless ./cmd/brainless` on the `go1.27.1` toolchain produces a 37,683,360-byte static executable that runs (`-h` prints its usage). **Verified against this live Forgejo instance:** the publish step was extracted verbatim from `build.yml` and run four times against a throwaway tag (`ci-verbatim-smoke`), with a local stand-in for `jq` because this container has no `jq` installed. Results: | run | condition | outcome | | --- | --- | --- | | 1 | no release, no tag | both deletes `404` -> release created, asset uploaded, stable download URL printed | | 2-3 | release and tag exist | both deletes `204` -> recreated | | 4 | a *different* commit | git tag moved `92a6dda` -> `ec6cfd9`, release `target_commitish` followed, exactly one release and one asset in the repository | | - | download of the uploaded asset | `HTTP 200`, 37,683,360 bytes, byte-identical to the uploaded file | That last row is what caught a real bug. `DELETE /repos/{owner}/{repo}/releases/tags/{tag}` deletes the release but **leaves the git tag**, and a release created for a tag that already exists keeps that tag's commit and ignores `target_commitish`. Without deleting the tag as well, the very first build would have pinned `latest` to its commit permanently while serving newer binaries from it. Fixed in `b9831e1`: the step now deletes `releases/tags/latest` and then `tags/latest`. The test released a temporary tag and asset; both were deleted afterwards and the repository is back to zero releases and zero tags. My scratch files under `/tmp` are removed. **Still unverified, and unavoidably so:** the runner-side mechanics — whether `runs-on: linux` host-mode steps get the `FORGEJO_*` environment variables and the automatic `FORGEJO_TOKEN`, whether the default shell really is bash, and whether that token may create releases. All of it is documented in the [Forgejo Actions reference](https://forgejo.org/docs/v16.0/user/actions/reference/), none of it can be exercised before the runner image is rebuilt. Once it is: ``` cd /home/sam/git/sam/pi-deploy/forgejo/runner docker compose build runner && docker compose up -d runner ``` the job can be triggered from this branch without merging, via the Actions tab or: ``` curl -X POST -H "Authorization: token $TOKEN" \ https://git.norobo.chat/api/v1/repos/sam/brainless/actions/workflows/build.yml/dispatches \ -d '{"ref":"feat/ci-build-release"}' ```
Author
Collaborator

End-to-end evidence from a real run on the branch

I dispatched build.yml at feat/ci-build-release (run 120, workflow_dispatch). It fails on purpose, and it fails usefully — this is the raw log:

Runner bd2f6e7a-... (version:v13.2.0) received task 121 of job build, triggered by event: workflow_dispatch
workflow prepared
⭐ Run Main Check out b9831e1b6d8cae628a2b4f2172418a283fa6b646
Cloning into 'repo'...
checked out b9831e1b6d8cae628a2b4f2172418a283fa6b646 fix(ci): delete the latest git tag, not just the release
/data/.cache/act/1a6e29d8ade9a2be/act/workflow/1.sh: line 8: go: command not found
⚙️ [runner]: RUN exit status 127
🏁  Job failed

What that establishes, none of which could be confirmed by reading documentation alone:

  • The workflow parses and is accepted by Forgejo — the dispatch returned run 120 with jobs: ["build"], so the job and its runs-on: linux label were understood.
  • The clone step works. The automatic FORGEJO_TOKEN authenticated over the internal URL, FORGEJO_REF_NAME/FORGEJO_REPOSITORY/FORGEJO_SERVER_URL are all populated in host-mode steps, and --depth 1 --branch checked out the pushed commit (b9831e1). This was the biggest open question, since plain git clone replaced actions/checkout.
  • The default shell is bash, not a POSIX sh: the Forgejo runner spawns run steps as bash --noprofile --norc -e -o pipefail <script>, so set -euo pipefail is safe.
  • A failed build publishes nothing — the job stopped at the failing step, so no release was created or touched.
  • Steps get their own shell, one script file per step, all starting in the same job workspace. go: command not found is reported at line 8 of workflow/1.sh — line 8 of the build step's script is exactly its CGO_ENABLED=0 go build ... line, which confirms the step numbering and that my relative paths (repo/, then repo/brainless from the publish step) resolve against the job workspace rather than something left over from the previous step. The runner's host executor uses the job workspace whenever a step declares no working-directory (act/container/host_environment.go, wd = e.Path).

The remaining failure is purely the missing toolchain, and the run is expected to stay red until the runner image is rebuilt:

cd /home/sam/git/sam/pi-deploy/forgejo/runner
docker compose build runner && docker compose up -d runner

After that I will dispatch it again to confirm a green run, latest pointing at the right commit, and the download URL serving the freshly built binary.

### End-to-end evidence from a real run on the branch I dispatched `build.yml` at `feat/ci-build-release` ([run 120](https://git.norobo.chat/sam/brainless/actions/runs/120), `workflow_dispatch`). It fails on purpose, and it fails usefully — this is the raw log: ``` Runner bd2f6e7a-... (version:v13.2.0) received task 121 of job build, triggered by event: workflow_dispatch workflow prepared ⭐ Run Main Check out b9831e1b6d8cae628a2b4f2172418a283fa6b646 Cloning into 'repo'... checked out b9831e1b6d8cae628a2b4f2172418a283fa6b646 fix(ci): delete the latest git tag, not just the release /data/.cache/act/1a6e29d8ade9a2be/act/workflow/1.sh: line 8: go: command not found ⚙️ [runner]: RUN exit status 127 🏁 Job failed ``` What that establishes, none of which could be confirmed by reading documentation alone: - **The workflow parses and is accepted by Forgejo** — the dispatch returned run `120` with `jobs: ["build"]`, so the job and its `runs-on: linux` label were understood. - **The clone step works.** The automatic `FORGEJO_TOKEN` authenticated over the internal URL, `FORGEJO_REF_NAME`/`FORGEJO_REPOSITORY`/`FORGEJO_SERVER_URL` are all populated in host-mode steps, and `--depth 1 --branch` checked out the pushed commit (`b9831e1`). This was the biggest open question, since plain `git clone` replaced `actions/checkout`. - **The default shell is bash**, not a POSIX `sh`: the Forgejo runner spawns run steps as `bash --noprofile --norc -e -o pipefail <script>`, so `set -euo pipefail` is safe. - **A failed build publishes nothing** — the job stopped at the failing step, so no release was created or touched. - **Steps get their own shell, one script file per step, all starting in the same job workspace.** `go: command not found` is reported at line 8 of `workflow/1.sh` — line 8 of the *build* step's script is exactly its `CGO_ENABLED=0 go build ...` line, which confirms the step numbering and that my relative paths (`repo/`, then `repo/brainless` from the publish step) resolve against the job workspace rather than something left over from the previous step. The runner's host executor uses the job workspace whenever a step declares no `working-directory` (`act/container/host_environment.go`, `wd = e.Path`). The remaining failure is purely the missing toolchain, and the run is expected to stay red until the runner image is rebuilt: ``` cd /home/sam/git/sam/pi-deploy/forgejo/runner docker compose build runner && docker compose up -d runner ``` After that I will dispatch it again to confirm a green run, `latest` pointing at the right commit, and the download URL serving the freshly built binary.
sam merged commit 41c24a4928 into main 2026-09-30 19:56:51 +00:00
sam deleted branch feat/ci-build-release 2026-09-30 19:56:52 +00:00
Sign in to join this conversation.
No reviewers
No labels
code-review
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
sam/brainless!18
No description provided.