Skip to content

Commit 77d1159

Browse files
committed
feat: move to gmpctl; adding shmft
Signed-off-by: bwplotka <[email protected]>
1 parent 5e96846 commit 77d1159

30 files changed

+1286
-1316
lines changed

.bingo/Variables.mk

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,9 @@ $(MDOX): $(BINGO_DIR)/mdox.mod
4747
@echo "(re)installing $(GOBIN)/mdox-v0.9.0"
4848
@cd $(BINGO_DIR) && GOWORK=off GOOS=$(GOHOSTOS) GOARCH=$(GOHOSTARCH) GOARM=$(GOHOSTARM) $(GO) build -mod=mod -modfile=mdox.mod -o=$(GOBIN)/mdox-v0.9.0 "github.com/bwplotka/mdox"
4949

50+
SHFMT := $(GOBIN)/shfmt-v3.12.0
51+
$(SHFMT): $(BINGO_DIR)/shfmt.mod
52+
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
53+
@echo "(re)installing $(GOBIN)/shfmt-v3.12.0"
54+
@cd $(BINGO_DIR) && GOWORK=off GOOS=$(GOHOSTOS) GOARCH=$(GOHOSTARCH) GOARM=$(GOHOSTARM) $(GO) build -mod=mod -modfile=shfmt.mod -o=$(GOBIN)/shfmt-v3.12.0 "mvdan.cc/sh/v3/cmd/shfmt"
55+

.bingo/shfmt.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT
2+
3+
go 1.25.0
4+
5+
require mvdan.cc/sh/v3 v3.12.0 // cmd/shfmt

.bingo/shfmt.sum

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
github.com/google/renameio/v2 v2.0.0 h1:UifI23ZTGY8Tt29JbYFiuyIU3eX+RNFtUwefq9qAhxg=
2+
github.com/google/renameio/v2 v2.0.0/go.mod h1:BtmJXm5YlszgC+TD4HOEEUFgkJP3nLxehU6hfe7jRt4=
3+
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
4+
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
5+
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
6+
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
7+
golang.org/x/term v0.32.0 h1:DR4lr0TjUs3epypdhTOkMmuF5CDFJ/8pOnbzMZPQ7bg=
8+
golang.org/x/term v0.32.0/go.mod h1:uZG1FhGx848Sqfsq4/DlJr3xGGsYMu/L5GW4abiaEPQ=
9+
mvdan.cc/editorconfig v0.3.0 h1:D1D2wLYEYGpawWT5SpM5pRivgEgXjtEXwC9MWhEY0gQ=
10+
mvdan.cc/editorconfig v0.3.0/go.mod h1:NcJHuDtNOTEJ6251indKiWuzK6+VcrMuLzGMLKBFupQ=
11+
mvdan.cc/sh/v3 v3.12.0 h1:ejKUR7ONP5bb+UGHGEG/k9V5+pRVIyD+LsZz7o8KHrI=
12+
mvdan.cc/sh/v3 v3.12.0/go.mod h1:Se6Cj17eYSn+sNooLZiEUnNNmNxg0imoYlTu4CyaGyg=

.bingo/variables.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ HELM="${GOBIN}/helm-v3.14.0"
1616

1717
MDOX="${GOBIN}/mdox-v0.9.0"
1818

19+
SHFMT="${GOBIN}/shfmt-v3.12.0"
20+

.github/workflows/release-bot.yml

Lines changed: 0 additions & 192 deletions
This file was deleted.

hack/gmpctl.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2025 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -o errexit
17+
set -o pipefail
18+
set -o nounset
19+
20+
if [[ -n "${DEBUG_MODE:-}" ]]; then
21+
set -o xtrace
22+
fi
23+
24+
SCRIPT_DIR="$(
25+
cd -- "$(dirname "$0")" >/dev/null 2>&1
26+
pwd -P
27+
)"
28+
29+
pushd "${SCRIPT_DIR}/gmpctl" >/dev/null
30+
# NOTE gmpctl expects the whole gmpctl directory to be present.
31+
# We could consider embedding bash scripts, config into binary, but it's good
32+
# for now.
33+
go run ./ "$@"
34+
popd >/dev/null

hack/gmpctl/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
data

hack/gmpctl/.gmpctl.default.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
dir: "./data"

