Skip to content
This repository has been archived by the owner on Aug 19, 2022. It is now read-only.

Commit

Permalink
fix release script 4
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasAribart committed Jul 29, 2022
1 parent 128b717 commit 952ab93
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release-to-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Build packages
run: yarn package
- name: Set packages versions
run: yarn set-packages-versions $RELEASE_VERSION
run: yarn set-packages-versions ${{ github.event.release.tag_name }}
- uses: JS-DevTools/npm-publish@v1
with:
token: ${{ secrets.NPM_TOKEN }}
Expand Down
27 changes: 18 additions & 9 deletions scripts/setPackagesVersions.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
import { readdirSync, readFileSync, writeFileSync } from 'fs';
import { readdirSync, readFileSync } from 'fs';
import { join } from 'path';

const newVersion = process.argv[2] as string | undefined;
const newVersionTag = process.argv[2] as string | undefined;

if (newVersion === undefined) {
console.log('newVersionTag', newVersionTag);

const semanticVersioningRegex =
/^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;

if (
newVersionTag === undefined ||
!semanticVersioningRegex.test(newVersionTag)
) {
throw new Error('Invalid version');
}

const semanticVersioningRegex =
/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
const NEW_VERSION = newVersionTag.slice(1);
console.log('NEW_VERSION', NEW_VERSION);

const VERSION_MAJOR = (newVersion.match(semanticVersioningRegex) ?? [])[1];
const VERSION_MAJOR = (newVersionTag.match(semanticVersioningRegex) ?? [])[1];
console.log('VERSION_MAJOR', VERSION_MAJOR);

type PackageJson = {
version?: string;
Expand All @@ -29,12 +38,12 @@ packagesNames.forEach(packageName => {
readFileSync(packageJsonPath).toString(),
) as PackageJson;

packageJson.version = newVersion;
packageJson.version = NEW_VERSION;

Object.keys(packageJson.dependencies ?? {}).forEach(dependencyName => {
if (dependencyName.startsWith('@castore/')) {
(packageJson.dependencies as Record<string, string>)[dependencyName] =
newVersion;
NEW_VERSION;
}
});

Expand All @@ -46,5 +55,5 @@ packagesNames.forEach(packageName => {
}
});

writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
// writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
});

0 comments on commit 952ab93

Please sign in to comment.