Skip to content

Commit c957b31

Browse files
chore: add build step to ci
1 parent 58c3d76 commit c957b31

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed

.github/workflows/ci.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,48 @@ jobs:
3333
- name: Run lints
3434
run: ./scripts/lint
3535

36+
build:
37+
timeout-minutes: 10
38+
name: build
39+
permissions:
40+
contents: read
41+
id-token: write
42+
runs-on: ${{ github.repository == 'stainless-sdks/stainless-v0-cli' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}
43+
if: github.event_name == 'push' || github.event.pull_request.head.repo.fork
44+
steps:
45+
- uses: actions/checkout@v6
46+
47+
- name: Setup go
48+
uses: actions/setup-go@v5
49+
with:
50+
go-version-file: ./go.mod
51+
52+
- name: Bootstrap
53+
run: ./scripts/bootstrap
54+
55+
- name: Run goreleaser
56+
uses: goreleaser/goreleaser-action@v6.1.0
57+
with:
58+
version: latest
59+
args: release --snapshot --clean --skip=publish
60+
env:
61+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
62+
63+
- name: Get GitHub OIDC Token
64+
if: github.repository == 'stainless-sdks/stainless-v0-cli'
65+
id: github-oidc
66+
uses: actions/github-script@v8
67+
with:
68+
script: core.setOutput('github_token', await core.getIDToken());
69+
70+
- name: Upload tarball
71+
if: github.repository == 'stainless-sdks/stainless-v0-cli'
72+
env:
73+
URL: https://pkg.stainless.com/s
74+
AUTH: ${{ steps.github-oidc.outputs.github_token }}
75+
SHA: ${{ github.sha }}
76+
run: ./scripts/utils/upload-artifact.sh
77+
3678
test:
3779
timeout-minutes: 10
3880
name: test

scripts/utils/upload-artifact.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env bash
2+
set -exuo pipefail
3+
4+
BINARY_NAME="stl"
5+
DIST_DIR="dist"
6+
FILENAME="dist.zip"
7+
8+
mapfile -d '' files < <(
9+
find "$DIST_DIR" -regextype posix-extended -type f \
10+
-regex ".*/[^/]*(amd64|arm64)[^/]*/${BINARY_NAME}(\\.exe)?$" -print0
11+
)
12+
13+
if [[ ${#files[@]} -eq 0 ]]; then
14+
echo -e "\033[31mNo binaries found for packaging.\033[0m"
15+
exit 1
16+
fi
17+
18+
rm -f "${DIST_DIR}/${FILENAME}"
19+
20+
while IFS= read -r -d '' dir; do
21+
printf "Remove the quarantine attribute before running the executable:\n\nxattr -d com.apple.quarantine %s\n" \
22+
"$BINARY_NAME" >"${dir}/README.txt"
23+
done < <(find "$DIST_DIR" -type d -name '*macos*' -print0)
24+
25+
relative_files=()
26+
for file in "${files[@]}"; do
27+
relative_files+=("${file#"${DIST_DIR}"/}")
28+
done
29+
30+
(cd "$DIST_DIR" && zip -r "$FILENAME" "${relative_files[@]}")
31+
32+
RESPONSE=$(curl -X POST "$URL?filename=$FILENAME" \
33+
-H "Authorization: Bearer $AUTH" \
34+
-H "Content-Type: application/json")
35+
36+
SIGNED_URL=$(echo "$RESPONSE" | jq -r '.url')
37+
38+
if [[ "$SIGNED_URL" == "null" ]]; then
39+
echo -e "\033[31mFailed to get signed URL.\033[0m"
40+
exit 1
41+
fi
42+
43+
UPLOAD_RESPONSE=$(curl -v -X PUT \
44+
-H "Content-Type: application/zip" \
45+
--data-binary "@${DIST_DIR}/${FILENAME}" "$SIGNED_URL" 2>&1)
46+
47+
if echo "$UPLOAD_RESPONSE" | grep -q "HTTP/[0-9.]* 200"; then
48+
echo -e "\033[32mUploaded build to Stainless storage.\033[0m"
49+
echo -e "\033[32mInstallation: Download and unzip: 'https://pkg.stainless.com/s/stainless-v0-cli/$SHA/$FILENAME'. On macOS, run `xattr -d com.apple.quarantine {executable name}.`\033[0m"
50+
else
51+
echo -e "\033[31mFailed to upload artifact.\033[0m"
52+
exit 1
53+
fi

0 commit comments

Comments
 (0)