Skip to content

Commit

Permalink
build: use spawn to run sub command
Browse files Browse the repository at this point in the history
Signed-off-by: Liu Bowen <[email protected]>
  • Loading branch information
lbwa committed Aug 2, 2021
1 parent 923ced1 commit 553f516
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 103 deletions.
1 change: 0 additions & 1 deletion dist/action.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion dist/index.d.ts

This file was deleted.

26 changes: 9 additions & 17 deletions dist/index.js

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"prepare": "husky install",
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,css,scss,sass,less,md}\"",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
"build": "tsc --noEmit & esbuild src/index.ts --bundle --platform=node --outdir=dist --target=node14 --tsconfig=tsconfig.json",
"build": "tsc --noEmit & esbuild src/index.ts --bundle --minify --platform=node --outdir=dist --target=node14 --tsconfig=tsconfig.json",
"watch": "tsc -p tsconfig.json -w"
},
"keywords": [
Expand All @@ -32,16 +32,17 @@
"dependencies": {
"@actions/core": "^1.2.7",
"@actions/github": "^5.0.0",
"cross-spawn": "^7.0.3",
"fs-extra": "^10.0.0",
"func-async": "^0.1.0",
"lodash": "^4.17.21",
"tslib": "^2.2.0",
"zx": "^2.0.0"
"tslib": "^2.2.0"
},
"devDependencies": {
"@lbwa/eslint-config-typescript": "^0.4.1",
"@lbwa/prettier-config": "^0.1.0",
"@lbwa/tsconfig": "^0.1.0",
"@types/cross-spawn": "^6.0.2",
"@types/fs-extra": "^9.0.11",
"@types/lodash": "^4.14.170",
"@typescript-eslint/eslint-plugin": "^4.23.0",
Expand Down
23 changes: 15 additions & 8 deletions src/action.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getInput, info, startGroup, endGroup, setFailed } from '@actions/core'
import * as github from '@actions/github'
import fs from 'fs-extra'
import { $ } from 'zx'
import spawn from 'cross-spawn'
import isString from 'lodash/isString'

const enum Input {
Expand All @@ -12,6 +12,10 @@ const enum Input {

type ClientPayload = { id: number; title: string; post: string; path: string }

function runGit(argv: string[]) {
return spawn.sync('git', argv, { stdio: 'inherit' })
}

export async function main() {
const token = getInput(Input.TOKEN, { required: true })
const outDir = getInput(Input.OUT_DIR)
Expand Down Expand Up @@ -49,17 +53,20 @@ export async function main() {
endGroup()

if (username) {
await Promise.all([
$`git config user.email ${username}@users.noreply.github.com`,
$`git config user.name "${username}"`
])
runGit(['user.email', `${username}@users.noreply.github.com`])
runGit(['user.name', `"${username}"`])
}

const nameOnlyForLog =
outFile.length > 24 ? `${outFile.slice(0, 21)}...` : outFile
await $`git add .`
await $`git commit -s -m \"docs: sync \`${nameOnlyForLog}\` from yuque.com\"`
await $`git push ${remoteOrigin}`
runGit(['add', '.'])
runGit([
'commit',
'-s',
'-m',
`"docs: sync \`${nameOnlyForLog}\` from yuque.com"`
])
runGit(['push', remoteOrigin])

info(`New data has been uploaded to remote git.`)
}
82 changes: 9 additions & 73 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,13 @@
dependencies:
"@octokit/openapi-types" "^7.0.0"

"@types/cross-spawn@^6.0.2":
version "6.0.2"
resolved "https://registry.nlark.com/@types/cross-spawn/download/@types/cross-spawn-6.0.2.tgz#168309de311cd30a2b8ae720de6475c2fbf33ac7"
integrity sha1-FoMJ3jEc0woriucg3mR1wvvzOsc=
dependencies:
"@types/node" "*"

"@types/fs-extra@^9.0.11":
version "9.0.11"
resolved "https://registry.npm.taobao.org/@types/fs-extra/download/@types/fs-extra-9.0.11.tgz#8cc99e103499eab9f347dbc6ca4e99fb8d2c2b87"
Expand All @@ -223,29 +230,11 @@
resolved "https://registry.nlark.com/@types/lodash/download/@types/lodash-4.14.170.tgz#0d67711d4bf7f4ca5147e9091b847479b87925d6"
integrity sha1-DWdxHUv39MpRR+kJG4R0ebh5JdY=

"@types/minimist@^1.2.1":
version "1.2.2"
resolved "https://registry.nlark.com/@types/minimist/download/@types/minimist-1.2.2.tgz?cache=0&sync_timestamp=1625616230224&other_urls=https%3A%2F%2Fregistry.nlark.com%2F%40types%2Fminimist%2Fdownload%2F%40types%2Fminimist-1.2.2.tgz#ee771e2ba4b3dc5b372935d549fd9617bf345b8c"
integrity sha1-7nceK6Sz3Fs3KTXVSf2WF780W4w=

"@types/node-fetch@^2.5.10":
version "2.5.12"
resolved "https://registry.nlark.com/@types/node-fetch/download/@types/node-fetch-2.5.12.tgz?cache=0&sync_timestamp=1626990626436&other_urls=https%3A%2F%2Fregistry.nlark.com%2F%40types%2Fnode-fetch%2Fdownload%2F%40types%2Fnode-fetch-2.5.12.tgz#8a6f779b1d4e60b7a57fb6fd48d84fb545b9cc66"
integrity sha1-im93mx1OYLelf7b9SNhPtUW5zGY=
dependencies:
"@types/node" "*"
form-data "^3.0.0"

"@types/node@*":
version "15.0.3"
resolved "https://registry.nlark.com/@types/node/download/@types/node-15.0.3.tgz?cache=0&sync_timestamp=1620848082471&other_urls=https%3A%2F%2Fregistry.nlark.com%2F%40types%2Fnode%2Fdownload%2F%40types%2Fnode-15.0.3.tgz#ee09fcaac513576474c327da5818d421b98db88a"
integrity sha1-7gn8qsUTV2R0wyfaWBjUIbmNuIo=

"@types/node@^16.0":
version "16.4.10"
resolved "https://registry.nlark.com/@types/node/download/@types/node-16.4.10.tgz?cache=0&sync_timestamp=1627817716261&other_urls=https%3A%2F%2Fregistry.nlark.com%2F%40types%2Fnode%2Fdownload%2F%40types%2Fnode-16.4.10.tgz#e57e2a54fc6da58da94b3571b1cb456d39f88597"
integrity sha1-5X4qVPxtpY2pSzVxsctFbTn4hZc=

"@types/parse-json@^4.0.0":
version "4.0.0"
resolved "https://registry.nlark.com/@types/parse-json/download/@types/parse-json-4.0.0.tgz#2f8bb441434d163b35fb8ffdccd7138927ffb8c0"
Expand Down Expand Up @@ -427,11 +416,6 @@ astral-regex@^2.0.0:
resolved "https://registry.npm.taobao.org/astral-regex/download/astral-regex-2.0.0.tgz#483143c567aeed4785759c0865786dc77d7d2e31"
integrity sha1-SDFDxWeu7UeFdZwIZXhtx319LjE=

asynckit@^0.4.0:
version "0.4.0"
resolved "https://registry.npm.taobao.org/asynckit/download/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
integrity sha1-x57Zf380y48robyXkLzDZkdLS3k=

balanced-match@^1.0.0:
version "1.0.2"
resolved "https://registry.npm.taobao.org/balanced-match/download/balanced-match-1.0.2.tgz?cache=0&sync_timestamp=1617714233441&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fbalanced-match%2Fdownload%2Fbalanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee"
Expand Down Expand Up @@ -531,13 +515,6 @@ color-name@~1.1.4:
resolved "https://registry.npm.taobao.org/color-name/download/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2"
integrity sha1-wqCah6y95pVD3m9j+jmVyCbFNqI=

combined-stream@^1.0.8:
version "1.0.8"
resolved "https://registry.nlark.com/combined-stream/download/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f"
integrity sha1-w9RaizT9cwYxoRCoolIGgrMdWn8=
dependencies:
delayed-stream "~1.0.0"

commander@^7.2.0:
version "7.2.0"
resolved "https://registry.npm.taobao.org/commander/download/commander-7.2.0.tgz?cache=0&sync_timestamp=1616364348904&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fcommander%2Fdownload%2Fcommander-7.2.0.tgz#a36cb57d0b501ce108e4d20559a150a391d97ab7"
Expand Down Expand Up @@ -614,11 +591,6 @@ define-properties@^1.1.3:
dependencies:
object-keys "^1.0.12"

delayed-stream@~1.0.0:
version "1.0.0"
resolved "https://registry.nlark.com/delayed-stream/download/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
integrity sha1-3zrhmayt+31ECqrgsp4icrJOxhk=

deprecation@^2.0.0, deprecation@^2.3.1:
version "2.3.1"
resolved "https://registry.npm.taobao.org/deprecation/download/deprecation-2.3.1.tgz#6368cbdb40abf3373b525ac87e4a260c3a700919"
Expand Down Expand Up @@ -968,15 +940,6 @@ flatted@^3.1.0:
resolved "https://registry.npm.taobao.org/flatted/download/flatted-3.1.1.tgz?cache=0&sync_timestamp=1611059462226&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fflatted%2Fdownload%2Fflatted-3.1.1.tgz#c4b489e80096d9df1dfc97c79871aea7c617c469"
integrity sha1-xLSJ6ACW2d8d/JfHmHGup8YXxGk=

form-data@^3.0.0:
version "3.0.1"
resolved "https://registry.nlark.com/form-data/download/form-data-3.0.1.tgz#ebd53791b78356a99af9a300d4282c4d5eb9755f"
integrity sha1-69U3kbeDVqma+aMA1CgsTV65dV8=
dependencies:
asynckit "^0.4.0"
combined-stream "^1.0.8"
mime-types "^2.1.12"

fs-extra@^10.0.0:
version "10.0.0"
resolved "https://registry.nlark.com/fs-extra/download/fs-extra-10.0.0.tgz#9ff61b655dde53fb34a82df84bb214ce802e17c1"
Expand Down Expand Up @@ -1453,18 +1416,6 @@ micromatch@^4.0.2, micromatch@^4.0.4:
braces "^3.0.1"
picomatch "^2.2.3"

[email protected]:
version "1.49.0"
resolved "https://registry.nlark.com/mime-db/download/mime-db-1.49.0.tgz#f3dfde60c99e9cf3bc9701d687778f537001cbed"
integrity sha1-89/eYMmenPO8lwHWh3ePU3ABy+0=

mime-types@^2.1.12:
version "2.1.32"
resolved "https://registry.nlark.com/mime-types/download/mime-types-2.1.32.tgz?cache=0&sync_timestamp=1627407652875&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fmime-types%2Fdownload%2Fmime-types-2.1.32.tgz#1d00e89e7de7fe02008db61001d9e02852670fd5"
integrity sha1-HQDonn3n/gIAjbYQAdngKFJnD9U=
dependencies:
mime-db "1.49.0"

mimic-fn@^2.1.0:
version "2.1.0"
resolved "https://registry.nlark.com/mimic-fn/download/mimic-fn-2.1.0.tgz#7ed2c2ccccaf84d3ffcb7a69b57711fc2083401b"
Expand All @@ -1477,7 +1428,7 @@ minimatch@^3.0.4:
dependencies:
brace-expansion "^1.1.7"

minimist@^1.2.0, minimist@^1.2.5:
minimist@^1.2.0:
version "1.2.5"
resolved "https://registry.npm.taobao.org/minimist/download/minimist-1.2.5.tgz#67d66014b66a6a8aaa0c083c5fd58df4e4e97602"
integrity sha1-Z9ZgFLZqaoqqDAg8X9WN9OTpdgI=
Expand Down Expand Up @@ -2126,7 +2077,7 @@ which-boxed-primitive@^1.0.2:
is-string "^1.0.5"
is-symbol "^1.0.3"

which@^2.0.1, which@^2.0.2:
which@^2.0.1:
version "2.0.2"
resolved "https://registry.nlark.com/which/download/which-2.0.2.tgz#7c6a8dd0a636a0327e10b59c9286eee93f3f51b1"
integrity sha1-fGqN0KY2oDJ+ELWckobu6T8/UbE=
Expand Down Expand Up @@ -2170,18 +2121,3 @@ yaml@^1.10.0:
version "1.10.2"
resolved "https://registry.nlark.com/yaml/download/yaml-1.10.2.tgz?cache=0&sync_timestamp=1618847148789&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fyaml%2Fdownload%2Fyaml-1.10.2.tgz#2301c5ffbf12b467de8da2333a459e29e7920e4b"
integrity sha1-IwHF/78StGfejaIzOkWeKeeSDks=

zx@^2.0.0:
version "2.0.0"
resolved "https://registry.nlark.com/zx/download/zx-2.0.0.tgz#08b11222a26fd160e234552fd54bb486ec6e81b9"
integrity sha1-CLESIqJv0WDiNFUv1Uu0huxugbk=
dependencies:
"@types/fs-extra" "^9.0.11"
"@types/minimist" "^1.2.1"
"@types/node" "^16.0"
"@types/node-fetch" "^2.5.10"
chalk "^4.1.1"
fs-extra "^10.0.0"
minimist "^1.2.5"
node-fetch "^2.6.1"
which "^2.0.2"

0 comments on commit 553f516

Please sign in to comment.