6551ab9f13
Take the binary list from cmd/ in the Makefile, the RPM packaging and the release pipeline so a new tool ships without a pipeline edit.
63 lines
2.1 KiB
Bash
Executable File
63 lines
2.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# Package the (already built) puppet-catalog-tools binaries 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
|
|
PACKAGE="puppet-catalog-tools"
|
|
DIST="dist"
|
|
BIN_DIR="${DIST}/bin"
|
|
COMP_DIR="${DIST}/completions"
|
|
|
|
# Every tool is a main package under cmd/, so the shipped list is the contents
|
|
# of cmd/ — the same list the Makefile builds.
|
|
BINARIES=()
|
|
for dir in cmd/*/; do
|
|
BINARIES+=("$(basename "${dir}")")
|
|
done
|
|
if [ ${#BINARIES[@]} -eq 0 ]; then
|
|
echo "ERROR: no binaries found under cmd/" >&2
|
|
exit 1
|
|
fi
|
|
|
|
for b in "${BINARIES[@]}"; do
|
|
if [ ! -f "${BIN_DIR}/${b}" ]; then
|
|
echo "ERROR: ${BIN_DIR}/${b} not found; run 'make build' first" >&2
|
|
exit 1
|
|
fi
|
|
done
|
|
|
|
# Generate shell completions from the freshly built binaries so they always
|
|
# match the shipped flags/subcommands. They are written under the name and
|
|
# directory they install as, because nfpm globs these directories.
|
|
rm -rf "${COMP_DIR}"
|
|
mkdir -p "${COMP_DIR}/bash" "${COMP_DIR}/zsh" "${COMP_DIR}/fish"
|
|
for b in "${BINARIES[@]}"; do
|
|
"./${BIN_DIR}/${b}" completion bash >"${COMP_DIR}/bash/${b}"
|
|
"./${BIN_DIR}/${b}" completion zsh >"${COMP_DIR}/zsh/_${b}"
|
|
"./${BIN_DIR}/${b}" completion fish >"${COMP_DIR}/fish/${b}.fish"
|
|
done
|
|
|
|
export PACKAGE_NAME="${PACKAGE}"
|
|
export PACKAGE_VERSION="${VERSION}"
|
|
export PACKAGE_RELEASE="1"
|
|
export PACKAGE_ARCH="amd64"
|
|
export PACKAGE_PLATFORM="linux"
|
|
export PACKAGE_DESCRIPTION="Puppet catalog tooling: catalog-diff compiles a host's catalog in two environments and diffs them; catalog-impact lists the hosts a control repo change affects"
|
|
export PACKAGE_MAINTAINER="Ben Vincent <ben@unkin.net>"
|
|
export PACKAGE_HOMEPAGE="https://git.unkin.net/unkin/puppet-catalog-tools"
|
|
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
|