Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
04400f4
add Homebrew tap formula
thatvideoshopguy Sep 10, 2026
3f7d9f0
add dev dispatcher which finds and documents its subcommands
thatvideoshopguy Sep 10, 2026
19c38e1
add shared test scaffolding for stubbing the tools the scripts call
thatvideoshopguy Sep 10, 2026
3b279b3
default dev-aws-login to the devsoc profile
thatvideoshopguy Sep 10, 2026
6a9383b
teach dev-clone about urls, non-python projects and vscode workspaces
thatvideoshopguy Sep 10, 2026
e655b52
add tofu env for reading and setting project env vars
thatvideoshopguy Sep 10, 2026
8a20e09
delete squash-merged branches too
thatvideoshopguy Sep 10, 2026
98a5ad6
unlock several servers, waiting for each one to boot
thatvideoshopguy Sep 10, 2026
1993b5a
diff and back up the aws config before rewriting it
thatvideoshopguy Sep 10, 2026
0fe1795
archive the repo on github after mirroring it
thatvideoshopguy Sep 10, 2026
98ca00c
confirm before uninstalling everything in the virtualenv
thatvideoshopguy Sep 10, 2026
7c410c5
run shellcheck, shfmt and the tests from make check
thatvideoshopguy Sep 10, 2026
605f85a
replace the readme with markdown covering install and each tool
thatvideoshopguy Sep 10, 2026
08c83e9
build the formula from the tap checkout so a branch can be tested loc…
thatvideoshopguy Sep 10, 2026
92dc0aa
document testing a branch through the tap clone
thatvideoshopguy Sep 10, 2026
61e669b
use posix test brackets instead of the bash double bracket
thatvideoshopguy Sep 14, 2026
5b4fbc5
match repo and branch names with case instead of regex
thatvideoshopguy Sep 14, 2026
8defa3f
time the boot wait with date instead of the SECONDS variable
thatvideoshopguy Sep 14, 2026
bf8a8c1
explain the unfollowable source path instead of disabling SC1090
thatvideoshopguy Sep 14, 2026
08b3750
prompt with read -p instead of a separate echo
thatvideoshopguy Sep 14, 2026
7f8f07c
stop clobbering TMPDIR when mirroring a repo
thatvideoshopguy Sep 14, 2026
88440b5
run tofu through tofu_exec in the passthrough case too
thatvideoshopguy Sep 14, 2026
d4c4a52
delete old aws config backups with xargs
thatvideoshopguy Sep 14, 2026
9ea765d
assert on substrings with an expect_contains helper
thatvideoshopguy Sep 14, 2026
9390293
inline the utility targets into the targets that use them
thatvideoshopguy Sep 14, 2026
63661c8
install shfmt in ci so the format check can run
thatvideoshopguy Sep 14, 2026
afda3e3
drop the awscli dependency from the formula
thatvideoshopguy Sep 14, 2026
6d1a9cd
move the tap notes above the formula class
thatvideoshopguy Sep 14, 2026
b53c98c
add AGENTS.md with the shell house style
thatvideoshopguy Sep 14, 2026
cde427d
move the contributor docs out of the readme
thatvideoshopguy Sep 14, 2026
a3b8db8
removed redundant code
thatvideoshopguy Sep 14, 2026
f3385b6
removed all the changes to the scripts and updated tests
thatvideoshopguy Sep 14, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: test

on:
push:
pull_request:

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install shfmt
run: |
go install mvdan.cc/sh/v3/cmd/shfmt@v3.14.1
echo "$HOME/go/bin" >> "$GITHUB_PATH"
- run: make check
101 changes: 101 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# AGENTS.md

The rules for writing code in this repo. The README covers installing and using the tools, and
`docs/development.md` covers the contributor workflow — tooling, testing a branch and releasing.

`bin/dev` finds its subcommands by globbing for sibling `bin/dev-*` scripts, so a new executable
with a `# help:` block is a new command. There is no registry to update.

## Shell

Everything is bash: `#!/usr/bin/env bash` on every script, `# shellcheck shell=bash` on the
sourced-only `tests/helpers.sh`. Nothing uses a bash 4 feature, so the scripts run on the bash 3.2
that ships with macOS as well as on a Homebrew bash. Keep it that way — no `mapfile`, no
`${var^^}`, no `declare -A`, no `<<<`, no process substitution.

Within bash, prefer the plain POSIX construct. The goal is that a reader who knows `sh` can follow
any script here without knowing bash's shorthand.

