From 4c274398388d3d84faa83ccef413f1363cb385cc Mon Sep 17 00:00:00 2001 From: x71c9 <108585118+x71c9@users.noreply.github.com> Date: Wed, 1 Jul 2026 11:14:27 +0200 Subject: [PATCH] chore: rename script without .sh --- scripts/fetch-rebase | 16 ++++ scripts/fetch-rebase.sh | 12 --- scripts/install | 86 +++++++++++++++++++ scripts/install-hooks.sh | 19 ---- scripts/pipe | 14 +++ ...-protection.sh => setup-branch-protection} | 4 +- shell.nix | 2 +- 7 files changed, 119 insertions(+), 34 deletions(-) create mode 100755 scripts/fetch-rebase delete mode 100755 scripts/fetch-rebase.sh create mode 100755 scripts/install delete mode 100755 scripts/install-hooks.sh create mode 100755 scripts/pipe rename scripts/{setup-branch-protection.sh => setup-branch-protection} (96%) diff --git a/scripts/fetch-rebase b/scripts/fetch-rebase new file mode 100755 index 0000000..ccb0bef --- /dev/null +++ b/scripts/fetch-rebase @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +set -euo pipefail + +if ! git diff --quiet || ! git diff --cached --quiet; then + echo "warning: working tree is dirty, skipping fetch-rebase" >&2 + exit 0 +fi + +echo "git fetch origin master" +git fetch origin master + +echo "git fetch origin master --tags" +git fetch origin master --tags + +echo "git rebase origin/master" +git rebase origin/master diff --git a/scripts/fetch-rebase.sh b/scripts/fetch-rebase.sh deleted file mode 100755 index b7f477c..0000000 --- a/scripts/fetch-rebase.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -if ! git diff --quiet 2>/dev/null || ! git diff --cached --quiet 2>/dev/null; then - echo "warning: dirty git tree — skipping fetch-rebase" >&2 - exit 0 -fi - -git fetch origin master -git fetch origin master --tags -git rebase origin/master diff --git a/scripts/install b/scripts/install new file mode 100755 index 0000000..172b2fd --- /dev/null +++ b/scripts/install @@ -0,0 +1,86 @@ +#!/usr/bin/env bash +# +# Run after cloning from the template. Idempotent — safe to run multiple times. +# Substitutes PKGCRATE / PKGBIN placeholders, installs git hooks, creates the +# develop branch, sets the CI_DISPATCH_TOKEN secret, and configures branch protection. +# +# Usage: +# bash scripts/install [binary-name] +# +# When crate name and binary name are the same (most projects): +# bash scripts/install mytool +# +# When they differ (e.g. crate published as "mytool-rust", binary is "mytool"): +# bash scripts/install mytool-rust mytool + +set -uo pipefail + +if [[ $# -lt 1 || $# -gt 2 ]]; then + echo "usage: bash scripts/install [binary-name]" >&2 + exit 1 +fi + +PKGCRATE="$1" +PKGBIN="${2:-$1}" + +repo_root="$(git rev-parse --show-toplevel)" +cd "$repo_root" + +ok() { echo " [ok] $*"; } +skip() { echo " [--] $*"; } +fail() { echo " [!!] $*" >&2; } + +echo +echo "==> substitute placeholders (PKGCRATE=${PKGCRATE}, PKGBIN=${PKGBIN})" +mapfile -t files < <(grep -rl "PKGCRATE\|PKGBIN" . \ + --exclude-dir=.git \ + --exclude-dir=target \ + --exclude="$(basename "$0")" 2>/dev/null || true) + +if [[ ${#files[@]} -eq 0 ]]; then + skip "no placeholder files found (already substituted?)" +else + for f in "${files[@]}"; do + sed -i "s/PKGCRATE/${PKGCRATE}/g; s/PKGBIN/${PKGBIN}/g" "$f" + ok "updated $f" + done +fi + +echo +echo "==> install git hooks" +hooks_dir="${repo_root}/scripts/hooks" +chmod +x "${hooks_dir}"/* 2>/dev/null || true +git -C "${repo_root}" config core.hooksPath scripts/hooks +ok "core.hooksPath set to scripts/hooks" + +echo +echo "==> create branch develop" +if git -C "${repo_root}" show-ref --verify --quiet refs/heads/develop; then + skip "branch develop already exists" + git -C "${repo_root}" checkout develop + ok "checked out develop" +else + git -C "${repo_root}" checkout -b develop + ok "created and checked out develop" +fi + +echo +echo "==> set CI_DISPATCH_TOKEN secret on x71c9/${PKGBIN}" +if pass github.com/github@x71c9.com/personal_access_token/CI_DISPATCH_TOKEN \ + | gh secret set CI_DISPATCH_TOKEN --repo "x71c9/${PKGBIN}"; then + ok "CI_DISPATCH_TOKEN set" +else + fail "failed to set CI_DISPATCH_TOKEN (is the repo created on GitHub?)" +fi + +echo +echo "==> configure branch protection" +if bash "${repo_root}/scripts/setup-branch-protection"; then + ok "branch protection applied" +else + fail "setup-branch-protection failed" +fi + +echo +echo "Done. Crate: ${PKGCRATE}, binary: ${PKGBIN}" +echo "Next step: fill in pkgdesc (and any extra deps) in ci.toml" diff --git a/scripts/install-hooks.sh b/scripts/install-hooks.sh deleted file mode 100755 index 7da776a..0000000 --- a/scripts/install-hooks.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash -# -# Install the repo's git hooks. Points git at scripts/hooks/ via core.hooksPath -# so the hooks are version-controlled and shared with everyone who clones. -# -# Run once after cloning: ./scripts/install-hooks.sh - -set -euo pipefail - -repo_root="$(git rev-parse --show-toplevel)" -hooks_dir="${repo_root}/scripts/hooks" - -chmod +x "${hooks_dir}"/* 2>/dev/null || true - -git -C "${repo_root}" config core.hooksPath scripts/hooks - -echo "Installed git hooks from scripts/hooks (core.hooksPath set)." -echo "Hooks active:" -ls -1 "${hooks_dir}" diff --git a/scripts/pipe b/scripts/pipe new file mode 100755 index 0000000..3e42477 --- /dev/null +++ b/scripts/pipe @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +set -euo pipefail + +echo "==> cargo fmt" +cargo fmt + +echo "==> cargo clippy" +cargo clippy -- -D warnings + +echo "==> cargo test" +cargo test + +echo "==> cargo build" +cargo build diff --git a/scripts/setup-branch-protection.sh b/scripts/setup-branch-protection similarity index 96% rename from scripts/setup-branch-protection.sh rename to scripts/setup-branch-protection index 148b889..2c3e6ef 100755 --- a/scripts/setup-branch-protection.sh +++ b/scripts/setup-branch-protection @@ -32,8 +32,8 @@ ENFORCE_ADMINS="${ENFORCE_ADMINS:-false}" # Required status checks. Must match job `name:` values in pr-validation.yml. CONTEXTS=( - "Run Tests" - "Validate PR Title (Future Squash Commit)" + "validate / Run Tests" + "validate / Validate PR Title (Future Squash Commit)" ) echo "Configuring branch protection for ${REPO}@${BRANCH}" diff --git a/shell.nix b/shell.nix index 1ebc1a3..8fdb1ec 100644 --- a/shell.nix +++ b/shell.nix @@ -9,7 +9,7 @@ pkgs.mkShell { ]; shellHook = '' export PATH="$PWD/scripts:$PATH" - bash scripts/fetch-rebase.sh + bash scripts/fetch-rebase echo "cargo: $(cargo -V) | rustc: $(rustc -V)" echo "rustfmt: $(rustfmt --version) | clippy: $(cargo clippy --version)" '';