fix(mod_commit): Stage and commit deno.json when bumping/syncing versions and create/update git tags
This commit is contained in:
		| @@ -90,12 +90,16 @@ function calculateNewVersion(currentVersion: string, versionType: VersionType): | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * Bumps the version in deno.json | ||||
|  * Bumps the version in deno.json, commits the change, and creates a tag | ||||
|  * @param versionType Type of version bump | ||||
|  * @returns The new version string | ||||
|  */ | ||||
| export async function bumpDenoVersion(versionType: VersionType): Promise<string> { | ||||
|   const denoJsonPath = plugins.path.join(paths.cwd, 'deno.json'); | ||||
|   const smartshellInstance = new plugins.smartshell.Smartshell({ | ||||
|     executor: 'bash', | ||||
|     sourceFilePaths: [], | ||||
|   }); | ||||
|  | ||||
|   try { | ||||
|     // Read deno.json | ||||
| @@ -121,6 +125,17 @@ export async function bumpDenoVersion(versionType: VersionType): Promise<string> | ||||
|       denoJsonPath | ||||
|     ); | ||||
|  | ||||
|     // Stage the deno.json file | ||||
|     await smartshellInstance.exec('git add deno.json'); | ||||
|  | ||||
|     // Commit the version bump | ||||
|     await smartshellInstance.exec(`git commit -m "v${newVersion}"`); | ||||
|  | ||||
|     // Create the version tag | ||||
|     await smartshellInstance.exec(`git tag v${newVersion} -m "v${newVersion}"`); | ||||
|  | ||||
|     logger.log('info', `Created commit and tag v${newVersion}`); | ||||
|  | ||||
|     return newVersion; | ||||
|   } catch (error) { | ||||
|     throw new Error(`Failed to bump deno.json version: ${error.message}`); | ||||
| @@ -147,11 +162,15 @@ async function bumpNpmVersion(versionType: VersionType): Promise<string> { | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * Syncs the version from package.json to deno.json | ||||
|  * Syncs the version from package.json to deno.json and amends the npm commit | ||||
|  * @param version The version to sync | ||||
|  */ | ||||
| async function syncVersionToDenoJson(version: string): Promise<void> { | ||||
|   const denoJsonPath = plugins.path.join(paths.cwd, 'deno.json'); | ||||
|   const smartshellInstance = new plugins.smartshell.Smartshell({ | ||||
|     executor: 'bash', | ||||
|     sourceFilePaths: [], | ||||
|   }); | ||||
|  | ||||
|   try { | ||||
|     const denoConfig = plugins.smartfile.fs.toObjectSync( | ||||
| @@ -165,6 +184,17 @@ async function syncVersionToDenoJson(version: string): Promise<void> { | ||||
|       JSON.stringify(denoConfig, null, 2) + '\n', | ||||
|       denoJsonPath | ||||
|     ); | ||||
|  | ||||
|     // Stage the deno.json file | ||||
|     await smartshellInstance.exec('git add deno.json'); | ||||
|  | ||||
|     // Amend the npm version commit to include deno.json | ||||
|     await smartshellInstance.exec('git commit --amend --no-edit'); | ||||
|  | ||||
|     // Re-create the tag with force to update it | ||||
|     await smartshellInstance.exec(`git tag -fa v${version} -m "v${version}"`); | ||||
|  | ||||
|     logger.log('info', `Amended commit to include deno.json and updated tag v${version}`); | ||||
|   } catch (error) { | ||||
|     throw new Error(`Failed to sync version to deno.json: ${error.message}`); | ||||
|   } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user