6a82b88947
agentws manages per-branch git worktrees for the unkin-agent user: it clones repos into the source root (~/src/prodenv/<repo>) so branches are visible in Ben's main checkout, and creates isolated worktrees under the worktree root (~/.cache/agentws/<repo>__<branch>). - New internal/agent/git.go: small, testable git helpers shelling out to the git binary (clone/fetch/worktree add/remove/list/prune, branch + config ops, porcelain parsing, path sanitizing). No go-git dependency. - New cmd/agentws: new / list / rm / clean / token / credential subcommands. Auth uses an ephemeral git credential helper (agentws credential get) so the ~1h Gitea token is never persisted in a remote URL or config; per-worktree config keeps the shared checkout's identity untouched. - Wire agentws into Makefile, scripts/build-rpm.sh, packaging/nfpm.yaml (binary + bash/zsh/fish completions), .woodpecker/release.yaml (cross-compile + assets) and .gitignore. - Tests: table tests for parsing/sanitizing/dir-naming, a real temp-git repo for the worktree lifecycle, and hermetic cmd tests (bad input + credential-helper host guard) that never touch the network. - Document agentws in README.md and AGENTS.md.
50 lines
1.7 KiB
Bash
Executable File
50 lines
1.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# Package the (already built) agentpr, watchpr and agentws 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="agent-tools"
|
|
BINARIES=(agentpr watchpr agentws)
|
|
DIST="dist"
|
|
|
|
for b in "${BINARIES[@]}"; do
|
|
if [ ! -f "${DIST}/${b}" ]; then
|
|
echo "ERROR: ${DIST}/${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.
|
|
COMP_DIR="${DIST}/completions"
|
|
mkdir -p "${COMP_DIR}"
|
|
for b in "${BINARIES[@]}"; do
|
|
"./${DIST}/${b}" completion bash >"${COMP_DIR}/${b}.bash"
|
|
"./${DIST}/${b}" completion zsh >"${COMP_DIR}/_${b}"
|
|
"./${DIST}/${b}" completion fish >"${COMP_DIR}/${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="CLI tools for Gitea automation as the unkin-agent user: agentpr (create PRs/comments), watchpr (poll PRs and alert on meaningful change) and agentws (manage per-branch git worktrees)"
|
|
export PACKAGE_MAINTAINER="Ben Vincent <ben@unkin.net>"
|
|
export PACKAGE_HOMEPAGE="https://git.unkin.net/unkin/agent-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
|