Skip to content

Commit 6bdc165

Browse files
committed
feat: add secret
1 parent e736bab commit 6bdc165

2 files changed

Lines changed: 56 additions & 42 deletions

File tree

.github/workflows/publish.yml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,15 @@ jobs:
7070
env:
7171
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7272
# OSS release channel runs fully in CI: upload + reconcile + manifest.json.
73-
# All values come from repo Settings: credentials via Secrets, the rest
74-
# via Variables. Leave the secrets unset to skip the OSS channel entirely.
73+
# All values come from repo Settings → Secrets — no OSS defaults live in
74+
# code. Leave AK/SK unset to skip the OSS channel; once enabled,
75+
# bucket/region/prefix are required.
7576
BAILIAN_OSS_AK: ${{ secrets.BAILIAN_OSS_AK }}
7677
BAILIAN_OSS_SK: ${{ secrets.BAILIAN_OSS_SK }}
77-
BAILIAN_OSS_BUCKET: ${{ vars.BAILIAN_OSS_BUCKET }}
78-
BAILIAN_OSS_REGION: ${{ vars.BAILIAN_OSS_REGION }}
79-
BAILIAN_OSS_ENDPOINT: ${{ vars.BAILIAN_OSS_ENDPOINT }}
80-
BAILIAN_RELEASE_PREFIX: ${{ vars.BAILIAN_RELEASE_PREFIX }}
78+
BAILIAN_OSS_BUCKET: ${{ secrets.BAILIAN_OSS_BUCKET }}
79+
BAILIAN_OSS_REGION: ${{ secrets.BAILIAN_OSS_REGION }}
80+
BAILIAN_OSS_ENDPOINT: ${{ secrets.BAILIAN_OSS_ENDPOINT }}
81+
BAILIAN_RELEASE_PREFIX: ${{ secrets.BAILIAN_RELEASE_PREFIX }}
8182
run: node tools/release/publish-stable.mjs ${{ inputs.package == 'knowledge-studio-cli' && '--knowledge' || '' }}
8283

8384
publish-channel:
@@ -130,8 +131,8 @@ jobs:
130131
# OSS release channel — same Settings-injected values as stable.
131132
BAILIAN_OSS_AK: ${{ secrets.BAILIAN_OSS_AK }}
132133
BAILIAN_OSS_SK: ${{ secrets.BAILIAN_OSS_SK }}
133-
BAILIAN_OSS_BUCKET: ${{ vars.BAILIAN_OSS_BUCKET }}
134-
BAILIAN_OSS_REGION: ${{ vars.BAILIAN_OSS_REGION }}
135-
BAILIAN_OSS_ENDPOINT: ${{ vars.BAILIAN_OSS_ENDPOINT }}
136-
BAILIAN_RELEASE_PREFIX: ${{ vars.BAILIAN_RELEASE_PREFIX }}
134+
BAILIAN_OSS_BUCKET: ${{ secrets.BAILIAN_OSS_BUCKET }}
135+
BAILIAN_OSS_REGION: ${{ secrets.BAILIAN_OSS_REGION }}
136+
BAILIAN_OSS_ENDPOINT: ${{ secrets.BAILIAN_OSS_ENDPOINT }}
137+
BAILIAN_RELEASE_PREFIX: ${{ secrets.BAILIAN_RELEASE_PREFIX }}
137138
run: node tools/release/publish-channel.mjs ${{ inputs.package == 'knowledge-studio-cli' && '--knowledge' || '' }} --channel "${{ inputs.channel }}"

tools/release/lib/oss-direct-upload.mjs

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,47 @@
2020
* - Once enabled, any upload/reconcile/manifest failure THROWS and fails the
2121
* release step — re-running the workflow is idempotent (uploads overwrite).
2222
*
23-
* Environment variables (all injected from GitHub repo Settings Secrets for
24-
* credentials, Variables for the rest; never hardcode values in the workflow):
23+
* Environment variables (all injected from GitHub repo Settings Secrets;
24+
* no OSS defaults are hardcoded in this repo):
2525
* BAILIAN_OSS_AK / BAILIAN_OSS_SK —— RAM AccessKey; needs oss:PutObject and
26-
* oss:GetObject on `<prefix>/*`
27-
* BAILIAN_OSS_BUCKET —— target bucket, default bailian-wiki
28-
* BAILIAN_OSS_REGION —— region, default oss-cn-hangzhou
29-
* BAILIAN_OSS_ENDPOINT —— optional request endpoint override,
30-
* e.g. oss-accelerate.aliyuncs.com; public
31-
* manifest URLs always use the region endpoint
32-
* BAILIAN_RELEASE_PREFIX —— object prefix, default release
26+
* oss:GetObject on the release prefix
27+
* BAILIAN_OSS_BUCKET / BAILIAN_OSS_REGION / BAILIAN_RELEASE_PREFIX
28+
* —— required once the channel is enabled
29+
* BAILIAN_OSS_ENDPOINT —— optional request endpoint override;
30+
* public manifest URLs always use the
31+
* region endpoint
3332
*/
3433
import { createHash, createHmac } from "node:crypto";
3534
import { readFileSync, statSync } from "node:fs";
3635
import { basename } from "node:path";
3736

