Skip to content

Commit e131859

Browse files
committed
Enhance smoke-test-release validation and cleanup
Make the smoke-test-release script more robust and safer: import execFileSync and use it to list tarball entries, add a missing generated C++ header to required entries, and use PKG.name for subpaths. Change failure handling to throw/catch errors and set process.exitCode instead of exiting immediately, move sandbox removal into a finally block (declare sandbox in outer scope), and ensure the tarball and sandbox are always cleaned up. These changes improve error reporting and guarantee cleanup on failure.
1 parent fa0a129 commit e131859

1 file changed

Lines changed: 25 additions & 12 deletions

File tree

scripts/smoke-test-release.js

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* Designed to run inside `release-it`'s `before:init` hook so a broken
1818
* release is caught before the npm publish + git push.
1919
*/
20-
const { execSync } = require('node:child_process')
20+
const { execFileSync, execSync } = require('node:child_process')
2121
const fs = require('node:fs')
2222
const os = require('node:os')
2323
const path = require('node:path')
@@ -28,6 +28,7 @@ const PKG = require(path.join(ROOT, 'package.json'))
2828
const REQUIRED_TARBALL_ENTRIES = [
2929
'package/nitrogen/generated/ios/SensitiveInfo+autolinking.rb',
3030
'package/nitrogen/generated/android/SensitiveInfo+autolinking.gradle',
31+
'package/nitrogen/generated/shared/c++/HybridSensitiveInfoSpec.hpp',
3132
'package/hooks/package.json',
3233
'package/errors/package.json',
3334
'package/lib/commonjs/index.js',
@@ -39,10 +40,10 @@ const REQUIRED_TARBALL_ENTRIES = [
3940
]
4041

4142
const SUBPATHS = [
42-
'react-native-sensitive-info',
43-
'react-native-sensitive-info/hooks',
44-
'react-native-sensitive-info/errors',
45-
'react-native-sensitive-info/package.json',
43+
PKG.name,
44+
`${PKG.name}/hooks`,
45+
`${PKG.name}/errors`,
46+
`${PKG.name}/package.json`,
4647
]
4748

4849
const PROXY_DIRS = ['hooks', 'errors']
@@ -53,8 +54,7 @@ const run = (cmd, opts = {}) =>
5354
.trim()
5455

5556
const fail = (msg) => {
56-
console.error(`\n[smoke-test-release] ❌ ${msg}\n`)
57-
process.exit(1)
57+
throw new Error(msg)
5858
}
5959

6060
const log = (msg) => console.log(`[smoke-test-release] ${msg}`)
@@ -63,10 +63,17 @@ const log = (msg) => console.log(`[smoke-test-release] ${msg}`)
6363
log('Packing tarball with `npm pack`…')
6464
const tarballName = run('npm pack --silent', { cwd: ROOT }).split('\n').pop()
6565
const tarballPath = path.join(ROOT, tarballName)
66+
let sandbox
6667

6768
try {
6869
// 2. Verify required entries are present.
69-
const entries = run(`tar -tzf ${tarballName}`, { cwd: ROOT }).split('\n')
70+
const entries = execFileSync('tar', ['-tzf', tarballName], {
71+
cwd: ROOT,
72+
stdio: ['ignore', 'pipe', 'pipe'],
73+
})
74+
.toString()
75+
.trim()
76+
.split('\n')
7077
const missing = REQUIRED_TARBALL_ENTRIES.filter((e) => !entries.includes(e))
7178
if (missing.length > 0) {
7279
fail(
@@ -78,7 +85,7 @@ try {
7885
)
7986

8087
// 3. Install the tarball into a throwaway project.
81-
const sandbox = fs.mkdtempSync(path.join(os.tmpdir(), 'rnsi-smoke-'))
88+
sandbox = fs.mkdtempSync(path.join(os.tmpdir(), 'rnsi-smoke-'))
8289
fs.writeFileSync(
8390
path.join(sandbox, 'package.json'),
8491
JSON.stringify({ name: 'rnsi-smoke', version: '0.0.0', private: true })
@@ -140,11 +147,17 @@ try {
140147
fail(`Ruby syntax check failed:\n${err.stderr?.toString() ?? err.message}`)
141148
}
142149

143-
// 7. Cleanup sandbox.
144-
fs.rmSync(sandbox, { recursive: true, force: true })
150+
// 7. Cleanup sandbox happens in `finally` below.
145151

146152
console.log('\n[smoke-test-release] ✅ Release candidate looks healthy.\n')
153+
} catch (err) {
154+
console.error(
155+
`\n[smoke-test-release] ❌ ${err instanceof Error ? err.message : err}\n`
156+
)
157+
process.exitCode = 1
147158
} finally {
148-
// Always remove the local tarball — release-it will pack again at publish time.
159+
// Always remove the sandbox + local tarball — release-it will pack again at publish time.
160+
if (sandbox && fs.existsSync(sandbox))
161+
fs.rmSync(sandbox, { recursive: true, force: true })
149162
if (fs.existsSync(tarballPath)) fs.unlinkSync(tarballPath)
150163
}

0 commit comments

Comments
 (0)