Skip to content

Commit 2fb2d16

Browse files
authored
Set up pre-commit GH workflow and switch to prek (#273)
* Use prek for pre-commit also configure gh action check * Shfmt changes * Add back checks from pre-commit/pre-commit-hooks * Update agents.md to use prek * show diff on failure is enabeled by default * Install tools * fixing trailing whitespace * use arc-runner * See if configuring the config file makes a difference here * Support for prek.toml was only added in v0.3.2 so we need to update the runner * Add go modules cache
1 parent 448305c commit 2fb2d16

6 files changed

Lines changed: 158 additions & 107 deletions

File tree

.github/workflows/prek.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: prek
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
workflow_dispatch:
8+
9+
concurrency:
10+
group: prek-${{ github.event.pull_request.number || github.sha }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
prek:
15+
name: Run prek hooks
16+
runs-on: arc-runner-15cpu
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
21+
- name: Cache Go modules
22+
uses: actions/cache@v4
23+
with:
24+
path: ~/.cache/go-build
25+
key: ${{ runner.os }}-go-prek-${{ hashFiles('**/go.sum') }}
26+
27+
- name: Install shfmt
28+
run: go install mvdan.cc/sh/v3/cmd/shfmt@latest
29+
30+
- name: Cache prek
31+
uses: actions/cache@v4
32+
with:
33+
path: ~/.cache/prek
34+
key: prek-${{ hashFiles('prek.toml') }}
35+
36+
- name: Run prek
37+
run: prek run --all-files --show-diff-on-failure --verbose

.pre-commit-config.yaml

Lines changed: 0 additions & 32 deletions
This file was deleted.

AGENTS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ go test -run TestName ./pkg/... # Single test
5454

5555
# Linting & Formatting
5656
golangci-lint run # Lint
57-
pre-commit run --all-files # All hooks
57+
prek run --all-files # All hooks (see prek.toml)
5858

5959
# Type Generation (from public-api-schema)
6060
export RENDER_API_PATH=/path/to/api
@@ -127,7 +127,7 @@ export RENDER_API_KEY="your-api-key"
127127

128128
- **Table-driven tests** with `stretchr/testify`
129129
- **Manual fakes** in `pkg/tui/testhelper/`
130-
- **Pre-commit hooks**: golangci-lint, go fmt, yaml checks, large file detection
130+
- **Hooks** (`prek.toml`): golangci-lint, shellcheck, shfmt, yaml checks, large file detection
131131

132132
## Common Gotchas
133133

bin/install.sh

Lines changed: 72 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -8,99 +8,99 @@ set -e
88
# Prevent running with partial download
99
{ # this ensures the entire script is downloaded
1010

11-
# Function to get latest release info using GitHub API
12-
get_latest_release() {
13-
curl --silent "https://api.github.com/repos/render-oss/cli/releases/latest" |
14-
sed -n 's/.*"tag_name": "\([^"]*\)".*/\1/p'
15-
}
16-
17-
# Function to output error message and exit
18-
error() {
11+
# Function to get latest release info using GitHub API
12+
get_latest_release() {
13+
curl --silent "https://api.github.com/repos/render-oss/cli/releases/latest" \
14+
| sed -n 's/.*"tag_name": "\([^"]*\)".*/\1/p'
15+
}
16+
17+
# Function to output error message and exit
18+
error() {
1919
echo "Error: $1" >&2
2020
exit 1
21-
}
22-
23-
# Check for required commands
24-
command -v curl >/dev/null 2>&1 || error "curl is required but not installed"
25-
command -v sed >/dev/null 2>&1 || error "sed is required but not installed"
26-
command -v unzip >/dev/null 2>&1 || error "unzip is required but not installed"
27-
28-
# Detect OS
29-
OS="$(uname -s)"
30-
case "${OS}" in
31-
Linux*) OS_NAME=linux;;
32-
Darwin*) OS_NAME=darwin;;
33-
*) error "Unsupported operating system: ${OS}";;
34-
esac
35-
36-
# Detect architecture
37-
ARCH="$(uname -m)"
38-
case "${ARCH}" in
39-
x86_64*) ARCH_NAME=amd64;;
40-
arm64*) ARCH_NAME=arm64;;
41-
aarch64*) ARCH_NAME=arm64;;
42-
*) error "Unsupported architecture: ${ARCH}";;
43-
esac
44-
45-
# Get the latest release version
46-
VERSION=$(get_latest_release)
47-
if [ -z "$VERSION" ]; then
21+
}
22+
23+
# Check for required commands
24+
command -v curl > /dev/null 2>&1 || error "curl is required but not installed"
25+
command -v sed > /dev/null 2>&1 || error "sed is required but not installed"
26+
command -v unzip > /dev/null 2>&1 || error "unzip is required but not installed"
27+
28+
# Detect OS
29+
OS="$(uname -s)"
30+
case "${OS}" in
31+
Linux*) OS_NAME=linux ;;
32+
Darwin*) OS_NAME=darwin ;;
33+
*) error "Unsupported operating system: ${OS}" ;;
34+
esac
35+
36+
# Detect architecture
37+
ARCH="$(uname -m)"
38+
case "${ARCH}" in
39+
x86_64*) ARCH_NAME=amd64 ;;
40+
arm64*) ARCH_NAME=arm64 ;;
41+
aarch64*) ARCH_NAME=arm64 ;;
42+
*) error "Unsupported architecture: ${ARCH}" ;;
43+
esac
44+
45+
# Get the latest release version
46+
VERSION=$(get_latest_release)
47+
if [ -z "$VERSION" ]; then
4848
error "Failed to get latest release version"
49-
fi
49+
fi
5050

