Skip to content

Commit 99b5132

Browse files
chore(ci): add build step
1 parent 84f2624 commit 99b5132

File tree

2 files changed

+147
-0
lines changed

2 files changed

+147
-0
lines changed

.github/workflows/ci.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,40 @@ on:
1313
- 'stl-preview-base/**'
1414

1515
jobs:
16+
build:
17+
timeout-minutes: 10
18+
name: build
19+
permissions:
20+
contents: read
21+
id-token: write
22+
runs-on: ${{ github.repository == 'stainless-sdks/tilda-ruby' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}
23+
if: |-
24+
github.repository == 'stainless-sdks/tilda-ruby' &&
25+
(github.event_name == 'push' || github.event.pull_request.head.repo.fork)
26+
steps:
27+
- uses: actions/checkout@v6
28+
- name: Set up Ruby
29+
uses: ruby/setup-ruby@v1
30+
with:
31+
bundler-cache: false
32+
- run: |-
33+
bundle install
34+
35+
- name: Get GitHub OIDC Token
36+
if: github.repository == 'stainless-sdks/tilda-ruby'
37+
id: github-oidc
38+
uses: actions/github-script@v8
39+
with:
40+
script: core.setOutput('github_token', await core.getIDToken());
41+
42+
- name: Build and upload gem artifacts
43+
if: github.repository == 'stainless-sdks/tilda-ruby'
44+
env:
45+
URL: https://pkg.stainless.com/s
46+
AUTH: ${{ steps.github-oidc.outputs.github_token }}
47+
SHA: ${{ github.sha }}
48+
PACKAGE_NAME: tilda_ruby
49+
run: ./scripts/utils/upload-artifact.sh
1650
lint:
1751
timeout-minutes: 10
1852
name: lint

scripts/utils/upload-artifact.sh

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
# ANSI Color Codes
6+
GREEN='\033[32m'
7+
RED='\033[31m'
8+
NC='\033[0m' # No Color
9+
10+
DIST_DIR="dist"
11+
12+
log_error() {
13+
local msg="$1"
14+
local headers="$2"
15+
local body="$3"
16+
echo -e "${RED}${msg}${NC}"
17+
[[ -f "$headers" ]] && echo -e "${RED}Headers:$(cat "$headers")${NC}"
18+
echo -e "${RED}Body: ${body}${NC}"
19+
exit 1
20+
}
21+
22+
upload_file() {
23+
local file_name="$1"
24+
local tmp_headers
25+
tmp_headers=$(mktemp)
26+
27+
if [ -f "$file_name" ]; then
28+
echo -e "${GREEN}Processing file: $file_name${NC}"
29+
pkg_file_name="${file_name#"${DIST_DIR}/"}"
30+
31+
# Get signed URL for uploading artifact file
32+
signed_url_response=$(curl -X POST -G "$URL" \
33+
-sS --retry 5 \
34+
-D "$tmp_headers" \
35+
--data-urlencode "filename=$pkg_file_name" \
36+
-H "Authorization: Bearer $AUTH" \
37+
-H "Content-Type: application/json")
38+
39+
# Validate JSON and extract URL
40+
if ! signed_url=$(echo "$signed_url_response" | jq -e -r '.url' 2>/dev/null) || [[ "$signed_url" == "null" ]]; then
41+
log_error "Failed to get valid signed URL" "$tmp_headers" "$signed_url_response"
42+
fi
43+
44+
# Set content-type based on file extension
45+
local extension="${file_name##*.}"
46+
local content_type
47+
case "$extension" in
48+
gem) content_type="application/octet-stream" ;;
49+
gz) content_type="application/gzip" ;;
50+
rz) content_type="application/octet-stream" ;;
51+
html) content_type="text/html" ;;
52+
*) content_type="application/octet-stream" ;;
53+
esac
54+
55+
# Upload file
56+
upload_response=$(curl -v -X PUT \
57+
--retry 5 \
58+
--retry-all-errors \
59+
-D "$tmp_headers" \
60+
-H "Content-Type: $content_type" \
61+
--data-binary "@${file_name}" "$signed_url" 2>&1)
62+
63+
if ! echo "$upload_response" | grep -q "HTTP/[0-9.]* 200"; then
64+
log_error "Failed to upload artifact file" "$tmp_headers" "$upload_response"
65+
fi
66+
67+
# Insert small throttle to reduce rate limiting risk
68+
sleep 0.1
69+
fi
70+
}
71+
72+
walk_tree() {
73+
local current_dir="$1"
74+
75+
for entry in "$current_dir"/*; do
76+
# Check that entry is valid
77+
[ -e "$entry" ] || [ -h "$entry" ] || continue
78+
79+
if [ -d "$entry" ]; then
80+
walk_tree "$entry"
81+
else
82+
upload_file "$entry"
83+
fi
84+
done
85+
}
86+
87+
cd "$(dirname "$0")/../.."
88+
89+
echo "::group::Building gem"
90+
VERSION_FILE="lib/${PACKAGE_NAME}/version.rb"
91+
if [[ ! -f "$VERSION_FILE" ]]; then
92+
echo -e "${RED}Version file not found: ${VERSION_FILE}${NC}"
93+
exit 1
94+
fi
95+
SHORT_SHA="${SHA:0:7}"
96+
sed -i.bak -E "s/(VERSION = \"[^\"]+)\"/\1.beta.${SHORT_SHA}\"/" "$VERSION_FILE"
97+
rm -f "${VERSION_FILE}.bak"
98+
99+
gem build
100+
mkdir -p "${DIST_DIR}/gems"
101+
mv ./*.gem "${DIST_DIR}/gems/"
102+
echo "::endgroup::"
103+
104+
echo "::group::Generating gem index"
105+
gem generate_index --directory "$DIST_DIR"
106+
echo "::endgroup::"
107+
108+
echo "::group::Uploading to pkg.stainless.com"
109+
walk_tree "$DIST_DIR"
110+
echo "::endgroup::"
111+
112+
echo -e "${GREEN}Gem artifacts uploaded to Stainless storage.${NC}"
113+
echo -e "\033[32mInstallation: bundle remove tilda-ruby && bundle add tilda-ruby --source 'https://pkg.stainless.com/s/tilda-ruby/$SHA'\033[0m"

0 commit comments

Comments
 (0)