Files
Ncurator/scripts/release-environment.mjs
T
Yoan Huang c40a7d1ea0 Refactor test documentation and improve testing structure
- Updated the test documentation in `doc/test.md` to clarify the purpose and structure of regression and unit tests, including changes to execution summaries and test file organization.
- Modified ESLint configuration in `eslint.config.mjs` to exclude specific directories and adjust rules for `.mjs` files.
- Removed unnecessary ESLint disable comments from various script files to enforce cleaner code practices.
- Introduced a new test case for image analysis in `tests/case/ai/tool/utility/image-analyze-contract.test.ts` to validate the behavior of the image recognition tool.
- Enhanced existing unit tests in `tests/case/unit/webCrawler/web-search-sidecar-retry.test.ts` and `tests/case/unit/workbench/assistant-markdown-memo.test.ts` for better reliability and clarity.
2026-07-18 13:54:43 +08:00

53 lines
1.8 KiB
JavaScript

import { access, readFile } from 'node:fs/promises'
import os from 'node:os'
import path from 'node:path'
import process from 'node:process'
export const loadReleaseEnvironment = async (root) => {
const filePath = path.join(root, '.env')
const content = await readFile(filePath, 'utf8').catch((error) => {
if (error?.code === 'ENOENT') return ''
throw error
})
for (const rawLine of content.split(/\r?\n/u)) {
const line = rawLine.trim()
if (!line || line.startsWith('#')) continue
const separator = line.indexOf('=')
if (separator < 1) throw new Error(`invalid release environment line: ${rawLine}`)
const name = line.slice(0, separator).trim()
let value = line.slice(separator + 1).trim()
if (
(value.startsWith('"') && value.endsWith('"')) ||
(value.startsWith("'") && value.endsWith("'"))
) {
value = value.slice(1, -1)
}
if (!process.env[name]) process.env[name] = value
}
if (!process.env.AWS_ACCESS_KEY_ID && process.env.R2_ACCESS_KEY_ID) {
process.env.AWS_ACCESS_KEY_ID = process.env.R2_ACCESS_KEY_ID
}
if (!process.env.AWS_SECRET_ACCESS_KEY && process.env.R2_SECRET_ACCESS_KEY) {
process.env.AWS_SECRET_ACCESS_KEY = process.env.R2_SECRET_ACCESS_KEY
}
if (process.platform === 'win32' && !process.env.NCURATOR_AWS_CLI) {
const candidates = [
process.env.ProgramFiles
? path.join(process.env.ProgramFiles, 'Amazon', 'AWSCLIV2', 'aws.exe')
: '',
path.join(os.homedir(), '.ncurator', 'release-tools', 'awscli', 'aws.exe')
].filter(Boolean)
for (const candidate of candidates) {
const exists = await access(candidate)
.then(() => true)
.catch(() => false)
if (exists) {
process.env.NCURATOR_AWS_CLI = candidate
break
}
}
}
}