Skip to content

Commit c110bb0

Browse files
ci: Harden GitHub Actions permissions (#27)
1 parent f982a03 commit c110bb0

4 files changed

Lines changed: 28 additions & 17 deletions

File tree

.github/actions/setup-go/action.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@ runs:
1717
- name: Configure Git for access to the Go SDK's staging repo
1818
if: github.repository == 'stainless-sdks/openai-cli'
1919
shell: bash
20-
run: git config --global url."https://x-access-token:${{ steps.get_token.outputs.github_access_token }}@github.com/stainless-sdks/openai-go".insteadOf "https://github.com/stainless-sdks/openai-go"
20+
env:
21+
GITHUB_ACCESS_TOKEN: ${{ steps.get_token.outputs.github_access_token }}
22+
run: |
23+
{
24+
echo "GIT_CONFIG_COUNT=1"
25+
echo "GIT_CONFIG_KEY_0=url.https://x-access-token:${GITHUB_ACCESS_TOKEN}@github.com/stainless-sdks/openai-go.insteadOf"
26+
echo "GIT_CONFIG_VALUE_0=https://github.com/stainless-sdks/openai-go"
27+
} >> "$GITHUB_ENV"
2128
2229
- name: Setup go
2330
uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5

.github/workflows/ci.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
name: CI
2+
permissions:
3+
contents: read
24
on:
35
push:
46
branches:
@@ -35,8 +37,10 @@ jobs:
3537

3638
- name: Link staging branch
3739
if: github.repository == 'stainless-sdks/openai-cli'
40+
env:
41+
GO_SDK_REPLACEMENT: github.com/stainless-sdks/openai-go/v3@${{ github.ref_name }}
3842
run: |
39-
./scripts/link 'github.com/stainless-sdks/openai-go/v3@${{ github.ref_name }}' || true
43+
./scripts/link "$GO_SDK_REPLACEMENT" || true
4044
4145
- name: Bootstrap
4246
run: ./scripts/bootstrap
@@ -63,8 +67,10 @@ jobs:
6367

6468
- name: Link staging branch
6569
if: github.repository == 'stainless-sdks/openai-cli'
70+
env:
71+
GO_SDK_REPLACEMENT: github.com/stainless-sdks/openai-go/v3@${{ github.ref_name }}
6672
run: |
67-
./scripts/link 'github.com/stainless-sdks/openai-go/v3@${{ github.ref_name }}' || true
73+
./scripts/link "$GO_SDK_REPLACEMENT" || true
6874
6975
- name: Bootstrap
7076
run: ./scripts/bootstrap
@@ -116,8 +122,10 @@ jobs:
116122

117123
- name: Link staging branch
118124
if: github.repository == 'stainless-sdks/openai-cli'
125+
env:
126+
GO_SDK_REPLACEMENT: github.com/stainless-sdks/openai-go/v3@${{ github.ref_name }}
119127
run: |
120-
./scripts/link 'github.com/stainless-sdks/openai-go/v3@${{ github.ref_name }}' || true
128+
./scripts/link "$GO_SDK_REPLACEMENT" || true
121129
122130
- name: Bootstrap
123131
run: ./scripts/bootstrap

.github/workflows/create-releases.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,9 @@ jobs:
1212
if: github.ref == 'refs/heads/main' && github.repository == 'openai/openai-cli'
1313
runs-on: ubuntu-latest
1414
environment: publish
15-
permissions:
16-
contents: write
15+
permissions: {}
1716

1817
steps:
19-
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
20-
with:
21-
persist-credentials: false
22-
2318
- uses: stainless-api/trigger-release-please@bb6677c5a04578eec1ccfd9e1913b5b78ed64c61 # v1.4.0
2419
id: release
2520
with:

scripts/utils/upload-artifact.sh

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bash
2-
set -exuo pipefail
2+
set -euo pipefail
33

44
BINARY_NAME="openai"
55
DIST_DIR="dist"
@@ -35,7 +35,7 @@ done
3535

3636
(cd "$DIST_DIR" && zip -r "$FILENAME" "${relative_files[@]}")
3737

38-
RESPONSE=$(curl -X POST "$URL?filename=$FILENAME" \
38+
RESPONSE=$(curl --fail-with-body -sS -X POST "$URL?filename=$FILENAME" \
3939
-H "Authorization: Bearer $AUTH" \
4040
-H "Content-Type: application/json")
4141

@@ -46,14 +46,15 @@ if [[ "$SIGNED_URL" == "null" ]]; then
4646
exit 1
4747
fi
4848

49-
UPLOAD_RESPONSE=$(curl -v -X PUT \
49+
if UPLOAD_STATUS=$(curl -sS -X PUT \
5050
-H "Content-Type: application/zip" \
51-
--data-binary "@${DIST_DIR}/${FILENAME}" "$SIGNED_URL" 2>&1)
52-
53-
if echo "$UPLOAD_RESPONSE" | grep -q "HTTP/[0-9.]* 200"; then
51+
--data-binary "@${DIST_DIR}/${FILENAME}" \
52+
--output /dev/null \
53+
--write-out "%{http_code}" \
54+
"$SIGNED_URL") && [[ "$UPLOAD_STATUS" == "200" ]]; then
5455
echo -e "\033[32mUploaded build to Stainless storage.\033[0m"
5556
echo -e "\033[32mInstallation: Download and unzip: 'https://pkg.stainless.com/s/openai-cli/$SHA'. On macOS, run 'xattr -d com.apple.quarantine {executable name}'.\033[0m"
5657
else
57-
echo -e "\033[31mFailed to upload artifact.\033[0m"
58+
echo -e "\033[31mFailed to upload artifact. HTTP status: ${UPLOAD_STATUS:-curl failed}.\033[0m"
5859
exit 1
5960
fi

0 commit comments

Comments
 (0)