~james/core

core/web/scripts/preview-worker-name.sh -rwxr-xr-x 461 bytes
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 14 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/sh
set -eu

branch="${1:-${TANGLED_PR_SOURCE_BRANCH:-}}"
if [ -z "$branch" ]; then
	echo "preview-worker-name: no branch given and TANGLED_PR_SOURCE_BRANCH is unset" >&2
	exit 1
fi

name=$(printf '%s' "$branch" |
	tr '[:upper:]' '[:lower:]' |
	tr '/_' '--' |
	tr -cd 'a-z0-9-' |
	cut -c1-40 |
	sed 's/^-*//; s/-*$//')

if [ -z "$name" ]; then
	echo "preview-worker-name: branch '$branch' sanitizes to an empty name" >&2
	exit 1
fi

printf '%s\n' "$name"