51-
# Remove 'v' prefix from version if present
52-
VERSION_NUM="${VERSION#v}"
51+
# Remove 'v' prefix from version if present
52+
VERSION_NUM="${VERSION#v}"
5353

54-
echo "Installing Render CLI version ${VERSION}..."
54+
echo "Installing Render CLI version ${VERSION}..."
5555

56-
# Construct download URL
57-
BINARY_NAME="cli_${VERSION_NUM}_${OS_NAME}_${ARCH_NAME}.zip"
58-
DOWNLOAD_URL="https://github.com/render-oss/cli/releases/download/${VERSION}/${BINARY_NAME}"
56+
# Construct download URL
57+
BINARY_NAME="cli_${VERSION_NUM}_${OS_NAME}_${ARCH_NAME}.zip"
58+
DOWNLOAD_URL="https://github.com/render-oss/cli/releases/download/${VERSION}/${BINARY_NAME}"
5959

60-
# Create temporary directory
61-
TMP_DIR=$(mktemp -d)
62-
trap 'rm -rf "$TMP_DIR"' EXIT
60+
# Create temporary directory
61+
TMP_DIR=$(mktemp -d)
62+
trap 'rm -rf "$TMP_DIR"' EXIT
6363

64-
# Download and install
65-
echo "Downloading from ${DOWNLOAD_URL}..."
66-
curl -fsSL "$DOWNLOAD_URL" -o "${TMP_DIR}/${BINARY_NAME}"
64+
# Download and install
65+
echo "Downloading from ${DOWNLOAD_URL}..."
66+
curl -fsSL "$DOWNLOAD_URL" -o "${TMP_DIR}/${BINARY_NAME}"
6767

68-
# Determine install location
69-
if [ "$(id -u)" -eq 0 ]; then
68+
# Determine install location
69+
if [ "$(id -u)" -eq 0 ]; then
7070
INSTALL_DIR="/usr/local/bin"
71-
else
71+
else
7272
INSTALL_DIR="$HOME/.local/bin"
7373
mkdir -p "$INSTALL_DIR"
74-
fi
74+
fi
7575

76-
# Unzip in temporary directory
77-
unzip -o "${TMP_DIR}/${BINARY_NAME}" -d "${TMP_DIR}" >/dev/null 2>&1
76+
# Unzip in temporary directory
77+
unzip -o "${TMP_DIR}/${BINARY_NAME}" -d "${TMP_DIR}" > /dev/null 2>&1
7878

79-
# Find and move the binary
80-
RENDER_BINARY=$(find "${TMP_DIR}" -type f -name "cli_v*" | head -n 1)
81-
if [ -z "$RENDER_BINARY" ]; then
79+
# Find and move the binary
80+
RENDER_BINARY=$(find "${TMP_DIR}" -type f -name "cli_v*" | head -n 1)
81+
if [ -z "$RENDER_BINARY" ]; then
8282
error "Could not find CLI binary in the archive"
83-
fi
83+
fi
8484