38-
const OSS_CONFIG = {
39-
bucket: process.env.BAILIAN_OSS_BUCKET || "bailian-wiki",
40-
region: process.env.BAILIAN_OSS_REGION || "oss-cn-hangzhou",
41-
endpoint: process.env.BAILIAN_OSS_ENDPOINT || "",
42-
prefix: process.env.BAILIAN_RELEASE_PREFIX || "release",
43-
};
44-
45-
function ossCredentials() {
37+
/**
38+
* Resolve the OSS context from the environment. Returns null when the channel
39+
* is disabled (no credentials). Throws when credentials are present but the
40+
* non-credential configuration is incomplete — a misconfigured release must
41+
* fail loudly instead of uploading to a guessed location.
42+
*/
43+
function ossContext() {
4644
const ak = process.env.BAILIAN_OSS_AK?.trim();
4745
const sk = process.env.BAILIAN_OSS_SK?.trim();
48-
return ak && sk ? { ak, sk } : null;
46+
if (!ak || !sk) return null;
47+
const cfg = {
48+
bucket: process.env.BAILIAN_OSS_BUCKET?.trim() || "",
49+
region: process.env.BAILIAN_OSS_REGION?.trim() || "",
50+
endpoint: process.env.BAILIAN_OSS_ENDPOINT?.trim() || "",
51+
prefix: process.env.BAILIAN_RELEASE_PREFIX?.trim() || "",
52+
};
53+
const missing = [
54+
["BAILIAN_OSS_BUCKET", cfg.bucket],
55+
["BAILIAN_OSS_REGION", cfg.region],
56+
["BAILIAN_RELEASE_PREFIX", cfg.prefix],
57+
]
58+
.filter(([, value]) => !value)
59+
.map(([name]) => name);
60+
if (missing.length > 0) {
61+
throw new Error(`OSS channel misconfigured; missing env: ${missing.join(", ")}`);
62+
}
63+
return { creds: { ak, sk }, cfg };
4964
}
5065

5166
/** Virtual-hosted-style request host: <bucket>.<endpoint-or-region>. */
@@ -186,20 +201,19 @@ async function getObjectJson(key, creds, cfg) {
186201
* @returns {Promise<{ uploaded: number, skipped: boolean }>}
187202
*/
188203
export async function mirrorReleaseAssetsToOss({ plans, dryRun = false }) {
189-
const creds = ossCredentials();
190-
const cfg = OSS_CONFIG;
191-
192-
const jobs = plans.flatMap(({ tag, paths }) =>
193-
paths.map((path) => ({ path, key: `${cfg.prefix}/${tag}/${basename(path)}` })),
194-
);
195-
if (jobs.length === 0) return { uploaded: 0, skipped: true };
196-
197-
if (!creds) {
204+
const ctx = ossContext();
205+
if (!ctx) {
198206
process.stdout.write(
199207
"\n[warn] BAILIAN_OSS_AK/SK unset; skip the OSS release channel entirely\n",
200208
);
201209
return { uploaded: 0, skipped: true };
202210
}
211+
const { creds, cfg } = ctx;
212+
213+
const jobs = plans.flatMap(({ tag, paths }) =>
214+
paths.map((path) => ({ path, key: `${cfg.prefix}/${tag}/${basename(path)}` })),
215+
);
216+
if (jobs.length === 0) return { uploaded: 0, skipped: true };
203217

204218
process.stdout.write(
205219
`\n==> OSS upload: ${jobs.length} object(s) → ${cfg.bucket} (${cfg.endpoint || cfg.region})\n`,
@@ -267,14 +281,13 @@ export async function mirrorReleaseAssetsToOss({ plans, dryRun = false }) {
267281
* @returns {Promise<{ updated: boolean, latest: string | null }>}
268282
*/
269283
export async function maintainReleaseManifest({ tag, assetNames, dryRun = false }) {
270-
const creds = ossCredentials();
271-
const cfg = OSS_CONFIG;
272-
const key = `${cfg.prefix}/manifest.json`;
273-
274-
if (!creds) {
284+
const ctx = ossContext();
285+
if (!ctx) {
275286
process.stdout.write("[info] BAILIAN_OSS_AK/SK unset; skip manifest.json maintenance\n");
276287
return { updated: false, latest: null };
277288
}
289+
const { creds, cfg } = ctx;
290+
const key = `${cfg.prefix}/manifest.json`;
278291

279292
if (dryRun) {
280293
process.stdout.write(

0 commit comments

Comments
 (0)