hack/gmpctl/README.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# gmpctl
2+
3+
`gmpctl` is an interactive CLI for common operations on GMP projects.
4+
5+
It's a starting point for smaller or bigger automation on OSS side (e.g. releasing, syncing or even debugging).
6+
7+
> NOTE: This script is far from perfect, but it's better than doing things manually. Feel free to contribute,
8+
> fix bugs and add more automation for common tasks!
9+
10+
## Setup
11+
12+
1. To start using `gmpctl` you need to have a clone of `prometheus-engine` on your machine (you probably have already one!
13+
to fetch the latest `main` for the best experience (latest scripts).
14+
15+
2. The next this is to obtain NVD API key to avoid rate-limits when querying CVE DB. See https://nvd.nist.gov/developers/request-an-api-key and save this key to `hack/vulnupdatelist/api.text`
16+
17+
3. You can configure different work directory for gmpctl via `-c` flag. By default, `gmpctl` does the work in `hack/gmpctl/.data`)
18+
19+
Enjoy!
20+
21+
## Usage
22+
23+
Generally `gmpctl` does not need flags for general usage. It interactively asks you for
24+
key information and confirmations e.g.
25+
26+
```bash
27+
./hack/gmpctl.sh release
28+
┃ What do you want to release?
29+
> release/0.17
30+
┃ release/0.15
31+
┃ release/0.14
32+
┃ release/0.12
33+
┃ release-2.45.3-gmp
34+
┃ release-2.53.5-gmp
35+
↑ up • ↓ down • / filter • enter submit
36+
```
37+
38+
`gmpctl` maintains 1 git clone for each project and uses `git worktree` for each command and branch.
39+
40+
`gmpctl` commands are aimed to be **idempotent**, meaning you should be able to run it multiple times with the
41+
same parameters, and it will continue the previous work or at least yield same results. This is crucial when iterating
42+
on breaking go mod updates for vulnerabilities or fork sync conflicts.
43+
44+
```text mdox-exec="bash hack/gmpctl.sh --help"
45+
Usage: gmpctl [COMMAND] [FLAGS]
46+
-c string
47+
Path to the configuration file. See config.go#Config for the structure. (default ".gmpctl.default.yaml")
48+
-v Enabled verbose, debug output (e.g. logging os.Exec commands)
49+
50+
--- Commands ---
51+
[release] Usage of release:
52+
-b string
53+
Release branch to work on; Project is auto-detected from this
54+
-patch
55+
If true, and --tag is empty, forces a new patch version as a new TAG.
56+
-t string
57+
Tag to release. If empty, next TAG version will be auto-detected (double check this!)
58+
59+
[vulnfix] Usage of vulnfix:
60+
-b string
61+
Release branch to work on; Project is auto-detected from this
62+
-pr-branch string
63+
(default: $USER/BRANCH-vulnfix) Upstream branch to push to (user-confirmed first).
64+
-sync-dockerfiles-from
65+
Optional branch name to sync Dockerfiles from. Useful when things changed.
66+
```
67+
68+
## `gmpctl` development
69+
70+
Some rules to follow:
71+
72+
* Downstream functions should literally use `panicf` for error handling. This improves readability and enormously help
73+
with debugging errors. The obvious exception is when code needs to handle this error. Then swap panic with a proper `err error` pattern.
74+
* Offer choice, be interactive! See `dialog.go` and https://github.com/charmbracelet/huh on what's possible.
75+
76+
## Bash development
77+
78+
While the `gmpctl` is written in Go, you might notice some functionalities are in Bash.
79+
80+
Bash is funky, but sometimes more readable than Go/easier to iterate.
81+
Eventually, we could rewrite more critical pieces to Go, but you're welcome to add some quick
82+
pieces in bash to automate some stuff.
83+
84+
It's trivial to call bash function from `gmpctl` e.g.:
85+
86+
```go
87+
if err := runLibFunction(dir, opts, "release-lib:vulnfix"); err != nil {
88+
return err
89+
}
90+
```
91+
92+
Some rules to follow:
93+
* CI checks bash formatting via https://github.com/mvdan/sh?tab=readme-ov-file#shfmt. You can install this on your IDE for formatting.
94+
* Write only libraries (functions). The starting point for scripts should be always Go gmpctl CLI.
95+
* Function names have `release-lib::` prefix to figure out where they come from.
96+
* Function check their required arguments/envvars; always.
97+
* Especially for functions that return strings via stdout:
98+
* Ensure all error messages are redirected to stderr, use log_err func for this.
99+
* Be careful with pushd/popd which log to stdout, you can redirect those to stderr too.
100+
101+
## TODO
102+
103+
* Ability to configure NVD API key in gmpctl config.
104+
* Port fork-sync script from the old PR.
105+
* Generate some on-demand query of vulnerabilities for all releases (aka dashboard.)
106+
* Fix NPM vulns (although it's rate).
107+
* Ability to schedule multiple scripts at once and managing that? (lot's of work vs multiple terminals)

0 commit comments

Comments
 (0)