fix: strip leading v from VERSION, guard unset SHELL in install.sh#47
Conversation
…all.sh
VERSION now matches goreleaser's {{.Version}} so `graft --version` is
consistent between local builds and released binaries. install.sh no
longer aborts under `set -u` when SHELL is unset (e.g. minimal
containers). Also adds `make cover-html` and reorders check-tidy/cover
targets.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
PR Summary by QodoFix VERSION normalization and harden install.sh for unset SHELL
AI Description
Diagram
High-Level Assessment
Files changed (2)
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Code Review by Qodo
Context used✅ Compliance rules (platform):
15 rules 1. Broken source hint fallback
|
| VERSION ?= $(shell git describe --tags --exact-match 2>/dev/null || git rev-parse --short HEAD) | ||
| # Leading "v" is stripped to match goreleaser's {{.Version}}, so `graft --version` | ||
| # prints the same string for local builds and released binaries. | ||
| VERSION ?= $(shell (git describe --tags --exact-match 2>/dev/null || git rev-parse --short HEAD) | sed 's/^v//') |
There was a problem hiding this comment.
1. Extra sed in version 🐞 Bug ⚙ Maintainability
The Makefile now pipes VERSION through sed, adding an avoidable external dependency and extra subprocess on every make invocation. This is unnecessary because the same “strip leading v” behavior can be implemented using make-native string functions.
Agent Prompt
### Issue description
`VERSION` is computed by spawning a shell pipeline that includes `sed` solely to strip a leading `v`. This adds an avoidable external dependency and process overhead.
### Issue Context
GoReleaser already stamps `main.version` with `{{.Version}}` (no leading `v`), so local builds should strip the `v` too, but this can be done without `sed`.
### Fix Focus Areas
- Makefile[1-6]
### Suggested change
Replace the `sed` usage with a make-native transformation, e.g.:
```make
VERSION ?= $(patsubst v%,%,$(shell git describe --tags --exact-match 2>/dev/null || git rev-parse --short HEAD))
```
(or split into `VERSION_RAW` + `VERSION` if you want to keep it readable).
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| # environments (e.g. containers) where SHELL is unset. | ||
| # shellcheck disable=SC2088 # intentional: ~ is displayed as a hint to the user, not expanded | ||
| case "${SHELL}" in | ||
| case "${SHELL:-}" in |
There was a problem hiding this comment.
2. Broken source hint fallback 🐞 Bug ≡ Correctness
With ${SHELL:-} the installer no longer aborts when SHELL is unset, but it can now emit a broken
instruction: source your shell config file (the placeholder contains spaces). This makes the PATH
hint copy/paste fail specifically in the minimal environments this change is targeting.
Agent Prompt
### Issue description
After switching to `case "${SHELL:-}"`, the `SHELL`-unset path is no longer fatal, but the fallback `shell_config` value is a placeholder string with spaces. The script then prints `source ${shell_config}` without quoting/escaping, resulting in an invalid command users may copy/paste.
### Issue Context
This happens when `SHELL` is unset (common in minimal containers) or when it doesn’t match the known cases.
### Fix Focus Areas
- script/install.sh[76-120]
### Suggested change
Make the fallback hint unambiguous and copy/paste safe. Any of these would fix it:
1) Use a real default file (no spaces), e.g.:
```bash
*) shell_config='~/.profile' ;;
```
2) Or if you want to keep it as a placeholder, avoid printing a `source ...` line when `shell_config` is not a concrete path.
Optionally, also quote/escape the printed `source` command (bash supports `%q`) if you ever allow values that may contain spaces.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Summary
Makefile: strip a leadingvfromVERSIONsograft --versionmatches goreleaser's{{.Version}}for both local and released builds; addmake cover-html; reordercheck-tidy/covertargets.script/install.sh: guard${SHELL}with${SHELL:-}so the script doesn't abort underset -uwhenSHELLis unset (e.g. minimal containers).Test plan
make check, tests) passes