Skip to content

Commit

Permalink
Merge bcc4d91 into 5987745
Browse files Browse the repository at this point in the history
  • Loading branch information
technote-space committed Sep 10, 2019
2 parents 5987745 + bcc4d91 commit 11345d8
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 69 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -2,3 +2,4 @@
/node_modules
/coverage
/lib
/.work
6 changes: 5 additions & 1 deletion __tests__/utils/misc.test.ts
@@ -1,3 +1,4 @@
import fs from 'fs';
import path from 'path';
import {getContext, testEnv} from '../util';
import {
Expand Down Expand Up @@ -89,7 +90,10 @@ describe('getWorkDir', () => {

it('should get working dir', () => {
process.env.GITHUB_WORKSPACE = undefined;
expect(getWorkDir()).toBe(path.resolve('.work'));
if (!fs.existsSync(path.resolve('.git'))) {
fs.mkdirSync(path.resolve('.git'));
}
expect(getWorkDir()).toBe(path.resolve('.'));
});
});

Expand Down
17 changes: 12 additions & 5 deletions package.json
Expand Up @@ -18,16 +18,16 @@
},
"main": "lib/main.js",
"dependencies": {
"@actions/core": "^1.0.0",
"@actions/github": "^1.0.0",
"@actions/core": "^1.1.0",
"@actions/github": "^1.1.0",
"signale": "^1.4.0"
},
"devDependencies": {
"@types/jest": "^24.0.18",
"@types/node": "^12.7.2",
"@types/node": "^12.7.4",
"jest": "^24.9.0",
"jest-circus": "^24.9.0",
"nock": "^10.0.6",
"nock": "^11.3.3",
"ts-jest": "^24.0.2",
"typescript": "^3.6.2"
},
Expand All @@ -37,6 +37,13 @@
"scripts": {
"build": "tsc",
"test": "jest",
"cover": "jest --coverage"
"cover": "jest --coverage",
"release": "yarn release:build && yarn release:mkdir && yarn release:copy && yarn release:clear",
"release:build": "yarn install && yarn build && yarn install --production",
"release:mkdir": "rm -rdf .work && mkdir .work",
"release:copy": "rsync -a --exclude='.git' --exclude='.work' --exclude='.idea' --exclude='coverage' --checksum --delete . .work",
"release:clear": "yarn release:clear:dir && yarn release:clear:file",
"release:clear:dir": "rm -rdf .work/.github && rm -rdf .work/__tests__ && rm -rdf .work/src",
"release:clear:file": "rm -rdf .work/.gitignore && rm -rdf .work/*.js && rm -rdf .work/*.json && rm -rdf .work/*.lock && rm -rdf .work/_config.yml"
}
}
6 changes: 5 additions & 1 deletion src/utils/command.ts
Expand Up @@ -3,7 +3,7 @@ import path from 'path';
import signale from 'signale';
import {exec} from 'child_process';
import {Context} from '@actions/github/lib/context';
import {getBranch, getDocTocArgs, getGitUrl, getWorkDir} from './misc';
import {getBranch, getDocTocArgs, getGitUrl, isCloned, getWorkDir} from './misc';

export const getChangedFiles = async (context: Context): Promise<string[] | false> => {
signale.info('Running DocToc and getting changed files');
Expand All @@ -18,6 +18,10 @@ export const getChangedFiles = async (context: Context): Promise<string[] | fals
};

