-
Notifications
You must be signed in to change notification settings - Fork 4
feat: add "bump packages" action #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 7 commits
ff20644
86bffc7
ed6c335
f7c043e
983f597
e8bb1bd
fbde9dd
b2baa34
96bbd4f
5244982
e9b5a47
32f35f5
70869ae
fb86730
461f159
baf20dc
17603ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| name: 'Bump All Packages' | ||
| description: 'Bumps major version for all packages in target directories using changesets' | ||
|
|
||
| inputs: | ||
| target-branch: | ||
| description: 'Branch to apply version bumps to' | ||
| required: true | ||
| target-directories: | ||
| description: 'List of directories containing packages to bump' | ||
| required: true | ||
| change-type: | ||
| description: 'Type of version bump to apply' | ||
| required: true | ||
| runs: | ||
| using: node20 | ||
| main: 'dist/index.js' | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add spaces whenever needed |
||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import { run } from './main'; | ||
|
|
||
| run(); |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,138 @@ | ||||||||||
| import * as core from '@actions/core'; | ||||||||||
| import * as exec from '@actions/exec'; | ||||||||||
| import { z } from 'zod'; | ||||||||||
| import { getArrayInput, getStringInput } from '@elementor-editor-github-actions/utils'; | ||||||||||
| import * as fs from 'fs'; | ||||||||||
| import { glob } from 'glob'; | ||||||||||
|
|
||||||||||
| const packagesDir = 'packages'; | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove, the dirs should be
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let the user define the glob |
||||||||||
| export async function run() { | ||||||||||
| try { | ||||||||||
| const inputs = parseInputs(); | ||||||||||
| const { | ||||||||||
| targetBranch, | ||||||||||
| targetDirectories, | ||||||||||
| changeType | ||||||||||
| } = inputs; | ||||||||||
|
|
||||||||||
| await core.group('Checking out target branch', async () => { | ||||||||||
| try { | ||||||||||
| await exec.exec('git', ['checkout', targetBranch]); | ||||||||||
| core.info(`Successfully checked out branch: ${targetBranch}`); | ||||||||||
| } catch (error) { | ||||||||||
| throw new Error(`Failed to checkout branch ${targetBranch}: ${error}`); | ||||||||||
| } | ||||||||||
| }); | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make sure in the workflow that it runs always on main
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why? Shouldn't it be generic? |
||||||||||
|
|
||||||||||
| await core.group('Configuring git user', async () => { | ||||||||||
| try { | ||||||||||
| await exec.exec('git', ['config', 'user.name', 'GitHub Actions']); | ||||||||||
| await exec.exec('git', ['config', 'user.email', 'github-actions@github.com']); | ||||||||||
|
|
||||||||||
| core.info('Git user configured'); | ||||||||||
| } catch (error) { | ||||||||||
| throw new Error(`Failed to configure git user: ${error}`); | ||||||||||
| } | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make sure the user config the git user before this actions. just validate it in this action |
||||||||||
| }); | ||||||||||
|
|
||||||||||
| await core.group('Bumping versions with changesets', async () => { | ||||||||||
| try { | ||||||||||
| if (targetDirectories.length > 0) { | ||||||||||
| const packageNames = []; | ||||||||||
|
|
||||||||||
| for (const dir of targetDirectories) { | ||||||||||
| try { | ||||||||||
| const packageJsonFiles = await glob(`${packagesDir}/${dir}/**/package.json`, { | ||||||||||
| ignore: ['**/node_modules/**'] | ||||||||||
| }); | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
|
||||||||||
| for (const packageJsonPath of packageJsonFiles) { | ||||||||||
| const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')); | ||||||||||
|
|
||||||||||
| packageNames.push(packageJson.name); | ||||||||||
| } | ||||||||||
| } catch (error) { | ||||||||||
| core.warning(`Error finding package.json files in ${dir}: ${error}`); | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the utils functions to warn or info
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. which utils? |
||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| if (packageNames.length > 0) { | ||||||||||
| core.info(`Found ${packageNames.length} packages to bump in target directories`); | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||||||||||
|
|
||||||||||
| const changesetId = Math.random().toString(36).substring(2, 12); | ||||||||||
| const changesetDir = '.changeset'; | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe you should use changeset cli to generate files? |
||||||||||
|
|
||||||||||
| if (!fs.existsSync(changesetDir)) { | ||||||||||
| fs.mkdirSync(changesetDir, { recursive: true }); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| const changesetContent = packageNames | ||||||||||
| .map(name => `"${name}": ${changeType}`) | ||||||||||
| .join('\n'); | ||||||||||
|
|
||||||||||
| const changesetFilePath = `${changesetDir}/${changesetId}.md`; | ||||||||||
| const fileContent = `---\n${changesetContent}\n---\n\nBump packages ${changeType} version\n`; | ||||||||||
|
|
||||||||||
| fs.writeFileSync(changesetFilePath, fileContent); | ||||||||||
| core.info(`Created changeset file: ${changesetFilePath}`); | ||||||||||
|
|
||||||||||
| core.info(`Successfully bumped versions using changesets with ${changeType} strategy`); | ||||||||||
| } else { | ||||||||||
| core.warning('No packages found in target directories'); | ||||||||||
| } | ||||||||||
| } else { | ||||||||||
| core.warning('No target directories specified'); | ||||||||||
| } | ||||||||||
| } catch (error) { | ||||||||||
| throw new Error(`Failed to bump versions with changesets: ${error}`); | ||||||||||
| } | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| await core.group('Committing version changes', async () => { | ||||||||||
| try { | ||||||||||
| await exec.exec('git', ['add', '.']); | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add only the changesets dir
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it also updates the packge jsons of the packages (and locks) |
||||||||||
| await exec.exec('git', ['commit', '-m', `chore: bump ${changeType} version using changesets`]); | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Allow configure the message |
||||||||||
|
|
||||||||||
| await exec.exec('git', ['push', 'origin', targetBranch]); | ||||||||||
|
|
||||||||||
| core.info(`Successfully committed and pushed version changes to ${targetBranch}`); | ||||||||||
| } catch (error) { | ||||||||||
| throw new Error(`Failed to commit version changes: ${error}`); | ||||||||||
| } | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| core.info(`✅ Successfully completed ${changeType} version bump process with changesets`); | ||||||||||
| } catch (error) { | ||||||||||
| if (error instanceof Error) { | ||||||||||
| core.setFailed(error.message); | ||||||||||
| } else { | ||||||||||
| core.setFailed('An unknown error occurred'); | ||||||||||
| } | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| function parseInputs() { | ||||||||||
| try { | ||||||||||
| const parsed = z.object({ | ||||||||||
| targetBranch: z.string(), | ||||||||||
| targetDirectories: z.array(z.string()), | ||||||||||
| changeType: z.enum(['major', 'minor', 'patch']), | ||||||||||
| }).parse({ | ||||||||||
| targetBranch: getStringInput('target-branch'), | ||||||||||
| targetDirectories: getArrayInput('target-directories'), | ||||||||||
| changeType: getStringInput('change-type'), | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| return parsed; | ||||||||||
| } catch (error) { | ||||||||||
| let message = 'Failed to parse inputs'; | ||||||||||
|
|
||||||||||
| if (error instanceof z.ZodError) { | ||||||||||
| message = `${message}: ${error.errors | ||||||||||
| .map((e) => `${e.path.join(', ')} - ${e.message}`) | ||||||||||
| .join('\n')}`; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| throw new Error(message); | ||||||||||
| } | ||||||||||
| } | ||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,22 @@ | ||||||
| { | ||||||
| "name": "@elementor-editor-github-actions/bump-all-packages", | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| "author": "Elementor Team", | ||||||
| "license": "GPL-3.0-or-later", | ||||||
| "private": true, | ||||||
| "scripts": { | ||||||
| "build": "tsup --config ./tsup.config.ts", | ||||||
| "dev": "npm run build -- --watch" | ||||||
| }, | ||||||
| "dependencies": { | ||||||
| "@elementor-editor-github-actions/utils": "*", | ||||||
| "@actions/core": "^1.11.1", | ||||||
| "@actions/exec": "^1.1.1", | ||||||
| "@actions/github": "^6.0.0", | ||||||
| "glob": "^10.3.10", | ||||||
| "zod": "^3.24.2" | ||||||
| }, | ||||||
| "devDependencies": { | ||||||
| "@types/semver": "^7.5.8", | ||||||
| "tsup": "^8.4.0" | ||||||
| } | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { defineConfig } from 'tsup'; | ||
|
|
||
| export default defineConfig({ | ||
| entry: ['index.ts'], | ||
| outDir: 'dist', | ||
| format: 'cjs', | ||
| noExternal: [/.+/], | ||
| platform: 'node', | ||
| minify: true, | ||
| clean: true, | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove