e070357d3f
## Why The unit tests stopped compiling after the `--pm` → `-p`/`-i` match-modifier refactor was left uncommitted, there was no RPM/completions distribution story, and invoking the tool without a TTY against an empty pipe silently returned nothing. This makes the project releasable and safe to run from agents/CI. ## Changes - Make stdin handling robust: replace the fragile `!isTerminal` check with `stdinReader()`, which only reads node names when stdin is a real pipe/redirect carrying data. Terminals, `/dev/null`, and empty/closed pipes now fall through to a normal query, so running without a TTY behaves like an interactive run. - Repair and expand `main_test.go` to match the current `buildQuery`/`run` signatures; add coverage for the match modifiers, all output modes, config precedence, and the new `stdinReader` logic. `httptest` stubs PuppetDB (no live deps). - Add nfpm packaging (`packaging/nfpm.yaml`, `scripts/build-rpm.sh`): installs the binary to `/usr/bin/node-lookup` and bundles generated bash/zsh/fish completions under the standard system paths. - Rework the Makefile to build into `dist/` and add `completions`/`rpm` targets. - Split PR CI into `build`, `test`, and `pre-commit` workflows and extend `release` to build the RPM and `PUT` it to the artifactapi `rpm-internal` repo. Every step sets a `serviceAccount` and k8s resources. The project directory has also been relocated under `prodenv`. Reviewed-on: #13 Co-authored-by: Ben Vincent <ben@unkin.net> Co-committed-by: Ben Vincent <ben@unkin.net>
45 lines
1.5 KiB
Bash
Executable File
45 lines
1.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# Package the (already built) node-lookup binary into an RPM with nfpm,
|
|
# bundling generated bash/zsh/fish shell completions.
|
|
# Usage: scripts/build-rpm.sh [version] (version defaults to $CI_COMMIT_TAG)
|
|
#
|
|
set -euo pipefail
|
|
|
|
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
cd "${ROOT_DIR}"
|
|
|
|
VERSION="${1:-${CI_COMMIT_TAG:-0.0.0-dev}}"
|
|
VERSION="${VERSION#v}" # strip a leading v
|
|
BINARY="node-lookup"
|
|
DIST="dist"
|
|
|
|
if [ ! -f "${DIST}/${BINARY}" ]; then
|
|
echo "ERROR: ${DIST}/${BINARY} not found; run 'make build' first" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Generate shell completions from the freshly built binary so they always match
|
|
# the shipped flags/subcommands.
|
|
COMP_DIR="${DIST}/completions"
|
|
mkdir -p "${COMP_DIR}"
|
|
"./${DIST}/${BINARY}" completion bash >"${COMP_DIR}/${BINARY}.bash"
|
|
"./${DIST}/${BINARY}" completion zsh >"${COMP_DIR}/_${BINARY}"
|
|
"./${DIST}/${BINARY}" completion fish >"${COMP_DIR}/${BINARY}.fish"
|
|
|
|
export PACKAGE_NAME="${BINARY}"
|
|
export PACKAGE_VERSION="${VERSION}"
|
|
export PACKAGE_RELEASE="1"
|
|
export PACKAGE_ARCH="amd64"
|
|
export PACKAGE_PLATFORM="linux"
|
|
export PACKAGE_DESCRIPTION="CLI tool that queries the PuppetDB API to look up and filter node facts"
|
|
export PACKAGE_MAINTAINER="Ben Vincent <ben@unkin.net>"
|
|
export PACKAGE_HOMEPAGE="https://git.unkin.net/unkin/node-lookup"
|
|
export PACKAGE_LICENSE="MIT"
|
|
|
|
envsubst <packaging/nfpm.yaml >"${DIST}/nfpm.yaml"
|
|
nfpm pkg --config "${DIST}/nfpm.yaml" --target "${DIST}" --packager rpm
|
|
|
|
echo "Built:"
|
|
ls -1 "${DIST}"/*.rpm
|