Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

release: v3.3.0 #120

Merged
merged 9 commits into from
Sep 25, 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
75 changes: 49 additions & 26 deletions __tests__/process.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ import {
spyOnStdout,
stdoutCalledWith,
spyOnSpawn,
execCalledWith,
spyOnExportVariable,
exportVariableCalledWith,
testChildProcess,
setChildProcessParams,
execCalledWith,
testFs,
generateContext,
getLogStdout,
} from '@technote-space/github-action-test-helper';
import {Logger} from '@technote-space/github-action-helper';
import {Logger} from '@technote-space/github-action-log-helper';
import {dumpDiffs, setResult, execute} from '../src/process';

const rootDir = path.resolve(__dirname, '..');
Expand Down Expand Up @@ -119,19 +121,17 @@ describe('setResult', () => {

it('should set result', () => {
const mockStdout = spyOnStdout();
const mockEnv = spyOnExportVariable();

setResult(diffs, false, logger);

stdoutCalledWith(mockStdout, [
'::group::Dump output',
'::set-output name=diff::test1 test2 test4',
'::set-env name=GIT_DIFF::test1 test2 test4',
'"diff: test1 test2 test4"',
'::set-output name=filtered_diff::test1 test2',
'::set-env name=GIT_DIFF_FILTERED::test1 test2',
'"filtered_diff: test1 test2"',
'::set-output name=matched_files::test4',
'::set-env name=MATCHED_FILES::test4',
'"matched_files: test4"',
'::set-output name=count::3',
'"count: 3"',
Expand All @@ -143,6 +143,11 @@ describe('setResult', () => {
'"lines: 303"',
'::endgroup::',
]);
exportVariableCalledWith(mockEnv, [
{name: 'GIT_DIFF', val: 'test1 test2 test4'},
{name: 'GIT_DIFF_FILTERED', val: 'test1 test2'},
{name: 'MATCHED_FILES', val: 'test4'},
]);
});

it('should set result without env', () => {
Expand All @@ -152,6 +157,7 @@ describe('setResult', () => {
process.env.INPUT_SET_ENV_NAME_DELETIONS = 'DELETIONS';
process.env.INPUT_SET_ENV_NAME_LINES = 'LINES';
const mockStdout = spyOnStdout();
const mockEnv = spyOnExportVariable();

setResult(diffs, false, logger);

Expand All @@ -160,25 +166,27 @@ describe('setResult', () => {
'::set-output name=diff::test1 test2 test4',
'"diff: test1 test2 test4"',
'::set-output name=filtered_diff::test1 test2',
'::set-env name=GIT_DIFF_FILTERED::test1 test2',
'"filtered_diff: test1 test2"',
'::set-output name=matched_files::test4',
'::set-env name=MATCHED_FILES::test4',
'"matched_files: test4"',
'::set-output name=count::3',
'::set-env name=FILE_COUNT::3',
'"count: 3"',
'::set-output name=insertions::3',
'::set-env name=INSERTIONS::3',
'"insertions: 3"',
'::set-output name=deletions::300',
'::set-env name=DELETIONS::300',
'"deletions: 300"',
'::set-output name=lines::303',
'::set-env name=LINES::303',
'"lines: 303"',
'::endgroup::',
]);
exportVariableCalledWith(mockEnv, [
{name: 'GIT_DIFF_FILTERED', val: 'test1 test2'},
{name: 'MATCHED_FILES', val: 'test4'},
{name: 'FILE_COUNT', val: '3'},
{name: 'INSERTIONS', val: '3'},
{name: 'DELETIONS', val: '300'},
{name: 'LINES', val: '303'},
]);
});
});

Expand All @@ -195,6 +203,7 @@ describe('execute', () => {

const mockExec = spyOnSpawn();
const mockStdout = spyOnStdout();
const mockEnv = spyOnExportVariable();
setChildProcessParams({
stdout: (command: string): string => {
if (command.startsWith('git diff')) {
Expand Down Expand Up @@ -264,13 +273,10 @@ describe('execute', () => {
'::endgroup::',
'::group::Dump output',
'::set-output name=diff::\'package.json\' \'abc/package.json\' \'src/main.ts\'',
'::set-env name=GIT_DIFF::\'package.json\' \'abc/package.json\' \'src/main.ts\'',
'"diff: \'package.json\' \'abc/package.json\' \'src/main.ts\'"',
'::set-output name=filtered_diff::\'src/main.ts\'',
'::set-env name=GIT_DIFF_FILTERED::\'src/main.ts\'',
'"filtered_diff: \'src/main.ts\'"',
'::set-output name=matched_files::\'package.json\' \'abc/package.json\'',
'::set-env name=MATCHED_FILES::\'package.json\' \'abc/package.json\'',
'"matched_files: \'package.json\' \'abc/package.json\'"',
'::set-output name=count::3',
'"count: 3"',
Expand All @@ -282,6 +288,11 @@ describe('execute', () => {
'"lines: 29"',
'::endgroup::',
]);
exportVariableCalledWith(mockEnv, [
{name: 'GIT_DIFF', val: '\'package.json\' \'abc/package.json\' \'src/main.ts\''},
{name: 'GIT_DIFF_FILTERED', val: '\'src/main.ts\''},
{name: 'MATCHED_FILES', val: '\'package.json\' \'abc/package.json\''},
]);
});

it('should execute (no diff)', async() => {
Expand All @@ -291,6 +302,7 @@ describe('execute', () => {

const mockExec = spyOnSpawn();
const mockStdout = spyOnStdout();
const mockEnv = spyOnExportVariable();
setChildProcessParams({
stdout: (command: string): string => {
if (command.startsWith('git diff')) {
Expand Down Expand Up @@ -323,13 +335,10 @@ describe('execute', () => {
'::endgroup::',
'::group::Dump output',
'::set-output name=diff::',
'::set-env name=GIT_DIFF::',
'"diff: "',
'::set-output name=filtered_diff::',
'::set-env name=GIT_DIFF_FILTERED::',
'"filtered_diff: "',
'::set-output name=matched_files::',
'::set-env name=MATCHED_FILES::',
'"matched_files: "',
'::set-output name=count::0',
'"count: 0"',
Expand All @@ -341,13 +350,19 @@ describe('execute', () => {
'"lines: 0"',
'::endgroup::',
]);
exportVariableCalledWith(mockEnv, [
{name: 'GIT_DIFF', val: ''},
{name: 'GIT_DIFF_FILTERED', val: ''},
{name: 'MATCHED_FILES', val: ''},
]);
});

it('should execute empty', async() => {
process.env.GITHUB_WORKSPACE = '/home/runner/work/my-repo-name/my-repo-name';

const mockExec = spyOnSpawn();
const mockStdout = spyOnStdout();
const mockEnv = spyOnExportVariable();

await execute(logger, prContext, true);

Expand All @@ -358,13 +373,10 @@ describe('execute', () => {
'::endgroup::',
'::group::Dump output',
'::set-output name=diff::',
'::set-env name=GIT_DIFF::',
'"diff: "',
'::set-output name=filtered_diff::',
'::set-env name=GIT_DIFF_FILTERED::',
'"filtered_diff: "',
'::set-output name=matched_files::',
'::set-env name=MATCHED_FILES::',
'"matched_files: "',
'::set-output name=count::0',
'"count: 0"',
Expand All @@ -376,6 +388,11 @@ describe('execute', () => {
'"lines: 0"',
'::endgroup::',
]);
exportVariableCalledWith(mockEnv, [
{name: 'GIT_DIFF', val: ''},
{name: 'GIT_DIFF_FILTERED', val: ''},
{name: 'MATCHED_FILES', val: ''},
]);
});

it('should execute empty with default value', async() => {
Expand All @@ -390,6 +407,7 @@ describe('execute', () => {

const mockExec = spyOnSpawn();
const mockStdout = spyOnStdout();
const mockEnv = spyOnExportVariable();

await execute(logger, prContext, true);

Expand All @@ -400,13 +418,10 @@ describe('execute', () => {
'::endgroup::',
'::group::Dump output',
'::set-output name=diff::1',
'::set-env name=GIT_DIFF::1',
'"diff: 1"',
'::set-output name=filtered_diff::2',
'::set-env name=GIT_DIFF_FILTERED::2',
'"filtered_diff: 2"',
'::set-output name=matched_files::3',
'::set-env name=MATCHED_FILES::3',
'"matched_files: 3"',
'::set-output name=count::4',
'"count: 4"',
Expand All @@ -418,13 +433,19 @@ describe('execute', () => {
'"lines: 7"',
'::endgroup::',
]);
exportVariableCalledWith(mockEnv, [
{name: 'GIT_DIFF', val: '1'},
{name: 'GIT_DIFF_FILTERED', val: '2'},
{name: 'MATCHED_FILES', val: '3'},
]);
});

it('should not execute if not cloned', async() => {
process.env.GITHUB_WORKSPACE = '/home/runner/work/my-repo-name/my-repo-name';

const mockExec = spyOnSpawn();
const mockStdout = spyOnStdout();
const mockEnv = spyOnExportVariable();
setChildProcessParams({
stdout: (command: string): string => {
if (command.startsWith('git diff')) {
Expand All @@ -448,13 +469,10 @@ describe('execute', () => {
'::endgroup::',
'::group::Dump output',
'::set-output name=diff::',
'::set-env name=GIT_DIFF::',
'"diff: "',
'::set-output name=filtered_diff::',
'::set-env name=GIT_DIFF_FILTERED::',
'"filtered_diff: "',
'::set-output name=matched_files::',
'::set-env name=MATCHED_FILES::',
'"matched_files: "',
'::set-output name=count::0',
'"count: 0"',
Expand All @@ -466,5 +484,10 @@ describe('execute', () => {
'"lines: 0"',
'::endgroup::',
]);
exportVariableCalledWith(mockEnv, [
{name: 'GIT_DIFF', val: ''},
{name: 'GIT_DIFF_FILTERED', val: ''},
{name: 'MATCHED_FILES', val: ''},
]);
});
});
2 changes: 1 addition & 1 deletion __tests__/utils/command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
disableNetConnect,
getApiFixture,
} from '@technote-space/github-action-test-helper';
import {Logger} from '@technote-space/github-action-helper';
import {Logger} from '@technote-space/github-action-log-helper';
import {getGitDiff, getFileDiff, getDiffFiles, sumResults} from '../../src/utils/command';

const rootDir = path.resolve(__dirname, '../..');
Expand Down
66 changes: 33 additions & 33 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,63 +1,63 @@
{
"name": "@technote-space/get-diff-action",
"version": "3.2.0",
"version": "3.3.0",
"description": "GitHub actions to get git diff.",
"author": {
"name": "Technote",
"email": "technote.space@gmail.com",
"url": "https://technote.space"
},
"license": "MIT",
"keywords": [
"github",
"github actions"
],
"homepage": "https://github.com/technote-space/get-diff-action",
"bugs": {
"url": "https://github.com/technote-space/get-diff-action/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/technote-space/get-diff-action.git"
},
"bugs": {
"url": "https://github.com/technote-space/get-diff-action/issues"
"license": "MIT",
"author": {
"name": "Technote",
"email": "technote.space@gmail.com",
"url": "https://technote.space"
},
"files": [
"lib",
"action.yml"
],
"scripts": {
"build": "tsc",
"cover": "jest --coverage",
"lint": "eslint 'src/**/*.ts' '__tests__/**/*.ts' --cache",
"lint:fix": "eslint --fix 'src/**/*.ts' '__tests__/**/*.ts'",
"release": "yarn release-ga --test",
"test": "yarn lint && yarn cover",
"update": "npx npm-check-updates -u && yarn install && yarn upgrade && yarn audit"
},
"dependencies": {
"@actions/core": "^1.2.5",
"@actions/core": "^1.2.6",
"@actions/github": "^4.0.0",
"@technote-space/filter-github-action": "^0.5.2",
"@technote-space/github-action-helper": "^3.5.0"
"@technote-space/filter-github-action": "^0.5.3",
"@technote-space/github-action-helper": "^4.0.2"
},
"devDependencies": {
"@commitlint/cli": "^9.1.2",
"@commitlint/config-conventional": "^9.1.2",
"@technote-space/github-action-test-helper": "^0.5.7",
"@technote-space/release-github-actions-cli": "^1.6.10",
"@types/jest": "^26.0.13",
"@types/node": "^14.10.0",
"@typescript-eslint/eslint-plugin": "^4.1.0",
"@typescript-eslint/parser": "^4.1.0",
"eslint": "^7.8.1",
"@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^11.0.0",
"@technote-space/github-action-test-helper": "^0.6.0",
"@technote-space/release-github-actions-cli": "^1.7.1",
"@types/jest": "^26.0.14",
"@types/node": "^14.11.2",
"@typescript-eslint/eslint-plugin": "^4.2.0",
"@typescript-eslint/parser": "^4.2.0",
"eslint": "^7.9.0",
"husky": "^4.3.0",
"jest": "^26.4.2",
"jest-circus": "^26.4.2",
"lint-staged": "^10.3.0",
"lint-staged": "^10.4.0",
"nock": "^13.0.4",
"ts-jest": "^26.3.0",
"typescript": "^4.0.2"
"ts-jest": "^26.4.0",
"typescript": "^4.0.3"
},
"publishConfig": {
"access": "public"
},
"scripts": {
"build": "tsc",
"test": "yarn lint && yarn cover",
"lint": "eslint 'src/**/*.ts' '__tests__/**/*.ts' --cache",
"lint:fix": "eslint --fix 'src/**/*.ts' '__tests__/**/*.ts'",
"cover": "jest --coverage",
"update": "npx npm-check-updates -u && yarn install && yarn upgrade && yarn audit",
"release": "yarn release-ga --test"
}
}
3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import {resolve} from 'path';
import {setFailed} from '@actions/core';
import {Context} from '@actions/github/lib/context';
import {isTargetEvent} from '@technote-space/filter-github-action';
import {Logger, ContextHelper} from '@technote-space/github-action-helper';
import {ContextHelper} from '@technote-space/github-action-helper';
import {Logger} from '@technote-space/github-action-log-helper';
import {execute} from './process';
import {TARGET_EVENTS} from './constant';

Expand Down
2 changes: 1 addition & 1 deletion src/process.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {exportVariable, getInput, setOutput} from '@actions/core' ;
import {Context} from '@actions/github/lib/context';
import {Logger} from '@technote-space/github-action-helper';
import {Logger} from '@technote-space/github-action-log-helper';
import {getGitDiff, getDiffFiles, getMatchedFiles, sumResults} from './utils/command';
import {DiffResult} from './types';

Expand Down
3 changes: 2 additions & 1 deletion src/utils/command.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import path from 'path';
import {getInput} from '@actions/core' ;
import {Context} from '@actions/github/lib/context';
import {Logger, Command, Utils, GitHelper} from '@technote-space/github-action-helper';
import {Command, Utils, GitHelper} from '@technote-space/github-action-helper';
import {Logger} from '@technote-space/github-action-log-helper';
import {escape, getDiffInfo} from './misc';
import {FileDiffResult, FileResult, DiffResult, DiffInfo} from '../types';
import {REMOTE_NAME} from '../constant';
Expand Down
Loading