Skip to content

Commit e4c28a7

Browse files
Merge pull request #4 from technote-space/fix/git_config
fix: add git config
2 parents ad8209b + 582f142 commit e4c28a7

File tree

5 files changed

+66
-5
lines changed

5 files changed

+66
-5
lines changed

__tests__/utils/misc.test.ts

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import path from 'path';
33
import nock from 'nock';
44
import tmp from 'tmp';
55
import {encodeContent} from '../util';
6-
import {isTargetEvent, parseConfig, getCommitMessage, getCloneDepth, getWorkspace, getBuildCommands, isGitCloned, getGitUrl} from '../../src/utils/misc';
7-
import {DEFAULT_COMMIT_MESSAGE, DEFAULT_CLONE_DEPTH} from '../../src/constant';
6+
import {isTargetEvent, parseConfig, getCommitMessage, getCommitName, getCommitEmail, getCloneDepth, getWorkspace, getBuildCommands, isGitCloned, getGitUrl} from '../../src/utils/misc';
7+
import {DEFAULT_COMMIT_MESSAGE, DEFAULT_COMMIT_NAME, DEFAULT_COMMIT_EMAIL, DEFAULT_CLONE_DEPTH} from '../../src/constant';
88

99
nock.disableNetConnect();
1010

@@ -110,6 +110,52 @@ describe('getCommitMessage', () => {
110110
});
111111
});
112112

113+
describe('getCommitName', () => {
114+
const OLD_ENV = process.env;
115+
116+
beforeEach(() => {
117+
jest.resetModules();
118+
process.env = {...OLD_ENV};
119+
delete process.env.NODE_ENV;
120+
});
121+
122+
afterEach(() => {
123+
process.env = OLD_ENV;
124+
});
125+
126+
it('should get commit name', () => {
127+
process.env.INPUT_COMMIT_NAME = 'test';
128+
expect(getCommitName()).toBe('test');
129+
});
130+
131+
it('should get commit default name', () => {
132+
expect(getCommitName()).toBe(DEFAULT_COMMIT_NAME);
133+
});
134+
});
135+
136+
describe('getCommitEmail', () => {
137+
const OLD_ENV = process.env;
138+
139+
beforeEach(() => {
140+
jest.resetModules();
141+
process.env = {...OLD_ENV};
142+
delete process.env.NODE_ENV;
143+
});
144+
145+
afterEach(() => {
146+
process.env = OLD_ENV;
147+
});
148+
149+
it('should get commit email', () => {
150+
process.env.INPUT_COMMIT_EMAIL = 'test';
151+
expect(getCommitEmail()).toBe('test');
152+
});
153+
154+
it('should get commit default email', () => {
155+
expect(getCommitEmail()).toBe(DEFAULT_COMMIT_EMAIL);
156+
});
157+
});
158+
113159
describe('getCloneDepth', () => {
114160
const OLD_ENV = process.env;
115161

action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ inputs:
1414
CLONE_DEPTH:
1515
description: Git clone depth.
1616
default: '50'
17+
COMMIT_NAME:
18+
description: Git commit name.
19+
default: 'GitHub Actions'
20+
COMMIT_EMAIL:
21+
description: Git commit email.
22+
default: '[email protected]'
1723
runs:
1824
using: node12
1925
main: lib/main.js

src/constant.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
export const DEFAULT_COMMIT_MESSAGE = 'feat: Build for release';
2+
export const DEFAULT_COMMIT_NAME = 'GitHub Actions';
3+
export const DEFAULT_COMMIT_EMAIL = '[email protected]';
24
export const DEFAULT_CLONE_DEPTH = '50';
35
export const TARGET_EVENT_NAME = 'release';
46
export const TARGET_EVENT_ACTION = 'published';

src/utils/command.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import signale from 'signale';
22
import {exec} from 'child_process';
33
import {Context} from '@actions/github/lib/context';
4-
import {isGitCloned, getGitUrl, getBuildCommands, getCloneDepth, getWorkspace, getCommitMessage} from './misc';
4+
import {isGitCloned, getGitUrl, getBuildCommands, getCloneDepth, getWorkspace, getCommitMessage, getCommitName, getCommitEmail} from './misc';
55

66
export const clone = async (context: Context) => {
77
if (isGitCloned()) return;
@@ -31,7 +31,10 @@ export const getDiffFiles = async () => {
3131
export const commit = async () => {
3232
const workspace = getWorkspace();
3333
const message = getCommitMessage();
34-
await execAsync(`git -C ${workspace} commit -m "${message}"`);
34+
const name = getCommitName();
35+
const email = getCommitEmail();
36+
37+
await execAsync(`git -C ${workspace} -c user.name="${name}" -c user.email="${email}" commit -m "${message}"`);
3538
return execAsync(`git -C ${workspace} rev-parse HEAD`);
3639
};
3740

src/utils/misc.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import path from 'path';
33
import yaml from 'js-yaml';
44
import {getInput} from '@actions/core' ;
55
import {Context} from '@actions/github/lib/context';
6-
import {TARGET_EVENT_NAME, TARGET_EVENT_ACTION, DEFAULT_COMMIT_MESSAGE, DEFAULT_CLONE_DEPTH} from '../constant';
6+
import {TARGET_EVENT_NAME, TARGET_EVENT_ACTION, DEFAULT_COMMIT_MESSAGE, DEFAULT_CLONE_DEPTH, DEFAULT_COMMIT_NAME, DEFAULT_COMMIT_EMAIL} from '../constant';
77

88
export const isTargetEvent = (context: Context) => TARGET_EVENT_NAME === context.eventName && TARGET_EVENT_ACTION === context.payload.action;
99

@@ -21,6 +21,10 @@ export const getBuildCommands = () => {
2121

2222
export const getCommitMessage = () => getInput('COMMIT_MESSAGE') || DEFAULT_COMMIT_MESSAGE;
2323

24+
export const getCommitName = () => getInput('COMMIT_NAME') || DEFAULT_COMMIT_NAME;
25+
26+
export const getCommitEmail = () => getInput('COMMIT_EMAIL') || DEFAULT_COMMIT_EMAIL;
27+
2428
export const getCloneDepth = () => getInput('CLONE_DEPTH') || DEFAULT_CLONE_DEPTH;
2529

2630
export const getWorkspace = () => process.env.GITHUB_WORKSPACE || '';

0 commit comments

Comments
 (0)