[mike@mwxm4]
This commit is contained in:
@@ -11,8 +11,7 @@
|
||||
- 🧹 **Auto-Import**: Runs `goimports` on save (optional via `-i`) to keep your imports clean — without touching the rest of your formatting.
|
||||
- 🖥️ **Interactive Menu**: Uses a select menu (`gbld.menu.json`) if run without arguments, letting you define and run custom build tasks.
|
||||
- 🚀 **Cross-Compilation**: Easily builds binaries for multiple target operating systems (macOS, Linux, Windows) and architectures (amd64, arm64) using a single command.
|
||||
- ☁️ **Remote Uploads**: Integrated command to upload build artifacts to a deployment server (`gozilla`).
|
||||
- 🔐 **Verified Self-Update**: Downloads updates over HTTPS and refuses to install anything that does not match its published SHA-256 checksum.
|
||||
- 🔐 **Verified Self-Update**: Installs new versions from the Gitea releases over HTTPS and refuses anything that does not match its published SHA-256 checksum.
|
||||
|
||||
---
|
||||
|
||||
@@ -53,15 +52,16 @@ gbld [flags] [target_name]
|
||||
| `-o` | `<args>` | Space-separated arguments to pass to the compiled binary on execution. |
|
||||
| `-c` | `<command>` | Command to execute immediately after a successful build (before execution). |
|
||||
| `-a` | None | Builds binaries for all supported platforms (Windows, macOS, Linux for AMD64/ARM64). |
|
||||
| `-u` | None | Uploads built binaries via SSH/SCP to the `gozilla` server. |
|
||||
| `-v` | None | Displays the current version of `gbld`. |
|
||||
| `-h` | None | Displays help and usage information. |
|
||||
| `--check-update` | None | Looks for a newer release and reports what it finds — installs nothing. |
|
||||
| `--update` | None | Downloads the newest release and replaces the running binary with it. |
|
||||
|
||||
### Environment
|
||||
|
||||
| Variable | Description |
|
||||
| :--- | :--- |
|
||||
| `GBLD_NO_UPDATE` | Set to any value to skip the update check at startup (useful offline or in CI). |
|
||||
| `GBLD_NO_UPDATE` | Set to any value to silence the background update check (useful offline or in CI). `--update` and `--check-update` still work. |
|
||||
|
||||
---
|
||||
|
||||
@@ -85,7 +85,7 @@ To make running common tasks easier, you can place a `gbld.menu.json` file in yo
|
||||
When compiling, `gbld` parses `build.go` to find a pattern matching `var build = "<number>"`. It increments this number by 1 and updates the file automatically, leaving the rest of the line (including trailing comments) untouched. This is useful for stamping build numbers/versions inside your binary. If there is no `build.go`, this step is silently skipped.
|
||||
|
||||
### Target Version
|
||||
`-a` and `-u` name their artifacts after the first `var version = "x.y.z"` found in the `*.go` files of the project. Ordinary builds do not need this variable.
|
||||
`-a` names its artifacts after the first `var version = "x.y.z"` found in the `*.go` files of the project. Ordinary builds do not need this variable.
|
||||
|
||||
### Automatic Backups
|
||||
Before `gbld` runs `goimports` on a file or modifies `build.go`, it creates a timestamped backup in a `./tmp/` directory inside the project workspace (the directory is created on demand):
|
||||
@@ -116,22 +116,49 @@ With `-1`, `gbld` is usable from scripts and CI:
|
||||
|
||||
---
|
||||
|
||||
## Cross-Compilation and Upload
|
||||
## Cross-Compilation
|
||||
|
||||
```bash
|
||||
gbld -a # build bin/<name>_<version>_<os>_<arch> for all 6 targets
|
||||
gbld -u # upload them to gozilla
|
||||
```
|
||||
|
||||
`-a` writes Windows artifacts with an `.exe` suffix and additionally produces:
|
||||
|
||||
- `bin/checksums.txt` — SHA-256 of every artifact, in the format used by `shasum -a 256 -c`
|
||||
- `bin/version.txt` — the published version
|
||||
- `bin/version.txt` — the version that was built
|
||||
|
||||
If any target fails to build, `version.txt` is **not** written and `gbld` exits with `1`, so a half-published version can never be announced. `-u` refuses build names containing anything but `A-Za-z0-9._-` and uploads the artifacts together with `checksums.txt` and `version.txt`.
|
||||
If any target fails to build, `version.txt` is **not** written and `gbld` exits with `1`, so a half-published version can never be announced.
|
||||
|
||||
> [!NOTE]
|
||||
> `-a` is the path for the programs `gbld` builds. `gbld` itself is released with `build.sh` (see below), which uses a different naming — both write `bin/checksums.txt`, so whichever ran last is the one that file describes.
|
||||
|
||||
---
|
||||
|
||||
## Releasing gbld itself
|
||||
|
||||
```bash
|
||||
./build.sh # steps the patch version, builds every platform
|
||||
VERSION=1.22.0 ./build.sh # a minor or major step is named outright
|
||||
PLATFORMS="linux/amd64" ./build.sh
|
||||
```
|
||||
|
||||
`build.sh` writes into `bin/` exactly what a release needs:
|
||||
|
||||
- `gbld-<goos>-<goarch>` — the binaries, `.exe` for Windows, built with `-trimpath -s -w` and the version injected via `-ldflags`
|
||||
- `checksums.txt` — their SHA-256, in the format of `shasum -a 256`
|
||||
|
||||
`version.txt` holds the version just built and is stepped by `0.0.1` on every run. Upload **all** of these files to a Gitea release whose tag is the bare version number (`1.21.1`, a leading `v` is allowed) — that is the layout `--update` expects.
|
||||
|
||||
> [!IMPORTANT]
|
||||
> `gbld -a` names its artifacts from `var version` in the sources, `build.sh` from `version.txt`, and nothing writes to a `.go` file. For gbld's own releases `build.sh` is the way — `var version` only shows up in a bare `go build`.
|
||||
|
||||
### Self-Update
|
||||
On startup `gbld` fetches `version.txt` from the update server (3 s timeout — an unreachable server never blocks a build). If a newer version is published, it asks before downloading, then verifies the download against the SHA-256 from `checksums.txt` before replacing itself. **If no matching checksum is published, the update is refused.** Publish new versions with `gbld -a` followed by `gbld -u`.
|
||||
|
||||
`selfupdate.go` holds the whole mechanism and is meant to be copied into other programs: adjust the block at its head, hang the two options into the flags, done. It needs nothing but the standard library.
|
||||
|
||||
Once a day, in the background, `gbld` asks the Gitea for the newest release and notes the answer in the cache directory. The next run reads that note and prints one line if something newer exists — the foreground never touches the network, so an unreachable server can never delay a build. The hint appears only on a terminal: in a pipe, a script or under cron, `gbld` stays quiet, as it does with `GBLD_NO_UPDATE` set.
|
||||
|
||||
`--update` fetches the asset for the running platform, weighs it against the SHA-256 from the release's `checksums.txt`, and only then replaces the running binary — after calling the fresh one once with `-v` to be sure it runs at all. **A release without a matching checksum is refused**, and a download that does not match is deleted, not installed. The certificate of the Gitea is verified like any other.
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user