Skip to content

Commit 61b50d6

Browse files
authored
Merge pull request #185 from grafbase/tomhoule-nlvlupvqokrx
protoc-gen-grafbase-subgraph: binary download script and release
2 parents 6a24625 + 69bba9c commit 61b50d6

File tree

3 files changed

+168
-8
lines changed

3 files changed

+168
-8
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
[tasks.bump]
2+
script = '''
3+
#!/usr/bin/env bash
4+
set -e
5+
6+
# Get current version from Cargo.toml
7+
current_version=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
8+
echo "Current version: $current_version"
9+
10+
# Read new version from user
11+
read -p "Enter new version (x.y.z): " new_version
12+
13+
# Validate version format
14+
if ! [[ $new_version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
15+
echo "Error: Version must be in format x.y.z"
16+
exit 1
17+
fi
18+
19+
# Update version in Cargo.toml
20+
if [[ "$OSTYPE" == "darwin"* ]]; then
21+
# macOS
22+
sed -i '' "s/^version = \".*\"/version = \"$new_version\"/" Cargo.toml
23+
else
24+
# Linux
25+
sed -i "s/^version = \".*\"/version = \"$new_version\"/" Cargo.toml
26+
fi
27+
28+
# Update version in install.sh
29+
if [[ "$OSTYPE" == "darwin"* ]]; then
30+
# macOS
31+
sed -i '' "s/^LATEST_VERSION=\".*\"/LATEST_VERSION=\"$new_version\"/" install.sh
32+
else
33+
# Linux
34+
sed -i "s/^LATEST_VERSION=\".*\"/LATEST_VERSION=\"$new_version\"/" install.sh
35+
fi
36+
37+
echo "Version bumped to $new_version"
38+
echo "Updated files:"
39+
echo " - Cargo.toml"
40+
echo " - install.sh"
41+
'''

cli/protoc-gen-grafbase-subgraph/README.md

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,24 @@ This binary crate is a protoc plugin that generates a GraphQL subgraph to be use
44

55
## Installation
66