85-
mv "${RENDER_BINARY}" "${INSTALL_DIR}/render"
86-
chmod +x "${INSTALL_DIR}/render"
85+
mv "${RENDER_BINARY}" "${INSTALL_DIR}/render"
86+
chmod +x "${INSTALL_DIR}/render"
8787

88-
# Verify installation by checking the binary directly
89-
if [ -x "${INSTALL_DIR}/render" ]; then
88+
# Verify installation by checking the binary directly
89+
if [ -x "${INSTALL_DIR}/render" ]; then
9090
echo "✨ Successfully installed Render CLI to ${INSTALL_DIR}/render"
9191
echo
92-
if ! command -v render >/dev/null 2>&1; then
93-
echo "NOTE: Make sure ${INSTALL_DIR} is in your PATH by adding this to your shell's rc file:"
94-
echo " export PATH=\$PATH:${INSTALL_DIR}"
95-
echo
96-
echo "To use render CLI immediately, run:"
97-
echo " export PATH=\$PATH:${INSTALL_DIR}"
98-
echo " ${INSTALL_DIR}/render --version"
92+
if ! command -v render > /dev/null 2>&1; then
93+
echo "NOTE: Make sure ${INSTALL_DIR} is in your PATH by adding this to your shell's rc file:"
94+
echo " export PATH=\$PATH:${INSTALL_DIR}"
95+
echo
96+
echo "To use render CLI immediately, run:"
97+
echo " export PATH=\$PATH:${INSTALL_DIR}"
98+
echo " ${INSTALL_DIR}/render --version"
9999
else
100-
"${INSTALL_DIR}/render" --version
100+
"${INSTALL_DIR}/render" --version
101101
fi
102-
else
102+
else
103103
error "Installation failed: Could not install binary to ${INSTALL_DIR}/render"
104-
fi
104+
fi
105105

106106
}

cmd/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ start psql/SSH sessions, and more.
3535
The CLI's default %s mode provides intuitive, menu-based navigation.
3636
3737
To use in %s mode (such as in a script), you can set each command's --output
38-
option to either json or yaml for structured responses. We'll also detect if stdout
38+
option to either json or yaml for structured responses. We'll also detect if stdout
3939
is not a TTY and automatically switch to json output.
4040
`, welcomeMsg, renderstyle.Bold("interactive"), renderstyle.Bold("non-interactive"))
4141

prek.toml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
fail_fast = false
2+
3+
# Prek builtin hooks - fast, no network required (priority 0 = run first)
4+
[[repos]]
5+
repo = "builtin"
6+
hooks = [
7+
{ id = "trailing-whitespace", priority = 0 },
8+
{ id = "end-of-file-fixer", priority = 0 },
9+
{ id = "check-yaml", priority = 0 },
10+
{ id = "check-added-large-files", args = ["--maxkb=500"], priority = 0 },
11+
{ id = "check-case-conflict", priority = 0 },
12+
{ id = "check-merge-conflict", priority = 0 },
13+
{ id = "check-symlinks", priority = 0 },
14+
{ id = "detect-private-key", priority = 0 },
15+
{ id = "check-executables-have-shebangs", priority = 0 },
16+
]
17+
18+
# Additional hooks not available as builtins (priority 0 = run with other checks)
19+
[[repos]]
20+
repo = "https://github.com/pre-commit/pre-commit-hooks"
21+
rev = "v5.0.0"
22+
hooks = [
23+
{ id = "destroyed-symlinks", priority = 0 },
24+
{ id = "check-vcs-permalinks", files = "\\.md$", priority = 0 },
25+
]
26+
27+
# Formatters (priority 10 = run after builtin, before linters)
28+
[[repos]]
29+
repo = "local"
30+
hooks = [
31+
{ id = "shfmt", name = "shfmt", entry = "shfmt -l -w -i 2 -bn -ci -sr", language = "system", files = "\\.sh$", priority = 10 },
32+
]
33+
34+
# Linters (priority 20 = run last, after formatting)
35+
[[repos]]
36+
repo = "https://github.com/golangci/golangci-lint"
37+
rev = "v2.4.0"
38+
hooks = [
39+
{ id = "golangci-lint", priority = 20 },
40+
]
41+
42+
[[repos]]
43+
repo = "local"
44+
hooks = [
45+
{ id = "shellcheck", name = "shellcheck", entry = "shellcheck", language = "system", types = ["shell"], priority = 20 },
46+
]

0 commit comments

Comments
 (0)