Skip to content

Commit 056b20b

Browse files
authored
feat: make installed binary name overridable (default flashduty) (#22)
* feat: make installed binary name overridable via env/make var install.sh: INSTALLED_NAME defaults to "flashduty" but honours a caller-supplied INSTALLED_NAME env var so we can install our bundled copy as "fduty" without shadowing a user's own flashduty installation. All uses of the installed name (mv target, chmod, PATH message, verify hint) already reference the variable — only the hardcoded default literal needed updating. Makefile: BINARY_NAME switches from := (immediate, non-overridable) to ?= so `make build BINARY_NAME=fduty` produces bin/fduty; default behaviour (make build) is unchanged. Public identity (cobra Use: string, help text, FLASHDUTY_* env vars, Go module, repo name) is untouched. * ci(release): mirror install.sh + install.ps1 to CDN on every release The release workflow uploaded binaries + releases/latest but not the install scripts; those were mirrored only by install-scripts.yml on install.sh/.ps1 changes. Re-upload them here so a release always ships a current installer on the CDN even when the scripts themselves didn't change. * ci: bake CDN default MIRROR_URL into mirrored install.sh The copy served from the CDN now defaults MIRROR_URL to the CDN (injected at upload time via the new MIRROR_PUBLIC_URL secret), so `curl <cdn>/install.sh | sh` pulls binaries from the CDN without the caller passing MIRROR_URL. The repo / GitHub copy stays generic (defaults to GitHub). A grep guard fails the job if the default line ever stops matching, so the injection can't silently no-op.
1 parent eaea632 commit 056b20b

4 files changed

Lines changed: 39 additions & 4 deletions

File tree

.github/workflows/install-scripts.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ jobs:
4545
BUCKET: ${{ secrets.MIRROR_S3_BUCKET }}
4646
ENDPOINT: ${{ secrets.MIRROR_S3_ENDPOINT }}
4747
PREFIX: ${{ secrets.MIRROR_S3_PATH_PREFIX }}
48+
MIRROR_PUBLIC_URL: ${{ secrets.MIRROR_PUBLIC_URL }}
4849
run: |
4950
set -eu
5051
if [ -z "${BUCKET:-}" ] || [ -z "${ENDPOINT:-}" ]; then
@@ -59,8 +60,18 @@ jobs:
5960
aws configure set default.response_checksum_validation when_required
6061
PREFIX="${PREFIX#/}"; PREFIX="${PREFIX%/}"
6162
63+
# Bake the CDN as the default MIRROR_URL into the copy we serve from the
64+
# CDN, so `curl <cdn>/install.sh | sh` pulls binaries from the CDN with
65+
# no MIRROR_URL arg. The repo / GitHub copy stays generic (GitHub default).
66+
src_sh=install.sh
67+
if [ -n "${MIRROR_PUBLIC_URL:-}" ]; then
68+
pub="${MIRROR_PUBLIC_URL%/}${PREFIX:+/${PREFIX}}"
69+
sed "s#MIRROR_URL=\"\${MIRROR_URL:-}\"#MIRROR_URL=\"\${MIRROR_URL:-${pub}}\"#" install.sh > /tmp/install.sh
70+
grep -q "MIRROR_URL:-${pub}" /tmp/install.sh || { echo "ERROR: MIRROR_URL default not injected (install.sh default line changed?)" >&2; exit 1; }
71+
src_sh=/tmp/install.sh
72+
fi
6273
sh_key="${PREFIX:+${PREFIX}/}install.sh"
63-
aws --endpoint-url="$ENDPOINT" s3 cp install.sh "s3://${BUCKET}/${sh_key}" \
74+
aws --endpoint-url="$ENDPOINT" s3 cp "$src_sh" "s3://${BUCKET}/${sh_key}" \
6475
--cache-control "public, max-age=300" \
6576
--content-type "text/x-shellscript; charset=utf-8"
6677

.github/workflows/release.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ jobs:
5353
BUCKET: ${{ secrets.MIRROR_S3_BUCKET }}
5454
ENDPOINT: ${{ secrets.MIRROR_S3_ENDPOINT }}
5555
PREFIX: ${{ secrets.MIRROR_S3_PATH_PREFIX }}
56+
MIRROR_PUBLIC_URL: ${{ secrets.MIRROR_PUBLIC_URL }}
5657
VERSION: ${{ github.ref_name }}
5758
run: |
5859
set -eu
@@ -97,3 +98,26 @@ jobs:
9798
aws --endpoint-url="$ENDPOINT" s3 cp /tmp/latest "s3://${BUCKET}/${latest_key}" \
9899
--cache-control "public, max-age=60" \
99100
--content-type "text/plain; charset=utf-8"
101+
102+
# Refresh the install scripts on every release so the mirror never
103+
# ships a stale/missing installer (install-scripts.yml only fires when
104+
# install.sh/.ps1 change on main; the scripts are version-agnostic, so
105+
# re-uploading the current copy here is the belt-and-suspenders guarantee).
106+
# Bake the CDN as the default MIRROR_URL into the served copy so
107+
# `curl <cdn>/install.sh | sh` pulls binaries from the CDN with no
108+
# MIRROR_URL arg. The repo / GitHub copy stays generic (GitHub default).
109+
src_sh=install.sh
110+
if [ -n "${MIRROR_PUBLIC_URL:-}" ]; then
111+
pub="${MIRROR_PUBLIC_URL%/}${PREFIX:+/${PREFIX}}"
112+
sed "s#MIRROR_URL=\"\${MIRROR_URL:-}\"#MIRROR_URL=\"\${MIRROR_URL:-${pub}}\"#" install.sh > /tmp/install.sh
113+
grep -q "MIRROR_URL:-${pub}" /tmp/install.sh || { echo "ERROR: MIRROR_URL default not injected (install.sh default line changed?)" >&2; exit 1; }
114+
src_sh=/tmp/install.sh
115+
fi
116+
sh_key="${PREFIX:+${PREFIX}/}install.sh"
117+
aws --endpoint-url="$ENDPOINT" s3 cp "$src_sh" "s3://${BUCKET}/${sh_key}" \
118+
--cache-control "public, max-age=300" \
119+
--content-type "text/x-shellscript; charset=utf-8"
120+
ps1_key="${PREFIX:+${PREFIX}/}install.ps1"
121+
aws --endpoint-url="$ENDPOINT" s3 cp install.ps1 "s3://${BUCKET}/${ps1_key}" \
122+
--cache-control "public, max-age=300" \
123+
--content-type "text/plain; charset=utf-8"

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build configuration
2-
BINARY_NAME := flashduty
2+
BINARY_NAME ?= flashduty
33
BUILD_DIR := bin
44
GOLANGCI_LINT_VERSION := v2.2.1
55
GOLANGCI_LINT := $(BUILD_DIR)/golangci-lint

install.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ set -e
1515

1616
REPO="flashcatcloud/flashduty-cli"
1717
BINARY="flashduty-cli"
18-
INSTALLED_NAME="flashduty"
18+
INSTALLED_NAME="${INSTALLED_NAME:-flashduty}"
1919
INSTALL_DIR="${FLASHDUTY_INSTALL_DIR:-/usr/local/bin}"
2020

2121
# When set, all release downloads are fetched from this prefix instead of github.com.
@@ -188,7 +188,7 @@ main() {
188188
info " export PATH=\"${INSTALL_DIR}:\$PATH\"" ;;
189189
esac
190190

191-
info "Run 'flashduty version' to verify"
191+
info "Run '${INSTALLED_NAME} version' to verify"
192192
}
193193

194194
main

0 commit comments

Comments
 (0)