const clone = async (workDir: string, context: Context): Promise<boolean> => {
if (isCloned()) {
return true;
}

const branch = getBranch(context);
const url = getGitUrl(context);
await execAsync(`git -C ${workDir} clone --quiet --branch=${branch} --depth=1 ${url} .`, false, null, true);
Expand Down
4 changes: 3 additions & 1 deletion src/utils/misc.ts
Expand Up @@ -37,7 +37,9 @@ const getTocTitle = (): string => getInput('TOC_TITLE') || '';

const getWorkspace = (): string => process.env.GITHUB_WORKSPACE || '';

export const getWorkDir = () => path.resolve(getWorkspace(), '.work');
export const isCloned = (): boolean => fs.existsSync(path.resolve(getWorkspace(), '.git'));

export const getWorkDir = (): string => isCloned() ? path.resolve(getWorkspace()) : path.resolve(getWorkspace(), '.work');

export const getGitUrl = (context: Context): string => `https://github.com/${context.repo.owner}/${context.repo.repo}.git`;

Expand Down
85 changes: 24 additions & 61 deletions yarn.lock
Expand Up @@ -2,15 +2,15 @@
# yarn lockfile v1


"@actions/core@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@actions/core/-/core-1.0.0.tgz#4a090a2e958cc300b9ea802331034d5faf42d239"
integrity sha512-aMIlkx96XH4E/2YZtEOeyrYQfhlas9jIRkfGPqMwXD095Rdkzo4lB6ZmbxPQSzD+e1M+Xsm98ZhuSMYGv/AlqA==
"@actions/core@^1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@actions/core/-/core-1.1.0.tgz#25c3aff43a20f9c5a04e2a3439898a49ba8d3625"
integrity sha512-KKpo3xzo0Zsikni9tbOsEQkxZBGDsYSJZNkTvmo0gPSXrc98TBOcdTvKwwjitjkjHkreTggWdB1ACiAFVgsuzA==

"@actions/github@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@actions/github/-/github-1.0.0.tgz#5154cadd93c4b17217f56304ee27056730b8ae88"
integrity sha512-PPbWZ5wFAD/Vr+RCECfR3KNHjTwYln4liJBihs9tQUL0/PCFqB2lSkIh9V94AcZFHxgKk8snImjuLaBE8bKR7A==
"@actions/github@^1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@actions/github/-/github-1.1.0.tgz#06f34e6b0cf07eb2b3641de3e680dbfae6bcd400"
integrity sha512-cHf6PyoNMdei13jEdGPhKprIMFmjVVW/dnM5/9QmQDJ1ZTaGVyezUSCUIC/ySNLRvDUpeFwPYMdThSEJldSbUw==
dependencies:
"@octokit/graphql" "^2.0.1"
"@octokit/rest" "^16.15.0"
Expand Down Expand Up @@ -423,10 +423,10 @@
dependencies:
"@types/jest-diff" "*"

"@types/node@^12.7.2":
version "12.7.2"
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.7.2.tgz#c4e63af5e8823ce9cc3f0b34f7b998c2171f0c44"
integrity sha512-dyYO+f6ihZEtNPDcWNR1fkoTDf3zAK3lAABDze3mz6POyIercH0lEUawUFXlG8xaQZmm1yEBON/4TsYv/laDYg==
"@types/node@^12.7.4":
version "12.7.4"
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.7.4.tgz#64db61e0359eb5a8d99b55e05c729f130a678b04"
integrity sha512-W0+n1Y+gK/8G2P/piTkBBN38Qc5Q1ZSO6B5H3QmPCUewaiXOo2GCAWZ4ElZCcNhjJuBSUSLGFUJnmlCn5+nxOQ==

"@types/stack-utils@^1.0.1":
version "1.0.1"
Expand Down Expand Up @@ -994,18 +994,6 @@ deep-eql@^3.0.1:
dependencies:
type-detect "^4.0.0"

deep-equal@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/deep-equal/-/deep-equal-1.1.0.tgz#3103cdf8ab6d32cf4a8df7865458f2b8d33f3745"
integrity sha512-ZbfWJq/wN1Z273o7mUSjILYqehAktR2NVoSrOukDkU9kg2v/Uv89yU4Cvz8seJeAmtN5oqiefKq8FPuXOboqLw==
dependencies:
is-arguments "^1.0.4"
is-date-object "^1.0.1"
is-regex "^1.0.4"
object-is "^1.0.1"
object-keys "^1.1.1"
regexp.prototype.flags "^1.2.0"

deep-extend@^0.6.0:
version "0.6.0"
resolved "https://registry.yarnpkg.com/deep-extend/-/deep-extend-0.6.0.tgz#c4fa7c95404a17a9c3e8ca7e1537312b736330ac"
Expand Down Expand Up @@ -1597,11 +1585,6 @@ is-accessor-descriptor@^1.0.0:
dependencies:
kind-of "^6.0.0"

is-arguments@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/is-arguments/-/is-arguments-1.0.4.tgz#3faf966c7cba0ff437fb31f6250082fcf0448cf3"
integrity sha512-xPh0Rmt8NE65sNzvyUmWgI1tz3mKq74lGA0mL8LYZcoIzKOzDh6HmrYm3d18k60nHerC8A9Km8kYu87zfSFnLA==

is-arrayish@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/is-arrayish/-/is-arrayish-0.2.1.tgz#77c99840527aa8ecb1a8ba697b80645a7a926a9d"
Expand Down Expand Up @@ -2375,7 +2358,7 @@ lodash.uniq@^4.5.0:
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"
integrity sha1-0CJTc662Uq3BvILklFM5qEJ1R3M=

lodash@^4.17.11, lodash@^4.17.13, lodash@^4.17.5:
lodash@^4.17.11, lodash@^4.17.13:
version "4.17.15"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548"
integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==
Expand Down Expand Up @@ -2568,20 +2551,17 @@ nice-try@^1.0.4:
resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366"
integrity sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==

nock@^10.0.6:
version "10.0.6"
resolved "https://registry.yarnpkg.com/nock/-/nock-10.0.6.tgz#e6d90ee7a68b8cfc2ab7f6127e7d99aa7d13d111"
integrity sha512-b47OWj1qf/LqSQYnmokNWM8D88KvUl2y7jT0567NB3ZBAZFz2bWp2PC81Xn7u8F2/vJxzkzNZybnemeFa7AZ2w==
nock@^11.3.3:
version "11.3.3"
resolved "https://registry.yarnpkg.com/nock/-/nock-11.3.3.tgz#f4553d87ac8e501d7a995a50df7e24857f879f58"
integrity sha512-SrRux5onbWf2ItpmietnLYis+C2QYF08hAo9wv/3QLqaLJVHBSVBTL0EvlD8Hjrm7lTH4vExTzr9gQUsPqy5Cg==
dependencies:
chai "^4.1.2"
debug "^4.1.0"
deep-equal "^1.0.0"
json-stringify-safe "^5.0.1"
lodash "^4.17.5"
lodash "^4.17.13"
mkdirp "^0.5.0"
propagate "^1.0.0"
qs "^6.5.1"
semver "^5.5.0"
propagate "^2.0.0"

node-fetch@^2.3.0:
version "2.6.0"
Expand Down Expand Up @@ -2709,12 +2689,7 @@ object-copy@^0.1.0:
define-property "^0.2.5"
kind-of "^3.0.3"

object-is@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/object-is/-/object-is-1.0.1.tgz#0aa60ec9989a0b3ed795cf4d06f62cf1ad6539b6"
integrity sha1-CqYOyZiaCz7Xlc9NBvYs8a1lObY=

object-keys@^1.0.12, object-keys@^1.1.1:
object-keys@^1.0.12:
version "1.1.1"
resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-1.1.1.tgz#1c47f272df277f3b1daf061677d9c82e2322c60e"
integrity sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==
Expand Down Expand Up @@ -2979,10 +2954,10 @@ prompts@^2.0.1:
kleur "^3.0.3"
sisteransi "^1.0.3"

propagate@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/propagate/-/propagate-1.0.0.tgz#00c2daeedda20e87e3782b344adba1cddd6ad709"
integrity sha1-AMLa7t2iDofjeCs0Stuhzd1q1wk=
propagate@^2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/propagate/-/propagate-2.0.1.tgz#40cdedab18085c792334e64f0ac17256d38f9a45"
integrity sha512-vGrhOavPSTz4QVNuBNdcNXePNdNMaO1xj9yBeH1ScQPjk/rhg9sSlCXPhMkFuaNNW/syTvYqsnbIJxMBfRbbag==

psl@^1.1.24, psl@^1.1.28:
version "1.3.0"
Expand All @@ -3007,11 +2982,6 @@ punycode@^2.1.0, punycode@^2.1.1:
resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec"
integrity sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==

qs@^6.5.1:
version "6.8.0"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.8.0.tgz#87b763f0d37ca54200334cd57bb2ef8f68a1d081"
integrity sha512-tPSkj8y92PfZVbinY1n84i1Qdx75lZjMQYx9WZhnkofyxzw2r7Ho39G3/aEvSUdebxpnnM4LZJCtvE/Aq3+s9w==

qs@~6.5.2:
version "6.5.2"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.2.tgz#cb3ae806e8740444584ef154ce8ee98d403f3e36"
Expand Down Expand Up @@ -3077,13 +3047,6 @@ regex-not@^1.0.0, regex-not@^1.0.2:
extend-shallow "^3.0.2"
safe-regex "^1.1.0"

regexp.prototype.flags@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/regexp.prototype.flags/-/regexp.prototype.flags-1.2.0.tgz#6b30724e306a27833eeb171b66ac8890ba37e41c"
integrity sha512-ztaw4M1VqgMwl9HlPpOuiYgItcHlunW0He2fE6eNfT6E/CF2FtYi9ofOYe4mKntstYk0Fyh/rDRBdS3AnxjlrA==
dependencies:
define-properties "^1.1.2"

remove-trailing-separator@^1.0.1:
version "1.1.0"
resolved "https://registry.yarnpkg.com/remove-trailing-separator/-/remove-trailing-separator-1.1.0.tgz#c24bce2a283adad5bc3f58e0d48249b92379d8ef"
Expand Down

0 comments on commit 11345d8

Please sign in to comment.