Skip to content
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

Release/v0.8.5 #215

Merged
merged 10 commits into from
Feb 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@

GitHub Actions 用のヘルパー

## Table of Contents

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents**
<details>
<summary>Details</summary>

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

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

## 使用方法
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@

Helper for GitHub Actions.

## Table of Contents

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents**
<details>
<summary>Details</summary>

- [Usage](#usage)
- [Logger](#logger)
Expand All @@ -23,6 +26,7 @@ Helper for GitHub Actions.
- [ContextHelper](#contexthelper)
- [Author](#author)

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

## Usage
Expand Down
72 changes: 53 additions & 19 deletions __tests__/git-helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ describe('GitHelper', () => {
]);
});

it('should run git checkout', async() => {
it('should run git clone PR', async() => {
setExists(false);
const mockExec = spyOnExec();

expect(await helper.clone(workDir, context({
await helper.clone(workDir, context({
ref: 'refs/pull/123/merge',
})));
}));

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

it('should throw error', async() => {
it('should run checkout', async() => {
setExists(false);
const mockExec = spyOnExec();

await helper.clone(workDir, context({
ref: 'refs/tags/v1.2.3',
sha: '1234567890',
}));

await expect(helper.clone(workDir, context({
ref: '',
sha: '',
}))).rejects.toThrow('Invalid context.');
execCalledWith(mockExec, [
'git init \'.\'',
'git remote add origin \'https://octocat:[email protected]/hello/world.git\' > /dev/null 2>&1 || :',
'git fetch --no-tags origin \'refs/tags/v1.2.3:refs/tags/v1.2.3\' || :',
'git checkout -qf 1234567890',
]);
});
});

describe('checkout', () => {
it('should run checkout 1', async() => {
it('should run checkout branch', async() => {
const mockExec = spyOnExec();

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

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

it('should run checkout 2', async() => {
it('should run checkout merge ref', async() => {
const mockExec = spyOnExec();

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

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

it('should run checkout 3', async() => {
it('should run checkout tag', async() => {
const mockExec = spyOnExec();

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

execCalledWith(mockExec, [
'git clone \'https://octocat:[email protected]/hello/world.git\' \'.\' > /dev/null 2>&1',
'git checkout -qf refs/tags/test-tag',
'rm -rdf \'.work\'',
'git init \'.\'',
'git remote add origin \'https://octocat:[email protected]/hello/world.git\' > /dev/null 2>&1 || :',
'git fetch --no-tags origin \'refs/tags/v1.2.3:refs/tags/v1.2.3\' || :',
'git checkout -qf test-sha',
]);
});
});
Expand Down Expand Up @@ -451,6 +467,24 @@ describe('GitHelper', () => {
'git show \'--stat-count=10\' HEAD',
]);
});

it('should run git commit with options', async() => {
setChildProcessParams({stdout: 'M file1\n\nM file2\n'});
const mockExec = spyOnExec();

expect(await helper.commit(workDir, 'test', {
count: 20,
allowEmpty: true,
args: ['--dry-run'],
})).toBeTruthy();

execCalledWith(mockExec, [
'git add --all',
'git status --short -uno',
'git commit --allow-empty --dry-run -qm test',
'git show \'--stat-count=20\' HEAD',
]);
});
});

describe('fetchTags', () => {
Expand Down
61 changes: 61 additions & 0 deletions __tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Utils } from '../src';
const {getWorkspace, getActor, escapeRegExp, getRegExp, getPrefixRegExp, getSuffixRegExp, useNpm, versionCompare, getOctokit} = Utils;
const {isSemanticVersioningTagName, isPrRef, getPrMergeRef, getBoolValue, replaceAll, getPrHeadRef, arrayChunk, sleep} = Utils;
const {getBranch, getRefForUpdate, uniqueArray, getBuildInfo, split, getArrayInput, generateNewPatchVersion, getPrBranch} = Utils;
const {isBranch, isTagRef, normalizeRef, trimRef, getTag, getRefspec} = Utils;

jest.useFakeTimers();

Expand Down Expand Up @@ -482,3 +483,63 @@ describe('getOctokit', () => {
expect(() => getOctokit()).toThrow();
});
});

describe('isBranch', () => {
it('should return true', () => {
expect(isBranch('refs/heads/master')).toBe(true);
expect(isBranch('heads/master')).toBe(true);
});

it('should return false', () => {
expect(isBranch('test')).toBe(false);
expect(isBranch('heads')).toBe(false);
});
});

describe('isTagRef', () => {
it('should return true', () => {
expect(isTagRef('refs/tags/v1.2.3')).toBe(true);
});

it('should return false', () => {
expect(isTagRef('refs/heads/master')).toBe(false);
expect(isTagRef('heads/master')).toBe(false);
});
});

describe('normalizeRef', () => {
it('should normalize ref', () => {
expect(normalizeRef('master')).toBe('refs/heads/master');
expect(normalizeRef('refs/heads/master')).toBe('refs/heads/master');
expect(normalizeRef('refs/tags/v1.2.3')).toBe('refs/tags/v1.2.3');
expect(normalizeRef('refs/pull/123/merge')).toBe('refs/pull/123/merge');
});
});

describe('trimRef', () => {
it('should trim ref', () => {
expect(trimRef('master')).toBe('master');
expect(trimRef('refs/heads/master')).toBe('master');
expect(trimRef('refs/tags/v1.2.3')).toBe('v1.2.3');
expect(trimRef('refs/pull/123/merge')).toBe('123/merge');
});
});

describe('getTag', () => {
it('should get tag', () => {
expect(getTag('master')).toBe('');
expect(getTag('heads/master')).toBe('');
expect(getTag('refs/heads/master')).toBe('');
expect(getTag('refs/tags/v1.2.3')).toBe('v1.2.3');
expect(getTag('refs/pull/123/merge')).toBe('');
});
});

describe('getRefspec', () => {
it('should get refspec', () => {
expect(getRefspec('master')).toBe('refs/heads/master:refs/remotes/origin/master');
expect(getRefspec('refs/heads/master', 'test')).toBe('refs/heads/master:refs/remotes/test/master');
expect(getRefspec('refs/tags/v1.2.3')).toBe('refs/tags/v1.2.3:refs/tags/v1.2.3');
expect(getRefspec('refs/pull/123/merge')).toBe('refs/pull/123/merge:refs/pull/123/merge');
});
});
6 changes: 3 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module.exports = {
clearMocks: true,
moduleFileExtensions: [ 'js', 'ts' ],
setupFiles: [ '<rootDir>/jest.setup.ts' ],
moduleFileExtensions: ['js', 'ts'],
setupFiles: ['<rootDir>/jest.setup.ts'],
testEnvironment: 'node',
testMatch: [ '**/*.test.ts' ],
testMatch: ['**/*.test.ts'],
testRunner: 'jest-circus/runner',
transform: {
'^.+\\.ts$': 'ts-jest',
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@technote-space/github-action-helper",
"version": "0.8.4",
"version": "0.8.5",
"description": "Helper to filter GitHub Action.",
"author": {
"name": "Technote",
Expand Down Expand Up @@ -32,7 +32,7 @@
"sprintf-js": "^1.1.2"
},
"devDependencies": {
"@technote-space/github-action-test-helper": "^0.1.5",
"@technote-space/github-action-test-helper": "^0.2.0",
"@types/jest": "^25.1.1",
"@types/node": "^13.7.0",
"@typescript-eslint/eslint-plugin": "^2.19.0",
Expand Down
Loading