Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,40 @@ on:
- 'stl-preview-base/**'

jobs:
build:
timeout-minutes: 10
name: build
permissions:
contents: read
id-token: write
runs-on: ${{ github.repository == 'stainless-sdks/stagehand-ruby' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}
if: |-
github.repository == 'stainless-sdks/stagehand-ruby' &&
(github.event_name == 'push' || github.event.pull_request.head.repo.fork)
steps:
- uses: actions/checkout@v6
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: false
- run: |-
bundle install

- name: Get GitHub OIDC Token
if: github.repository == 'stainless-sdks/stagehand-ruby'
id: github-oidc
uses: actions/github-script@v8
with:
script: core.setOutput('github_token', await core.getIDToken());

- name: Build and upload gem artifacts
if: github.repository == 'stainless-sdks/stagehand-ruby'
env:
URL: https://pkg.stainless.com/s
AUTH: ${{ steps.github-oidc.outputs.github_token }}
SHA: ${{ github.sha }}
PACKAGE_NAME: stagehand
run: ./scripts/utils/upload-artifact.sh
lint:
timeout-minutes: 10
name: lint
Expand Down
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "3.7.1"
".": "3.7.2"
}
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## 3.7.2 (2026-03-03)

Full Changelog: [v3.7.1...v3.7.2](https://github.com/browserbase/stagehand-ruby/compare/v3.7.1...v3.7.2)

### Chores

* **ci:** add build step ([ed6573f](https://github.com/browserbase/stagehand-ruby/commit/ed6573f2ddab4f5f51d1262480cb663da5e003d0))
* **internal:** codegen related update ([ed9fab1](https://github.com/browserbase/stagehand-ruby/commit/ed9fab1f726c05ef48d4a55507b09212d7ced713))

## 3.7.1 (2026-02-27)

Full Changelog: [v3.7.0...v3.7.1](https://github.com/browserbase/stagehand-ruby/compare/v3.7.0...v3.7.1)
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ GIT
PATH
remote: .
specs:
stagehand (3.7.1)
stagehand (3.7.2)
cgi
connection_pool

Expand Down
31 changes: 31 additions & 0 deletions lib/stagehand/internal/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,37 @@ def writable_enum(&blk)
JSONL_CONTENT = %r{^application/(:?x-(?:n|l)djson)|(:?(?:x-)?jsonl)}

class << self
# @api private
#
# @param query [Hash{Symbol=>Object}]
#
# @return [Hash{Symbol=>Object}]
def encode_query_params(query)
out = {}
query.each { write_query_param_element!(out, _1, _2) }
out
end

# @api private
#
# @param collection [Hash{Symbol=>Object}]
# @param key [String]
# @param element [Object]
#
# @return [nil]
private def write_query_param_element!(collection, key, element)
case element
in Hash
element.each do |name, value|
write_query_param_element!(collection, "#{key}[#{name}]", value)
end
in Array
collection[key] = element.map(&:to_s).join(",")
else
collection[key] = element.to_s
end
end

# @api private
#
# @param y [Enumerator::Yielder]
Expand Down
2 changes: 1 addition & 1 deletion lib/stagehand/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Stagehand
VERSION = "3.7.1"
VERSION = "3.7.2"
end
20 changes: 20 additions & 0 deletions rbi/stagehand/internal/util.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,26 @@ module Stagehand
T.let(%r{^application/(:?x-(?:n|l)djson)|(:?(?:x-)?jsonl)}, Regexp)

class << self
# @api private
sig do
params(query: Stagehand::Internal::AnyHash).returns(
Stagehand::Internal::AnyHash
)
end
def encode_query_params(query)
end

# @api private
sig do
params(
collection: Stagehand::Internal::AnyHash,
key: String,
element: T.anything
).void
end
private def write_query_param_element!(collection, key, element)
end

# @api private
sig do
params(
Expand Down
113 changes: 113 additions & 0 deletions scripts/utils/upload-artifact.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#!/usr/bin/env bash

set -euo pipefail

# ANSI Color Codes
GREEN='\033[32m'
RED='\033[31m'
NC='\033[0m' # No Color

DIST_DIR="dist"

log_error() {
local msg="$1"
local headers="$2"
local body="$3"
echo -e "${RED}${msg}${NC}"
[[ -f "$headers" ]] && echo -e "${RED}Headers:$(cat "$headers")${NC}"
echo -e "${RED}Body: ${body}${NC}"
exit 1
}

upload_file() {
local file_name="$1"
local tmp_headers
tmp_headers=$(mktemp)

if [ -f "$file_name" ]; then
echo -e "${GREEN}Processing file: $file_name${NC}"
pkg_file_name="${file_name#"${DIST_DIR}/"}"

# Get signed URL for uploading artifact file
signed_url_response=$(curl -X POST -G "$URL" \
-sS --retry 5 \
-D "$tmp_headers" \
--data-urlencode "filename=$pkg_file_name" \
-H "Authorization: Bearer $AUTH" \
-H "Content-Type: application/json")

# Validate JSON and extract URL
if ! signed_url=$(echo "$signed_url_response" | jq -e -r '.url' 2>/dev/null) || [[ "$signed_url" == "null" ]]; then
log_error "Failed to get valid signed URL" "$tmp_headers" "$signed_url_response"
fi

# Set content-type based on file extension
local extension="${file_name##*.}"
local content_type
case "$extension" in
gem) content_type="application/octet-stream" ;;
gz) content_type="application/gzip" ;;
rz) content_type="application/octet-stream" ;;
html) content_type="text/html" ;;
*) content_type="application/octet-stream" ;;
esac

# Upload file
upload_response=$(curl -v -X PUT \
--retry 5 \
--retry-all-errors \
-D "$tmp_headers" \
-H "Content-Type: $content_type" \
--data-binary "@${file_name}" "$signed_url" 2>&1)

if ! echo "$upload_response" | grep -q "HTTP/[0-9.]* 200"; then
log_error "Failed to upload artifact file" "$tmp_headers" "$upload_response"
fi

# Insert small throttle to reduce rate limiting risk
sleep 0.1
fi
}

walk_tree() {
local current_dir="$1"

for entry in "$current_dir"/*; do
# Check that entry is valid
[ -e "$entry" ] || [ -h "$entry" ] || continue

if [ -d "$entry" ]; then
walk_tree "$entry"
else
upload_file "$entry"
fi
done
}

cd "$(dirname "$0")/../.."

echo "::group::Building gem"
VERSION_FILE="lib/${PACKAGE_NAME}/version.rb"
if [[ ! -f "$VERSION_FILE" ]]; then
echo -e "${RED}Version file not found: ${VERSION_FILE}${NC}"
exit 1
fi
SHORT_SHA="${SHA:0:7}"
sed -i.bak -E "s/(VERSION = \"[^\"]+)\"/\1.beta.${SHORT_SHA}\"/" "$VERSION_FILE"
rm -f "${VERSION_FILE}.bak"

gem build
mkdir -p "${DIST_DIR}/gems"
mv ./*.gem "${DIST_DIR}/gems/"
echo "::endgroup::"

echo "::group::Generating gem index"
gem generate_index --directory "$DIST_DIR"
echo "::endgroup::"

echo "::group::Uploading to pkg.stainless.com"
walk_tree "$DIST_DIR"
echo "::endgroup::"

echo -e "${GREEN}Gem artifacts uploaded to Stainless storage.${NC}"
echo -e "\033[32mInstallation: bundle remove stagehand && bundle add stagehand --source 'https://pkg.stainless.com/s/stagehand-ruby/$SHA'\033[0m"
10 changes: 10 additions & 0 deletions sig/stagehand/internal/util.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@ module Stagehand
JSON_CONTENT: Regexp
JSONL_CONTENT: Regexp

def encode_query_params: (
::Hash[Symbol, top] query
) -> ::Hash[Symbol, top]

private def write_query_param_element!: (
::Hash[Symbol, top] collection,
String key,
top element
) -> nil

def self?.write_multipart_content: (
Enumerator::Yielder y,
val: top,
Expand Down