Skip to content

Commit 4a8efaf

Browse files
committed
feat: enhance R2 configuration validation and update README with bucket naming guidelines
1 parent 91262a2 commit 4a8efaf

2 files changed

Lines changed: 59 additions & 4 deletions

File tree

.github/workflows/agent-release.yml

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,22 +113,66 @@ jobs:
113113
run: ls -lah ./dist/release
114114

115115
- name: Validate R2 configuration
116+
id: r2
116117
shell: bash
117118
run: |
118119
set -euo pipefail
120+
121+
trim() {
122+
local value="${1:-}"
123+
value="${value#"${value%%[![:space:]]*}"}"
124+
value="${value%"${value##*[![:space:]]}"}"
125+
printf '%s' "${value}"
126+
}
127+
119128
: "${AWS_ACCESS_KEY_ID:?Missing R2_ACCESS_KEY_ID secret}"
120129
: "${AWS_SECRET_ACCESS_KEY:?Missing R2_SECRET_ACCESS_KEY secret}"
121130
: "${R2_ACCOUNT_ID:?Missing R2_ACCOUNT_ID secret}"
122131
: "${R2_BUCKET:?Missing R2_BUCKET secret}"
132+
133+
raw_bucket="$(trim "${R2_BUCKET}")"
134+
135+
if [[ "${raw_bucket}" == s3://* ]]; then
136+
raw_bucket="${raw_bucket#s3://}"
137+
fi
138+
139+
if [[ "${raw_bucket}" == http://* || "${raw_bucket}" == https://* ]]; then
140+
path_part="${raw_bucket#http://}"
141+
path_part="${path_part#https://}"
142+
if [[ "${path_part}" != */* ]]; then
143+
echo "R2_BUCKET must be the bucket name only, not a URL without a bucket path." >&2
144+
echo "Example: media-assets" >&2
145+
exit 1
146+
fi
147+
raw_bucket="${path_part#*/}"
148+
fi
149+
150+
raw_bucket="${raw_bucket#/}"
151+
raw_bucket="${raw_bucket%%/*}"
152+
153+
if [[ -z "${raw_bucket}" ]]; then
154+
echo "Resolved R2 bucket name is empty. Set R2_BUCKET to your bucket name, for example media-assets." >&2
155+
exit 1
156+
fi
157+
158+
if [[ ! "${raw_bucket}" =~ ^[a-zA-Z0-9._-]{1,255}$ ]]; then
159+
echo "Resolved R2 bucket name is invalid: ${raw_bucket}" >&2
160+
echo "Set R2_BUCKET to the plain bucket name only, without https:// or extra path segments." >&2
161+
exit 1
162+
fi
163+
164+
echo "bucket_name=${raw_bucket}" >> "${GITHUB_OUTPUT}"
165+
echo "endpoint_url=https://${R2_ACCOUNT_ID}.r2.cloudflarestorage.com" >> "${GITHUB_OUTPUT}"
166+
123167
aws --version
124168
125169
- name: Publish installer and latest channel
126170
if: steps.release.outputs.publish_latest == 'true'
127171
shell: bash
128172
run: |
129173
set -euo pipefail
130-
endpoint="https://${R2_ACCOUNT_ID}.r2.cloudflarestorage.com"
131-
bucket="s3://${R2_BUCKET}"
174+
endpoint="${{ steps.r2.outputs.endpoint_url }}"
175+
bucket="s3://${{ steps.r2.outputs.bucket_name }}"
132176
133177
aws s3 cp ./dist/release/install.sh "${bucket}/noderax-agent/install.sh" \
134178
--endpoint-url "${endpoint}" \
@@ -155,8 +199,8 @@ jobs:
155199
shell: bash
156200
run: |
157201
set -euo pipefail
158-
endpoint="https://${R2_ACCOUNT_ID}.r2.cloudflarestorage.com"
159-
bucket="s3://${R2_BUCKET}"
202+
endpoint="${{ steps.r2.outputs.endpoint_url }}"
203+
bucket="s3://${{ steps.r2.outputs.bucket_name }}"
160204
version="${{ steps.release.outputs.release_version }}"
161205
162206
aws s3 cp ./dist/release/noderax-agent-linux-amd64 "${bucket}/noderax-agent/releases/${version}/noderax-agent-linux-amd64" \

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,17 @@ Required GitHub secrets:
7171
- `R2_SECRET_ACCESS_KEY`
7272
- `R2_BUCKET`
7373

74+
`R2_BUCKET` plain bucket name olmalı. URL veya custom domain verme.
75+
76+
Doğru örnek:
77+
78+
- `R2_BUCKET=noderax-assets`
79+
80+
Yanlış örnekler:
81+
82+
- `R2_BUCKET=https://cdn.noderax.net`
83+
- `R2_BUCKET=https://<accountid>.r2.cloudflarestorage.com/noderax-assets`
84+
7485
Trigger behavior:
7586

7687
- Pushes to `main` refresh `install.sh` and the `latest` binaries

0 commit comments

Comments
 (0)