Skip to content

Commit

Permalink
cli: Add skip_bump_version to github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
aXenDeveloper committed Oct 19, 2024
1 parent 44e206f commit bb2274f
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 79 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ on:
- patch
- minor
- major
skip_bump_version:
description: 'Skip bumping version in package.json and release notes?'
required: false
type: boolean

jobs:
bump-version:
Expand Down Expand Up @@ -53,13 +57,23 @@ jobs:
run: pnpm run build --filter=vitnode-backend --filter=vitnode-frontend --filter=vitnode-backend-email-resend --filter=vitnode-backend-email-smtp --filter=vitnode-backend-ai-google --filter=vitnode-backend-ai-open-ai

- name: Run script to bump version
if: github.event.inputs.skip_bump_version == false
run: pnpm run release
id: version-bump
env:
VERSION_TYPE: ${{ github.event.inputs.type }}
RELEASE_TYPE: ${{ github.event.inputs.release }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Run script to bump version
if: github.event.inputs.skip_bump_version == true
run: pnpm run release --without-bump-version
id: version-bump-without-bump-version
env:
VERSION_TYPE: ${{ github.event.inputs.type }}
RELEASE_TYPE: ${{ github.event.inputs.release }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Create Pre-release
if: github.event.inputs.release == 'canary' || github.event.inputs.release == 'release-candidate'
run: gh release create ${{ steps.version-bump.outputs.newTag }} --generate-notes --prerelease
Expand Down
162 changes: 83 additions & 79 deletions bump-version.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const ALLOWED_VERSION_TYPES = ['major', 'minor', 'patch'];
const GIT_USER_NAME = process.env.GITHUB_USER || 'Automated Version Bump';
const GIT_USER_EMAIL =
process.env.GITHUB_EMAIL || 'gh-action-bump-version@users.noreply.github.com';
const WORKSPACE = process.env.GITHUB_WORKSPACE;
const WORKSPACE = process.env.GITHUB_WORKSPACE || process.cwd();
const EVENT_PATH = process.env.GITHUB_EVENT_PATH;
const VERSION_TYPE = process.env.VERSION_TYPE;
const RELEASE_TYPE = process.env.RELEASE_TYPE;
Expand Down Expand Up @@ -115,12 +115,90 @@ function logError(error) {
}

(async () => {
try {
if (!WORKSPACE) {
exitFailure('GITHUB_WORKSPACE is not defined.');
return;
if (!WORKSPACE) {
exitFailure('GITHUB_WORKSPACE is not defined.');
return;
}

if (process.argv[2] === '--without-bump-version') {
// Copy frontend files from app dir
const frontendPackagePath = path.join(
WORKSPACE,
'packages',
'frontend',
'folders_to_copy',
);
const frontendAppPath = path.join(WORKSPACE, 'apps', 'frontend');
const pathsToFoldersForce = [
join('src', 'app', '[locale]', 'admin', '(vitnode)'),
join('src', 'app', '[locale]', 'admin', '(auth)', '(vitnode)'),
join('src', 'app', '[locale]', '(main)', '(layout)', '(vitnode)'),
];
const pathsToFiles = [
{
folder: join('src', 'app'),
file: 'not-found.tsx',
},
{
folder: join('src', 'plugins', 'core', 'langs'),
file: 'en.json',
},
{
folder: join('src', 'plugins', 'admin', 'langs'),
file: 'en.json',
},
];

// Create folder for apps in frontend package
if (!fs.existsSync(frontendPackagePath)) {
fs.mkdirSync(frontendPackagePath, { recursive: true });
}

// Copy folders
pathsToFoldersForce.forEach(folder => {
const appPath = join(frontendAppPath, folder);
const packagePath = join(frontendPackagePath, folder);
if (!fs.existsSync(packagePath)) {
fs.mkdirSync(packagePath, { recursive: true });
}

fs.cpSync(appPath, packagePath, { recursive: true });
});

// Copy files
pathsToFiles.forEach(file => {
const appPath = join(frontendAppPath, file.folder, file.file);
const packagePath = join(frontendPackagePath, file.folder, file.file);

fs.cpSync(appPath, packagePath, {
recursive: true,
});
});

// Copy src in frontend to create-vitnode-app
const createVitnodeAppPath = path.join(
WORKSPACE,
'packages',
'create-vitnode-app',
'templates',
'basic',
'apps',
'frontend',
'src',
);
const frontendSrcPath = path.join(WORKSPACE, 'apps', 'frontend', 'src');
if (!fs.existsSync(createVitnodeAppPath)) {
fs.mkdirSync(createVitnodeAppPath, { recursive: true });
}

fs.cpSync(frontendSrcPath, createVitnodeAppPath, {
recursive: true,
});

return;
}

try {
// Check if packages exist
for (const pkg of packages) {
if (!existsSync(path.join(WORKSPACE, 'packages', pkg, 'package.json'))) {
Expand Down Expand Up @@ -276,80 +354,6 @@ function logError(error) {
const remoteRepo = `https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git`;
await runInWorkspace('git', ['push', remoteRepo]);

// Copy frontend files from app dir
const frontendPackagePath = path.join(
WORKSPACE,
'packages',
'frontend',
'folders_to_copy',
);
const frontendAppPath = path.join(WORKSPACE, 'apps', 'frontend');
const pathsToFoldersForce = [
join('src', 'app', '[locale]', 'admin', '(vitnode)'),
join('src', 'app', '[locale]', 'admin', '(auth)', '(vitnode)'),
join('src', 'app', '[locale]', '(main)', '(layout)', '(vitnode)'),
];
const pathsToFiles = [
{
folder: join('src', 'app'),
file: 'not-found.tsx',
},
{
folder: join('src', 'plugins', 'core', 'langs'),
file: 'en.json',
},
{
folder: join('src', 'plugins', 'admin', 'langs'),
file: 'en.json',
},
];

// Create folder for apps in frontend package
if (!fs.existsSync(frontendPackagePath)) {
fs.mkdirSync(frontendPackagePath, { recursive: true });
}

// Copy folders
pathsToFoldersForce.forEach(folder => {
const appPath = join(frontendAppPath, folder);
const packagePath = join(frontendPackagePath, folder);
if (!fs.existsSync(packagePath)) {
fs.mkdirSync(packagePath, { recursive: true });
}

fs.cpSync(appPath, packagePath, { recursive: true });
});

// Copy files
pathsToFiles.forEach(file => {
const appPath = join(frontendAppPath, file.folder, file.file);
const packagePath = join(frontendPackagePath, file.folder, file.file);

fs.cpSync(appPath, packagePath, {
recursive: true,
});
});

// Copy src in frontend to create-vitnode-app
const createVitnodeAppPath = path.join(
WORKSPACE,
'packages',
'create-vitnode-app',
'templates',
'basic',
'apps',
'frontend',
'src',
);
const frontendSrcPath = path.join(WORKSPACE, 'apps', 'frontend', 'src');
if (!fs.existsSync(createVitnodeAppPath)) {
fs.mkdirSync(createVitnodeAppPath, { recursive: true });
}

fs.cpSync(frontendSrcPath, createVitnodeAppPath, {
recursive: true,
});

exitSuccess('Version bumped!');
} catch (e) {
logError(e);
Expand Down

0 comments on commit bb2274f

Please sign in to comment.