- **`[ ]`, not `[[ ]]`.** Quote every variable inside it: `[ "$#" -ne 1 ]`, `[ -x "$script" ]`,
`[ -n "${2:-}" ]`. Use the numeric operators (`-ne`, `-lt`, `-gt`) for numbers and `=` / `!=`
for strings.
- **`case` only for patterns.** A glob or an alternation list is what `case` is for:
```bash
case "$REPO_ARG" in
*/*) REPO_NAME="$REPO_ARG" ;;
*) REPO_NAME="$DEFAULT_ORG/$REPO_ARG" ;;
esac
```
For an exact match against one or two values, `if [ ... ] || [ ... ]` is shorter and reads
better. Don't reach for `case` just to avoid repeating `"${1:-}"`.
- **No regex.** `=~` is bash-only and needs a second language in your head. A membership test is a
space-wrapped `case` — the wrapping spaces are what make it an exact-word match, so `mainline`
doesn't match `main`:
```bash
case " $PROTECTED_BRANCHES $DEFAULT_BRANCH " in
*" $BRANCH "*) continue ;;
esac
```
- **No `$SECONDS`, `$RANDOM` or other bash magic variables.** A deadline is
`$(($(date +%s) + $TIMEOUT))`.
- **Words over punctuation.** `source` rather than `.`, because a lone dot is easy to miss. The
scripts are bash, so there is nothing to gain by spelling it the POSIX way.
- **Keep what earns its place.** Arrays, `local`, and `set -o pipefail` are bash-only and stay:
rewriting them in POSIX makes the scripts longer and less safe, which defeats the point.

Deliberately unfollowable `source` lines get a directive with a reason, not a rule number —
`# shellcheck source=/dev/null # path is set per-machine` rather than
`# shellcheck disable=SC1090`.

## Style

The house style is "least sugar, most explicit". Someone reading a script a year from now should
not have to look anything up.

- 100 character lines. Four-space indent, enforced by `shfmt --indent 4`.
- Every script opens with `set -euo pipefail` and `IFS=$'\n\t'`.
- Hard-coded values are named constants in `UPPER_CASE`, declared near the top of the file, above
the logic that uses them. This holds during refactors too: if the mechanism consuming a constant
changes, reshape the constant's value to suit — don't inline it and delete the name.
- Name your arguments. `REPO_ARG="$1"` once, then use the name, rather than `$1` scattered about.
- Prompt on the `read` that waits for it: `read -r -p "Press Enter to continue, or <ctrl>-c to
bail"`, not an `echo` followed by a bare `read -r` that silently fills `$REPLY`.
- Descriptive names, and never a magic environment variable as a scratch variable. `WORK_DIR`, not
`TMPDIR` — that one is read by `mktemp` and `git`, so assigning it moves everyone else's
temporary files too.
- Comments explain *why*. The `# help:` block explains *what*, and it is the only user-facing
documentation of a command. Its first line is the summary in `dev help`.
- Anything creating a temporary directory cleans it up: `trap 'rm -rf "$WORK_DIR"' EXIT`.
- Anything destructive shows what it is about to do and waits for Enter first.

## Adding a command

`bin/dev-something`, `chmod +x`, standard header. Then: a `# help:` block, the `--help` guard
which re-enters the dispatcher rather than printing anything itself, a `tests/test-something.sh`,
and a row in the README's command table.

```bash
if [ "${1:-}" = "-h" ] || [ "${1:-}" = "--help" ]; then
exec "$(dirname "$0")/dev" help "${0##*/dev-}"
fi
```

## Tests

Plain bash, no framework. One executable `tests/test-<command>.sh` per command, sourcing
`tests/helpers.sh` for its assertions and stub scaffolding.

- Assertions report and carry on rather than aborting, so one run tells you everything that is
broken. `finish` is what decides the exit status, so every test ends with a `finish` line.
- Stub every external command with `write_stub`, so tests need no credentials, touch no real repos
or servers, and write nothing outside `$WORKDIR`. A stub usually logs its arguments to a file
the test then asserts against.
- Test the behaviour worth protecting — which arguments the command builds, which paths it writes,
what it refuses to do, and that it cleans up after a failure — rather than restating the
implementation.
- Each test opens with a comment saying what is worth checking in that command and why.
- Commands that wait for Enter are driven with `printf '\n' | ...`.

## Docs

The README is deliberately limited to installation and usage. New documentation goes in `docs/`.
32 changes: 32 additions & 0 deletions Formula/devtools.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# The tap and the tools are the same repo, so the scripts are already on disk next to this
# formula: Homebrew builds from the tap's own checkout rather than fetching from GitHub again.
# That also makes testing a branch a matter of checking it out in the tap, with no push needed.

