Use native copy (#129)
This commit is contained in:
parent
45b1e3298a
commit
6963e12505
55
.github/workflows/ci.yml
vendored
55
.github/workflows/ci.yml
vendored
|
@ -11,15 +11,62 @@ on:
|
|||
jobs:
|
||||
ci:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- target_branch: 'gh-pages'
|
||||
keep_history: 'false'
|
||||
- target_branch: 'gh-pages-keep'
|
||||
keep_history: 'true'
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
-
|
||||
name: Init
|
||||
run: |
|
||||
sudo apt-get install tree
|
||||
mkdir public
|
||||
-
|
||||
name: Gen dummy files and folders
|
||||
run: |
|
||||
MAXDIRS=5
|
||||
MAXDEPTH=5
|
||||
MAXFILES=10
|
||||
MAXSIZE=1000
|
||||
TOP=$(pwd|tr -cd '/'|wc -c)
|
||||
|
||||
populate() {
|
||||
cd $1
|
||||
curdir=$PWD
|
||||
files=$(($RANDOM*$MAXFILES/32767))
|
||||
for n in $(seq $files)
|
||||
do
|
||||
f=$(mktemp XXXXXX)
|
||||
size=$(($RANDOM*$MAXSIZE/32767))
|
||||
head -c $size /dev/urandom > $f
|
||||
done
|
||||
depth=$(pwd | tr -cd '/' | wc -c)
|
||||
if [ $(($depth-$TOP)) -ge $MAXDEPTH ]
|
||||
then
|
||||
return
|
||||
fi
|
||||
unset dirlist
|
||||
dirs=$(($RANDOM*$MAXDIRS/32767))
|
||||
for n in $(seq $dirs); do
|
||||
d=`mktemp -d XXXXXX`
|
||||
dirlist="$dirlist${dirlist:+ }$PWD/$d"
|
||||
done
|
||||
for dir in $dirlist; do
|
||||
populate "$dir"
|
||||
done
|
||||
}
|
||||
|
||||
populate $PWD/public
|
||||
-
|
||||
name: Gen dummy page
|
||||
run: |
|
||||
mkdir public
|
||||
touch public/file{0001..3000}
|
||||
cat > public/index.html <<EOL
|
||||
<!doctype html>
|
||||
<html>
|
||||
|
@ -31,6 +78,7 @@ jobs:
|
|||
</body>
|
||||
</html>
|
||||
EOL
|
||||
tree -f -h ./public
|
||||
-
|
||||
name: Check GitHub Pages status
|
||||
uses: crazy-max/ghaction-github-status@v2
|
||||
|
@ -41,7 +89,8 @@ jobs:
|
|||
if: success()
|
||||
uses: ./
|
||||
with:
|
||||
target_branch: gh-pages
|
||||
target_branch: ${{ matrix.target_branch }}
|
||||
keep_history: ${{ matrix.keep_history }}
|
||||
build_dir: public
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
|
3356
dist/index.js
generated
vendored
3356
dist/index.js
generated
vendored
File diff suppressed because it is too large
Load Diff
|
@ -23,12 +23,10 @@
|
|||
"dependencies": {
|
||||
"@actions/core": "^1.2.6",
|
||||
"@actions/exec": "^1.0.4",
|
||||
"addressparser": "^1.0.1",
|
||||
"fs-extra": "^9.0.1"
|
||||
"addressparser": "^1.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@actions/io": "^1.0.2",
|
||||
"@types/fs-extra": "^9.0.1",
|
||||
"@types/node": "^14.11.2",
|
||||
"@vercel/ncc": "^0.24.1",
|
||||
"prettier": "^2.1.2",
|
||||
|
|
27
src/main.ts
27
src/main.ts
|
@ -1,10 +1,10 @@
|
|||
import addressparser from 'addressparser';
|
||||
import {copySync} from 'fs-extra';
|
||||
import * as fs from 'fs';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import * as core from '@actions/core';
|
||||
import * as git from './git';
|
||||
import * as util from './util';
|
||||
|
||||
async function run() {
|
||||
try {
|
||||
|
@ -26,10 +26,10 @@ async function run() {
|
|||
|
||||
let remoteURL = String('https://');
|
||||
if (process.env['GH_PAT']) {
|
||||
core.info(`✅ Use GH_PAT`);
|
||||
core.debug(`Use GH_PAT`);
|
||||
remoteURL = remoteURL.concat(process.env['GH_PAT'].trim());
|
||||
} else if (process.env['GITHUB_TOKEN']) {
|
||||
core.info(`✅ Use GITHUB_TOKEN`);
|
||||
core.debug(`Use GITHUB_TOKEN`);
|
||||
remoteURL = remoteURL.concat('x-access-token:', process.env['GITHUB_TOKEN'].trim());
|
||||
} else {
|
||||
core.setFailed('You have to provide a GITHUB_TOKEN or GH_PAT');
|
||||
|
@ -56,11 +56,8 @@ async function run() {
|
|||
await git.checkout(targetBranch);
|
||||
}
|
||||
|
||||
core.info(`🏃 Copying ${path.join(currentdir, buildDir)} contents to ${tmpdir}`);
|
||||
await copySync(path.join(currentdir, buildDir), tmpdir, {
|
||||
overwrite: true,
|
||||
errorOnExist: false,
|
||||
dereference: true
|
||||
await core.group(`🏃 Copying ${path.join(currentdir, buildDir)} contents to ${tmpdir}`, async () => {
|
||||
await util.copyDir(path.join(currentdir, buildDir), tmpdir);
|
||||
});
|
||||
|
||||
if (fqdn) {
|
||||
|
@ -94,20 +91,20 @@ async function run() {
|
|||
await git.add('.');
|
||||
|
||||
if (allowEmptyCommit) {
|
||||
core.info(`✅ Allow empty commit`);
|
||||
core.debug(`Allow empty commit`);
|
||||
}
|
||||
|
||||
const authorPrs: addressparser.Address = addressparser(author)[0];
|
||||
core.startGroup(`📦 Committing changes as ${authorPrs.name} <${authorPrs.address}> author`);
|
||||
await git.commit(allowEmptyCommit, `${authorPrs.name} <${authorPrs.address}>`, commitMessage);
|
||||
await git.showStat().then(output => {
|
||||
core.info(output);
|
||||
await core.group(`📦 Committing changes as ${authorPrs.name} <${authorPrs.address}> author`, async () => {
|
||||
await git.commit(allowEmptyCommit, `${authorPrs.name} <${authorPrs.address}>`, commitMessage);
|
||||
await git.showStat().then(output => {
|
||||
core.info(output);
|
||||
});
|
||||
});
|
||||
core.endGroup();
|
||||
|
||||
core.info(`🏃 Pushing ${buildDir} directory to ${targetBranch} branch on ${repo} repo`);
|
||||
if (!keepHistory) {
|
||||
core.info(`✅ Force push`);
|
||||
core.debug(`Force push`);
|
||||
}
|
||||
await git.push(remoteURL, targetBranch, !keepHistory);
|
||||
|
||||
|
|
77
src/util.ts
Normal file
77
src/util.ts
Normal file
|
@ -0,0 +1,77 @@
|
|||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as core from '@actions/core';
|
||||
|
||||
export async function copyDir(from: string, to: string): Promise<void> {
|
||||
core.debug(`copyDir ${from} to ${to}`);
|
||||
await fs.promises.mkdir(to, {recursive: true}).catch(err => {
|
||||
core.warning(err);
|
||||
});
|
||||
core.debug(`readdir ${from}`);
|
||||
await fs.promises.readdir(from).then(async (files: string[]) => {
|
||||
for (let fname of files) {
|
||||
core.debug(`# ${fname}`);
|
||||
core.debug(`stat ${path.join(from, fname)}`);
|
||||
const stat = await fs.promises.lstat(path.join(from, fname));
|
||||
if (stat.isFile()) {
|
||||
core.debug(`stat.isFile`);
|
||||
await fs.promises
|
||||
.copyFile(path.join(from, fname), path.join(to, fname))
|
||||
.then(_ => {
|
||||
core.info(
|
||||
`${path.join(from, fname).replace(process.env.GITHUB_WORKSPACE || '', '.')} => ${path.join(to, fname)}`
|
||||
);
|
||||
})
|
||||
.catch(err => {
|
||||
core.warning(err);
|
||||
});
|
||||
} else if (stat.isSymbolicLink()) {
|
||||
core.debug(`stat.isSymbolicLink`);
|
||||
await copySymlink(path.join(from, fname), path.join(to, fname));
|
||||
} else if (stat.isDirectory()) {
|
||||
core.debug(`stat.isDirectory`);
|
||||
await copyDir(path.join(from, fname), path.join(to, fname));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function copySymlink(from: string, to: string): Promise<void> {
|
||||
core.debug(`copySymlink ${from} to ${to}`);
|
||||
const llink = await fs.promises.readlink(from).catch(err => {
|
||||
if (err) {
|
||||
core.warning(err);
|
||||
}
|
||||
});
|
||||
core.debug(`llink ${llink}`);
|
||||
if (!llink) {
|
||||
return;
|
||||
}
|
||||
const lsrc = path.resolve(llink);
|
||||
core.debug(`lsrc ${lsrc}`);
|
||||
const lstat = await fs.promises.lstat(llink).catch(err => {
|
||||
if (err) {
|
||||
core.warning(`Cannot stat symlink ${llink} for ${from.replace(process.env.GITHUB_WORKSPACE || '', '.')}: ${err}`);
|
||||
}
|
||||
});
|
||||
if (!lstat) {
|
||||
return;
|
||||
}
|
||||
if (lstat.isFile()) {
|
||||
core.debug(`lstat.isFile`);
|
||||
await fs.promises
|
||||
.copyFile(lsrc, to)
|
||||
.then(_ => {
|
||||
core.info(`${lsrc.replace(process.env.GITHUB_WORKSPACE || '', '.')} => ${to}`);
|
||||
})
|
||||
.catch(err => {
|
||||
core.warning(err);
|
||||
});
|
||||
} else if (lstat.isSymbolicLink()) {
|
||||
core.debug(`lstat.isSymbolicLink`);
|
||||
await copySymlink(lsrc, to);
|
||||
} else if (lstat.isDirectory()) {
|
||||
core.debug(`lstat.isDirectory`);
|
||||
await copyDir(lsrc, to);
|
||||
}
|
||||
}
|
46
yarn.lock
46
yarn.lock
|
@ -19,18 +19,6 @@
|
|||
resolved "https://registry.yarnpkg.com/@actions/io/-/io-1.0.2.tgz#2f614b6e69ce14d191180451eb38e6576a6e6b27"
|
||||
integrity sha512-J8KuFqVPr3p6U8W93DOXlXW6zFvrQAJANdS+vw0YhusLIq+bszW8zmK2Fh1C2kDPX8FMvwIl1OUcFgvJoXLbAg==
|
||||
|
||||
"@types/fs-extra@^9.0.1":
|
||||
version "9.0.1"
|
||||
resolved "https://registry.yarnpkg.com/@types/fs-extra/-/fs-extra-9.0.1.tgz#91c8fc4c51f6d5dbe44c2ca9ab09310bd00c7918"
|
||||
integrity sha512-B42Sxuaz09MhC3DDeW5kubRcQ5by4iuVQ0cRRWM2lggLzAa/KVom0Aft/208NgMvNQQZ86s5rVcqDdn/SH0/mg==
|
||||
dependencies:
|
||||
"@types/node" "*"
|
||||
|
||||
"@types/node@*":
|
||||
version "14.0.14"
|
||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.0.14.tgz#24a0b5959f16ac141aeb0c5b3cd7a15b7c64cbce"
|
||||
integrity sha512-syUgf67ZQpaJj01/tRTknkMNoBBLWJOBODF0Zm4NrXmiSuxjymFrxnTu1QVYRubhVkRcZLYZG8STTwJRdVm/WQ==
|
||||
|
||||
"@types/node@^14.11.2":
|
||||
version "14.11.2"
|
||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.11.2.tgz#2de1ed6670439387da1c9f549a2ade2b0a799256"
|
||||
|
@ -46,11 +34,6 @@ addressparser@^1.0.1:
|
|||
resolved "https://registry.yarnpkg.com/addressparser/-/addressparser-1.0.1.tgz#47afbe1a2a9262191db6838e4fd1d39b40821746"
|
||||
integrity sha1-R6++GiqSYhkdtoOOT9HTm0CCF0Y=
|
||||
|
||||
at-least-node@^1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/at-least-node/-/at-least-node-1.0.0.tgz#602cd4b46e844ad4effc92a8011a3c46e0238dc2"
|
||||
integrity sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==
|
||||
|
||||
commander@^2.19.0:
|
||||
version "2.20.3"
|
||||
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33"
|
||||
|
@ -71,30 +54,6 @@ editorconfig@^0.15.0:
|
|||
semver "^5.6.0"
|
||||
sigmund "^1.0.1"
|
||||
|
||||
fs-extra@^9.0.1:
|
||||
version "9.0.1"
|
||||
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-9.0.1.tgz#910da0062437ba4c39fedd863f1675ccfefcb9fc"
|
||||
integrity sha512-h2iAoN838FqAFJY2/qVpzFXy+EBxfVE220PalAqQLDVsFOHLJrZvut5puAbCdNv6WJk+B8ihI+k0c7JK5erwqQ==
|
||||
dependencies:
|
||||
at-least-node "^1.0.0"
|
||||
graceful-fs "^4.2.0"
|
||||
jsonfile "^6.0.1"
|
||||
universalify "^1.0.0"
|
||||
|
||||
graceful-fs@^4.1.6, graceful-fs@^4.2.0:
|
||||
version "4.2.4"
|
||||
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.4.tgz#2256bde14d3632958c465ebc96dc467ca07a29fb"
|
||||
integrity sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw==
|
||||
|
||||
jsonfile@^6.0.1:
|
||||
version "6.0.1"
|
||||
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-6.0.1.tgz#98966cba214378c8c84b82e085907b40bf614179"
|
||||
integrity sha512-jR2b5v7d2vIOust+w3wtFKZIfpC2pnRmFAhAC/BuweZFQR8qZzxH1OyrQ10HmdVYiXWkYUqPVsz91cG7EL2FBg==
|
||||
dependencies:
|
||||
universalify "^1.0.0"
|
||||
optionalDependencies:
|
||||
graceful-fs "^4.1.6"
|
||||
|
||||
lru-cache@^4.1.5:
|
||||
version "4.1.5"
|
||||
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-4.1.5.tgz#8bbe50ea85bed59bc9e33dcab8235ee9bcf443cd"
|
||||
|
@ -136,11 +95,6 @@ typescript@^4.0.3:
|
|||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.0.3.tgz#153bbd468ef07725c1df9c77e8b453f8d36abba5"
|
||||
integrity sha512-tEu6DGxGgRJPb/mVPIZ48e69xCn2yRmCgYmDugAVwmJ6o+0u1RI18eO7E7WBTLYLaEVVOhwQmcdhQHweux/WPg==
|
||||
|
||||
universalify@^1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/universalify/-/universalify-1.0.0.tgz#b61a1da173e8435b2fe3c67d29b9adf8594bd16d"
|
||||
integrity sha512-rb6X1W158d7pRQBg5gkR8uPaSfiids68LTJQYOtEUhoJUWBdaQHsuT/EUduxXYxcrt4r5PJ4fuHW1MHT6p0qug==
|
||||
|
||||
yallist@^2.1.2:
|
||||
version "2.1.2"
|
||||
resolved "https://registry.yarnpkg.com/yallist/-/yallist-2.1.2.tgz#1c11f9218f076089a47dd512f93c6699a6a81d52"
|
||||
|
|
Loading…
Reference in New Issue
Block a user