Skip to content

Commit a620ee7

Browse files
Merge pull request #215 from technote-space/release/v0.8.5
Release/v0.8.5
2 parents 8a74ad3 + af92f08 commit a620ee7

File tree

9 files changed

+198
-109
lines changed

9 files changed

+198
-109
lines changed

README.ja.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010

1111
GitHub Actions 用のヘルパー
1212

13+
## Table of Contents
14+
1315
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
1416
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
15-
**Table of Contents**
17+
<details>
18+
<summary>Details</summary>
1619

1720
- [使用方法](#%E4%BD%BF%E7%94%A8%E6%96%B9%E6%B3%95)
1821
- [Logger](#logger)
@@ -23,6 +26,7 @@ GitHub Actions 用のヘルパー
2326
- [ContextHelper](#contexthelper)
2427
- [Author](#author)
2528

29+
</details>
2630
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
2731

2832
## 使用方法

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010

1111
Helper for GitHub Actions.
1212

13+
## Table of Contents
14+
1315
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
1416
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
15-
**Table of Contents**
17+
<details>
18+
<summary>Details</summary>
1619

1720
- [Usage](#usage)
1821
- [Logger](#logger)
@@ -23,6 +26,7 @@ Helper for GitHub Actions.
2326
- [ContextHelper](#contexthelper)
2427
- [Author](#author)
2528

29+
</details>
2630
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
2731

2832
## Usage

__tests__/git-helper.test.ts

Lines changed: 53 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ describe('GitHelper', () => {
7070
]);
7171
});
7272

73-
it('should run git checkout', async() => {
73+
it('should run git clone PR', async() => {
7474
setExists(false);
7575
const mockExec = spyOnExec();
7676

77-
expect(await helper.clone(workDir, context({
77+
await helper.clone(workDir, context({
7878
ref: 'refs/pull/123/merge',
79-
})));
79+
}));
8080

8181
execCalledWith(mockExec, [
8282
'git clone \'--depth=3\' \'https://octocat:[email protected]/hello/world.git\' \'.\' > /dev/null 2>&1 || :',
@@ -85,48 +85,64 @@ describe('GitHelper', () => {
8585
]);
8686
});
8787

88-
it('should throw error', async() => {
88+
it('should run checkout', async() => {
8989
setExists(false);
90+
const mockExec = spyOnExec();
91+
92+
await helper.clone(workDir, context({
93+
ref: 'refs/tags/v1.2.3',
94+
sha: '1234567890',
95+
}));
9096

91-
await expect(helper.clone(workDir, context({
92-
ref: '',
93-
sha: '',
94-
}))).rejects.toThrow('Invalid context.');
97+
execCalledWith(mockExec, [
98+
'git init \'.\'',
99+
'git remote add origin \'https://octocat:[email protected]/hello/world.git\' > /dev/null 2>&1 || :',
100+
'git fetch --no-tags origin \'refs/tags/v1.2.3:refs/tags/v1.2.3\' || :',
101+
'git checkout -qf 1234567890',
102+
]);
95103
});
96104
});
97105

98106
describe('checkout', () => {
99-
it('should run checkout 1', async() => {
107+
it('should run checkout branch', async() => {
100108
const mockExec = spyOnExec();
101109

102110
await helper.checkout(workDir, context());
103111

104112
execCalledWith(mockExec, [
105-
'git clone \'--depth=3\' \'https://octocat:[email protected]/hello/world.git\' \'.\' > /dev/null 2>&1',
106-
'git fetch \'https://octocat:[email protected]/hello/world.git\' refs/heads/test-ref > /dev/null 2>&1',
113+
'rm -rdf \'.work\'',
114+
'git init \'.\'',
115+
'git remote add origin \'https://octocat:[email protected]/hello/world.git\' > /dev/null 2>&1 || :',
116+
'git fetch --no-tags origin \'refs/heads/test-ref:refs/remotes/origin/test-ref\' || :',
107117
'git checkout -qf test-sha',
108118
]);
109119
});
110120

111-
it('should run checkout 2', async() => {
121+
it('should run checkout merge ref', async() => {
112122
const mockExec = spyOnExec();
113123

114-
await helper.checkout(workDir, context({sha: ''}));
124+
await helper.checkout(workDir, context({ref: 'refs/pull/123/merge'}));
115125

116126
execCalledWith(mockExec, [
117-
'git clone \'https://octocat:[email protected]/hello/world.git\' \'.\' > /dev/null 2>&1',
118-
'git checkout -qf test-ref',
127+
'rm -rdf \'.work\'',
128+
'git init \'.\'',
129+
'git remote add origin \'https://octocat:[email protected]/hello/world.git\' > /dev/null 2>&1 || :',
130+
'git fetch --no-tags origin \'refs/pull/123/merge:refs/pull/123/merge\' || :',
131+
'git checkout -qf test-sha',
119132
]);
120133
});
121134

122-
it('should run checkout 3', async() => {
135+
it('should run checkout tag', async() => {
123136
const mockExec = spyOnExec();
124137

125-
await helper.checkout(workDir, context({sha: '', ref: 'refs/tags/test-tag'}));
138+
await helper.checkout(workDir, context({ref: 'refs/tags/v1.2.3'}));
126139

127140
execCalledWith(mockExec, [
128-
'git clone \'https://octocat:[email protected]/hello/world.git\' \'.\' > /dev/null 2>&1',
129-
'git checkout -qf refs/tags/test-tag',
141+
'rm -rdf \'.work\'',
142+
'git init \'.\'',
143+
'git remote add origin \'https://octocat:[email protected]/hello/world.git\' > /dev/null 2>&1 || :',
144+
'git fetch --no-tags origin \'refs/tags/v1.2.3:refs/tags/v1.2.3\' || :',
145+
'git checkout -qf test-sha',
130146
]);
131147
});
132148
});
@@ -451,6 +467,24 @@ describe('GitHelper', () => {
451467
'git show \'--stat-count=10\' HEAD',
452468
]);
453469
});
470+
471+
it('should run git commit with options', async() => {
472+
setChildProcessParams({stdout: 'M file1\n\nM file2\n'});
473+
const mockExec = spyOnExec();
474+
475+
expect(await helper.commit(workDir, 'test', {
476+
count: 20,
477+
allowEmpty: true,
478+
args: ['--dry-run'],
479+
})).toBeTruthy();
480+
481+
execCalledWith(mockExec, [
482+
'git add --all',
483+
'git status --short -uno',
484+
'git commit --allow-empty --dry-run -qm test',
485+
'git show \'--stat-count=20\' HEAD',
486+
]);
487+
});
454488
});
455489

456490
describe('fetchTags', () => {

__tests__/utils.test.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Utils } from '../src';
66
const {getWorkspace, getActor, escapeRegExp, getRegExp, getPrefixRegExp, getSuffixRegExp, useNpm, versionCompare, getOctokit} = Utils;
77
const {isSemanticVersioningTagName, isPrRef, getPrMergeRef, getBoolValue, replaceAll, getPrHeadRef, arrayChunk, sleep} = Utils;
88
const {getBranch, getRefForUpdate, uniqueArray, getBuildInfo, split, getArrayInput, generateNewPatchVersion, getPrBranch} = Utils;
9+
const {isBranch, isTagRef, normalizeRef, trimRef, getTag, getRefspec} = Utils;
910

1011
jest.useFakeTimers();
1112

@@ -482,3 +483,63 @@ describe('getOctokit', () => {
482483
expect(() => getOctokit()).toThrow();
483484
});
484485
});
486+
487+
describe('isBranch', () => {
488+
it('should return true', () => {
489+
expect(isBranch('refs/heads/master')).toBe(true);
490+
expect(isBranch('heads/master')).toBe(true);
491+
});
492+
493+
it('should return false', () => {
494+
expect(isBranch('test')).toBe(false);
495+
expect(isBranch('heads')).toBe(false);
496+
});
497+
});
498+
499+
describe('isTagRef', () => {
500+
it('should return true', () => {
501+
expect(isTagRef('refs/tags/v1.2.3')).toBe(true);
502+
});
503+
504+
it('should return false', () => {
505+
expect(isTagRef('refs/heads/master')).toBe(false);
506+
expect(isTagRef('heads/master')).toBe(false);
507+
});
508+
});
509+
510+
describe('normalizeRef', () => {
511+
it('should normalize ref', () => {
512+
expect(normalizeRef('master')).toBe('refs/heads/master');
513+
expect(normalizeRef('refs/heads/master')).toBe('refs/heads/master');
514+
expect(normalizeRef('refs/tags/v1.2.3')).toBe('refs/tags/v1.2.3');
515+
expect(normalizeRef('refs/pull/123/merge')).toBe('refs/pull/123/merge');
516+
});
517+
});
518+
519+
describe('trimRef', () => {
520+
it('should trim ref', () => {
521+
expect(trimRef('master')).toBe('master');
522+
expect(trimRef('refs/heads/master')).toBe('master');
523+
expect(trimRef('refs/tags/v1.2.3')).toBe('v1.2.3');
524+
expect(trimRef('refs/pull/123/merge')).toBe('123/merge');
525+
});
526+
});
527+
528+
describe('getTag', () => {
529+
it('should get tag', () => {
530+
expect(getTag('master')).toBe('');
531+
expect(getTag('heads/master')).toBe('');
532+
expect(getTag('refs/heads/master')).toBe('');
533+
expect(getTag('refs/tags/v1.2.3')).toBe('v1.2.3');
534+
expect(getTag('refs/pull/123/merge')).toBe('');
535+
});
536+
});
537+
538+
describe('getRefspec', () => {
539+
it('should get refspec', () => {
540+
expect(getRefspec('master')).toBe('refs/heads/master:refs/remotes/origin/master');
541+
expect(getRefspec('refs/heads/master', 'test')).toBe('refs/heads/master:refs/remotes/test/master');
542+
expect(getRefspec('refs/tags/v1.2.3')).toBe('refs/tags/v1.2.3:refs/tags/v1.2.3');
543+
expect(getRefspec('refs/pull/123/merge')).toBe('refs/pull/123/merge:refs/pull/123/merge');
544+
});
545+
});

jest.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
module.exports = {
22
clearMocks: true,
3-
moduleFileExtensions: [ 'js', 'ts' ],
4-
setupFiles: [ '<rootDir>/jest.setup.ts' ],
3+
moduleFileExtensions: ['js', 'ts'],
4+
setupFiles: ['<rootDir>/jest.setup.ts'],
55
testEnvironment: 'node',
6-
testMatch: [ '**/*.test.ts' ],
6+
testMatch: ['**/*.test.ts'],
77
testRunner: 'jest-circus/runner',
88
transform: {
99
'^.+\\.ts$': 'ts-jest',

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@technote-space/github-action-helper",
3-
"version": "0.8.4",
3+
"version": "0.8.5",
44
"description": "Helper to filter GitHub Action.",
55
"author": {
66
"name": "Technote",
@@ -32,7 +32,7 @@
3232
"sprintf-js": "^1.1.2"
3333
},
3434
"devDependencies": {
35-
"@technote-space/github-action-test-helper": "^0.1.5",
35+
"@technote-space/github-action-test-helper": "^0.2.0",
3636
"@types/jest": "^25.1.1",
3737
"@types/node": "^13.7.0",
3838
"@typescript-eslint/eslint-plugin": "^2.19.0",

0 commit comments

Comments
 (0)