Skip to content

Commit 5ef496c

Browse files
authored
Merge pull request #12 from taj54/feature/refactor-git-operations
Feature/refactor git operations
2 parents b886b98 + 4b497eb commit 5ef496c

4 files changed

Lines changed: 36 additions & 16 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes for each version of the Ambient Music extension.
44

55
---
66

7+
## v0.7.1 2025 08 24
8+
9+
- refactor: Extract Git operations into a separate utility
10+
711
## v0.7.0 2025 08 24
812

913
- fix: Update version badges in README for consistency.

src/index.ts

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import * as core from '@actions/core';
2-
import * as exec from '@actions/exec';
3-
import { detectPlatform, updateVersion } from './utils';
2+
import {
3+
detectPlatform,
4+
updateVersion,
5+
configureGitUser,
6+
commitChanges,
7+
createAndPushTag,
8+
} from './utils';
49
import semver from 'semver';
510

611
async function run() {
@@ -14,20 +19,9 @@ async function run() {
1419
core.setOutput('new_version', version);
1520

1621
// Git Commit & Tag
17-
await exec.exec('git', ['config', 'user.name', 'github-actions[bot]']);
18-
await exec.exec('git', [
19-
'config',
20-
'user.email',
21-
'github-actions[bot]@users.noreply.github.com',
22-
]);
23-
24-
await exec.exec('git', ['add', '-A']);
25-
await exec.exec('git', ['diff-index', '--quiet', 'HEAD']).catch(async () => {
26-
await exec.exec('git', ['commit', '-m', `chore: bump version to ${version}`]);
27-
});
28-
29-
await exec.exec('git', ['tag', `v${version}`]);
30-
await exec.exec('git', ['push', 'origin', 'HEAD', '--tags']);
22+
await configureGitUser();
23+
await commitChanges(`chore: bump version to ${version}`);
24+
await createAndPushTag(version);
3125
} catch (error: unknown) {
3226
if (error instanceof Error) {
3327
core.setFailed(error.message);

src/utils/git.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import * as exec from '@actions/exec';
2+
3+
export async function configureGitUser() {
4+
await exec.exec('git', ['config', 'user.name', 'github-actions[bot]']);
5+
await exec.exec('git', ['config', 'user.email', 'github-actions[bot]@users.noreply.github.com']);
6+
}
7+
8+
export async function commitChanges(message: string) {
9+
await exec.exec('git', ['add', '-A']);
10+
try {
11+
await exec.exec('git', ['diff-index', '--quiet', 'HEAD']);
12+
} catch (error) {
13+
// Only commit if there are changes
14+
await exec.exec('git', ['commit', '-m', message]);
15+
}
16+
}
17+
18+
export async function createAndPushTag(version: string) {
19+
await exec.exec('git', ['tag', `v${version}`]);
20+
await exec.exec('git', ['push', 'origin', 'HEAD', '--tags']);
21+
}

src/utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './updaterUtil';
2+
export * from './git';

0 commit comments

Comments
 (0)