-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: packages validation + builds upload (#49)
Co-authored-by: Sherlo Bot <admin@sherlo.io>
- Loading branch information
Showing
19 changed files
with
199 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ jobs: | |
chore | ||
fix | ||
feat | ||
test | ||
scopes: | | ||
action | ||
cli | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
packages/cli/src/helpers/uploadOrLogBinaryReuse/uploadBuild/getSizeInMB.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import runShellCommand from '../../runShellCommand'; | ||
|
||
function getSizeInMB({ | ||
path, | ||
buffer, | ||
projectRoot, | ||
}: { | ||
path?: string; | ||
buffer?: Buffer; | ||
projectRoot: string; | ||
}): string { | ||
if (buffer) { | ||
return (buffer.length / 1024 / 1024).toFixed(2); // bytes to MB | ||
} | ||
|
||
if (path) { | ||
const duOutput = runShellCommand({ | ||
command: `du -sk "${path}"`, | ||
projectRoot, | ||
}); | ||
|
||
const [sizeInKB] = duOutput.split('\t'); | ||
return (parseInt(sizeInKB, 10) / 1024).toFixed(2); // KB to MB | ||
} | ||
|
||
throw new Error('Either path or buffer must be provided'); | ||
} | ||
|
||
export default getSizeInMB; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 41 additions & 4 deletions
45
packages/cli/src/helpers/validatePackages/getPackageVersion.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,48 @@ | ||
import { throwError } from '../../helpers'; | ||
import { readFileSync } from 'fs'; | ||
import { join, dirname } from 'path'; | ||
|
||
const PACKAGE_JSON = 'package.json'; | ||
|
||
function getPackageVersion(packageName: string): string | null { | ||
let packagePath; | ||
let packageJson; | ||
|
||
try { | ||
const pkgPath = require.resolve(`${packageName}/package.json`); | ||
packagePath = require.resolve(packageName); | ||
} catch (error) { | ||
if (error.code === 'MODULE_NOT_FOUND') { | ||
return null; | ||
} | ||
|
||
throwError({ type: 'unexpected', error }); | ||
} | ||
|
||
return require(pkgPath).version; | ||
} catch { | ||
return null; | ||
let currentDir = dirname(packagePath); | ||
while (!currentDir.endsWith('node_modules') && currentDir !== '/') { | ||
try { | ||
const currentPackageJsonPath = join(currentDir, PACKAGE_JSON); | ||
const currentPackageJson = JSON.parse(readFileSync(currentPackageJsonPath, 'utf8')); | ||
|
||
if (currentPackageJson.name === packageName) { | ||
packageJson = currentPackageJson; | ||
break; | ||
} | ||
} catch {} | ||
|
||
currentDir = dirname(currentDir); | ||
} | ||
|
||
if (!packageJson) { | ||
throwError({ | ||
type: 'unexpected', | ||
error: new Error( | ||
`Package ${packageName} was found at ${packagePath} but its ${PACKAGE_JSON} is invalid or inaccessible` | ||
), | ||
}); | ||
} | ||
|
||
return packageJson.version; | ||
} | ||
|
||
export default getPackageVersion; |
2 changes: 1 addition & 1 deletion
2
packages/react-native-storybook/android/src/main/assets/sherlo.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"version": "1.1.2"} | ||
{"version": "1.1.3-alpha.3"} |
2 changes: 1 addition & 1 deletion
2
packages/react-native-storybook/ios/Resources/assets/sherlo.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"version": "1.1.2"} | ||
{"version": "1.1.3-alpha.3"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.