class Devtools < Formula
desc "Development tools for The Developer Society"
homepage "https://github.com/developersociety/tools"

# A pinned revision would need a second commit after every tag, so the version is what Homebrew
# keys its cache on: bump it to ship a release. While testing a branch, "brew fetch --force
# devtools" clears the cached clone without a bump.
TAP_CHECKOUT = Pathname.new(__dir__).parent.freeze

# No "branch:" here - cloning a local repo follows its HEAD, which is whichever branch the tap
# is currently on, which is exactly what testing a branch needs.
url "file://#{TAP_CHECKOUT}", using: :git
version "1.0.0"

depends_on "aws-vault"
depends_on "opentofu"

# The 1Password CLI is a cask, which formulae can't depend on, and pyenv/virtualenvwrapper are
# only needed by "dev clone". The scripts which need them say so when they're missing.

def install
bin.install Dir["bin/dev*"]
end

test do
assert_match "Usage: dev <command>", shell_output("#{bin}/dev help")
end
end
41 changes: 41 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
SHELL=/bin/bash
.DEFAULT_GOAL := help

SHELL_SOURCES = bin/dev* tests/*.sh


# -------------------------------
# Common targets for Dev projects
# -------------------------------
#
# Edit these targets so they work as expected on the current project.
#
# Remember there may be other tools which use these targets, so if a target is not suitable for
# the current project, then keep the target and simply make it do nothing.

help: ## This help dialog.
help:
@awk '/^[\-[:alnum:]]*: ##/ { split($$0, x, "##"); printf "%20s%s\n", x[1], x[2]; }' $(MAKEFILE_LIST)

install-local: ## Install the tools needed to work on this project.
install-local:
brew install shellcheck shfmt

check: ## Check for any obvious errors in the project's setup.
check: lint test

format: ## Run this project's code formatters.
format:
shfmt --indent 4 --write $(SHELL_SOURCES)

lint: ## Lint the project.
lint:
shellcheck $(SHELL_SOURCES)
shfmt --indent 4 --diff $(SHELL_SOURCES)

test: ## Run this project's tests.
test:
@for test in tests/test-*.sh; do \
echo "== $$test"; \
"$$test" || exit 1; \
done
60 changes: 60 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# The Developer Society — Development Tools

Tools for making development at The Developer Society quicker, easier and less error-prone.

## Installation

The tools are distributed through our own Homebrew tap. The repo is private, so Homebrew fetches it over SSH using the
GitHub key you already have set up:

```console
$ brew tap developersociety/tools git@github.com:developersociety/tools.git
$ brew trust developersociety/tools
$ brew install devtools
```

The explicit git URL is required: without it Homebrew guesses a public
`https://github.com/developersociety/homebrew-tools` and gets a 404. `brew trust` is required too, as Homebrew refuses
to load formulae from third-party taps until you say so.

If you previously added a checkout of this repo to your `$PATH`, remove that from your shell profile. It shadows the
Homebrew copies, and you'll keep running the old scripts without noticing.

To upgrade later:

```console
$ brew upgrade devtools
```

## Usage

Run `dev help` for the list of commands, and `dev help <command>` for the detail on one of them. Each command also takes
`--help` directly, and is available under its own name, so `dev clone devsoc` and `dev-clone devsoc` do the same thing.

```console
$ dev help
$ dev help tofu
$ dev tofu --help
```

Each command explains itself, so the list below is a map rather than a manual.

| Command | What it does |
|-------------------------|-----------------------------------------------------|
| `dev clone` | Clone a repo and set up virtualenvwrapper for it |
| `dev clean-branches` | Delete merged local branches and prune remotes |
| `dev tofu` | Run tofu with the devsoc-tofu profile |
| `dev aws-login` | Open the AWS console via aws-vault |
| `dev update-aws-config` | Rewrite `~/.aws/config` from the 1Password template |
| `dev unlock-server` | Unlock the encrypted root filesystem on a server |
| `dev archive-repo` | Mirror a repo to the archive server |
| `dev wipeenv` | Uninstall every package in the active virtualenv |

## Development

Please contribute! If you find yourself needing to do the same thing over and over, or you keep forgetting a process, or
you just feel you're typing too much to do boring stuff ... then create a script to automate/help/optimise it. And then
we can all benefit.

See [docs/development.md](docs/development.md) to get set up, and [AGENTS.md](AGENTS.md) for the house style and how the
tests are put together.
71 changes: 0 additions & 71 deletions README.rst

This file was deleted.

Loading
Loading