7+
### Quick install with script
8+
9+
You can install the latest version using the install script:
10+
11+
```bash
12+
curl -fsSL https://raw.githubusercontent.com/grafbase/extensions/main/cli/protoc-gen-grafbase-subgraph/install.sh | bash
13+
```
14+
15+
Or download and run manually:
16+
17+
```bash
18+
curl -O https://raw.githubusercontent.com/grafbase/extensions/main/cli/protoc-gen-grafbase-subgraph/install.sh
19+
chmod +x install.sh
20+
./install.sh
21+
```
22+
23+
### Manual installation
24+
725
Download the relevant binary from your platform from the [GitHub releases](https://github.com/grafbase/extensions/releases?q=protoc-gen-grafbase-subgraph&expanded=true).
826

927
## Usage with buf
@@ -436,16 +454,22 @@ type Mutation {
436454

437455
### Releasing
438456

439-
To release a new version of the binary:
457+
To release a new version:
440458

441-
1. Update the version number in `Cargo.toml`
442-
2. Create a tag with the format `protoc-gen-grafbase-subgraph-X.Y.Z` (e.g., `protoc-gen-grafbase-subgraph-0.2.0`)
443-
3. Push the tag to GitHub:
459+
1. **Bump version**: Run `cargo make bump` to update version in `Cargo.toml` and `install.sh`
460+
2. **Update changelog**: Edit `CHANGELOG.md` with release notes
461+
3. **Commit and push**:
462+
```bash
463+
git add Cargo.toml install.sh CHANGELOG.md
464+
git commit -m "Bump protoc-gen-grafbase-subgraph to vX.Y.Z"
465+
git push origin main
444466
```
445-
git tag protoc-gen-grafbase-subgraph-X.Y.Z
446-
git push origin protoc-gen-grafbase-subgraph-X.Y.Z
447-
```
448-
4. The GitHub Actions workflow will automatically build the binary for multiple platforms and create a release with the artifacts
467+
468+
The GitHub Actions workflow will automatically:
469+
- Detect the version change
470+
- Build binaries for macOS, Windows, Linux (x64/ARM64)
471+
- Create a GitHub release with tag `protoc-gen-grafbase-subgraph-vX.Y.Z`
472+
- Upload the binaries as release assets
449473

450474
## Prior art
451475

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
LATEST_VERSION="0.3.0"
6+
NAME="protoc-gen-grafbase-subgraph"
7+
8+
echo "Installing $NAME v$LATEST_VERSION..."
9+
10+
# Get the operating system and architecture
11+
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
12+
ARCH=$(uname -m)
13+
14+
# Map the OS and architecture to the target triple
15+
case "$OS" in
16+
darwin)
17+
case "$ARCH" in
18+
x86_64)
19+
TARGET="x86_64-apple-darwin"
20+
;;
21+
arm64)
22+
TARGET="aarch64-apple-darwin"
23+
;;
24+
*)
25+
echo "Error: Unsupported architecture $ARCH on macOS"
26+
exit 1
27+
;;
28+
esac
29+
;;
30+
linux)
31+
case "$ARCH" in
32+
aarch64|arm64)
33+
TARGET="aarch64-unknown-linux-musl"
34+
;;
35+
x86_64)
36+
TARGET="x86_64-unknown-linux-musl"
37+
;;
38+
*)
39+
echo "Error: Unsupported architecture $ARCH on Linux"
40+
exit 1
41+
;;
42+
esac
43+
;;
44+
*)
45+
echo "Error: Unsupported operating system $OS"
46+
exit 1
47+
;;
48+
esac
49+
50+
# Create the installation directory
51+
INSTALL_DIR="$HOME/.grafbase/bin"
52+
mkdir -p "$INSTALL_DIR"
53+
54+
# Download the binary
55+
URL="https://github.com/grafbase/extensions/releases/download/$NAME-v$LATEST_VERSION/$NAME-$TARGET"
56+
echo "Downloading from $URL..."
57+
58+
if command -v curl >/dev/null 2>&1; then
59+
curl -sSL "$URL" -o "$INSTALL_DIR/$NAME"
60+
elif command -v wget >/dev/null 2>&1; then
61+
wget -q "$URL" -O "$INSTALL_DIR/$NAME"
62+
else
63+
echo "Error: Neither curl nor wget is installed"
64+
exit 1
65+
fi
66+
67+
# Make the binary executable
68+
chmod +x "$INSTALL_DIR/$NAME"
69+
70+
echo "$NAME has been installed to $INSTALL_DIR/$NAME"
71+
72+
# Check if the installation directory is in PATH
73+
if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then
74+
echo ""
75+
echo "Add $INSTALL_DIR to your PATH to use $NAME from anywhere."
76+
echo ""
77+
78+
# Detect the shell and provide instructions
79+
if [ -n "$FISH_VERSION" ]; then
80+
echo "For fish shell, add to ~/.config/fish/config.fish:"
81+
echo " fish_add_path $INSTALL_DIR"
82+
elif [ -n "$ZSH_VERSION" ]; then
83+
echo "For zsh, add to ~/.zshrc:"
84+
echo " export PATH=\"\$PATH:$INSTALL_DIR\""
85+
elif [ -n "$BASH_VERSION" ]; then
86+
echo "For bash, add to ~/.bashrc or ~/.bash_profile:"
87+
echo " export PATH=\"\$PATH:$INSTALL_DIR\""
88+
else
89+
echo "Add to your shell configuration file:"
90+
echo " export PATH=\"\$PATH:$INSTALL_DIR\""
91+
fi
92+
fi
93+
94+
echo ""
95+
echo "Installation complete! You can now use '$NAME'."

0 commit comments

Comments
 (0)