From 9dc51bfe9af64bfe180177883349faf589258c13 Mon Sep 17 00:00:00 2001 From: BetaHuhn Date: Fri, 16 Apr 2021 14:41:17 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Use=20fs-extra=20instead=20of=20?= =?UTF-8?q?actions/io=20#15?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 16 +++------------- package.json | 2 +- src/config.js | 3 +-- src/helpers.js | 22 +++++++++++++++++++--- src/index.js | 10 ++++------ 5 files changed, 28 insertions(+), 25 deletions(-) diff --git a/package-lock.json b/package-lock.json index d8de241e..4fa73d49 100644 --- a/package-lock.json +++ b/package-lock.json @@ -86,11 +86,6 @@ "tunnel": "0.0.6" } }, - "@actions/io": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/@actions/io/-/io-1.1.0.tgz", - "integrity": "sha512-PspSX7Z9zh2Fyyuf3F6BsYeXcYHfc/VJ1vwy2vouas95efHVd42M6UfBFRs+jY0uiMDXhAoUtATn9g2r1MaWBQ==" - }, "@babel/code-frame": { "version": "7.12.11", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.12.11.tgz", @@ -737,8 +732,7 @@ "at-least-node": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/at-least-node/-/at-least-node-1.0.0.tgz", - "integrity": "sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==", - "dev": true + "integrity": "sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==" }, "atob-lite": { "version": "2.0.0", @@ -1625,7 +1619,6 @@ "version": "9.1.0", "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-9.1.0.tgz", "integrity": "sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ==", - "dev": true, "requires": { "at-least-node": "^1.0.0", "graceful-fs": "^4.2.0", @@ -1818,8 +1811,7 @@ "graceful-fs": { "version": "4.2.6", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.6.tgz", - "integrity": "sha512-nTnJ528pbqxYanhpDYsi4Rd8MAeaBA67+RZ10CM1m3bTAVFEDcd5AuA4a6W5YkGZ1iNXHzZz8T6TBKLeBuNriQ==", - "dev": true + "integrity": "sha512-nTnJ528pbqxYanhpDYsi4Rd8MAeaBA67+RZ10CM1m3bTAVFEDcd5AuA4a6W5YkGZ1iNXHzZz8T6TBKLeBuNriQ==" }, "handlebars": { "version": "4.7.7", @@ -2177,7 +2169,6 @@ "version": "6.1.0", "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", - "dev": true, "requires": { "graceful-fs": "^4.1.6", "universalify": "^2.0.0" @@ -5756,8 +5747,7 @@ "universalify": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz", - "integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==", - "dev": true + "integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==" }, "uri-js": { "version": "4.4.1", diff --git a/package.json b/package.json index bacf8e21..6c2cf863 100644 --- a/package.json +++ b/package.json @@ -29,9 +29,9 @@ "dependencies": { "@actions/core": "^1.2.7", "@actions/github": "^2.2.0", - "@actions/io": "^1.1.0", "@putout/git-status-porcelain": "^1.1.0", "dotenv": "^8.2.0", + "fs-extra": "^9.1.0", "js-yaml": "^4.1.0" }, "devDependencies": { diff --git a/src/config.js b/src/config.js index 43958993..fda3aef6 100644 --- a/src/config.js +++ b/src/config.js @@ -1,6 +1,6 @@ const core = require('@actions/core') const yaml = require('js-yaml') -const fs = require('fs') +const fs = require('fs-extra') require('dotenv').config() @@ -126,7 +126,6 @@ const parseRepoName = (fullRepo) => { } } - const parseFiles = (files) => { return files.map((item) => { diff --git a/src/helpers.js b/src/helpers.js index c837567e..25fbdeaf 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -1,4 +1,4 @@ -const fs = require('fs') +const fs = require('fs-extra') const { exec } = require('child_process') const core = require('@actions/core') @@ -55,14 +55,30 @@ const execCmd = (command, workingDir) => { const addTrailingSlash = (str) => str.endsWith('/') ? str : str + '/' const pathIsDirectory = async (path) => { - const stat = await fs.promises.lstat(path) + const stat = await fs.lstat(path) return stat.isDirectory() } +const copy = async (src, dest) => { + + core.debug(`CP: ${ src } TO ${ dest }`) + + return fs.copy(src, dest) +} + +const remove = async (src) => { + + core.debug(`RM: ${ src }`) + + return fs.remove(src) +} + module.exports = { forEach, dedent, addTrailingSlash, pathIsDirectory, - execCmd + execCmd, + copy, + remove } \ No newline at end of file diff --git a/src/index.js b/src/index.js index 31795ad1..6d3436fa 100644 --- a/src/index.js +++ b/src/index.js @@ -1,10 +1,9 @@ const core = require('@actions/core') const github = require('@actions/github') -const io = require('@actions/io') const fs = require('fs') const Git = require('./git') -const { forEach, dedent, addTrailingSlash, pathIsDirectory } = require('./helpers') +const { forEach, dedent, addTrailingSlash, pathIsDirectory, copy, remove } = require('./helpers') const { parseConfig, @@ -70,12 +69,11 @@ const run = async () => { if (isDirectory) core.warning(`Source is directory`) - core.debug(`Copying ${ source } to ${ localDestination }`) - await io.cp(source, localDestination, { recursive: true, force: true }) + await copy(source, localDestination) await git.add(file.dest) - // Commit each file separately, if option is set to false, commit all files at once later + // Commit each file separately, if option is set to false commit all files at once later if (COMMIT_EACH_FILE === true) { const hasChanges = await git.hasChanges() @@ -192,7 +190,7 @@ const run = async () => { return } - await io.rmRF(TMP_DIR) + await remove(TMP_DIR) core.info('Cleanup complete') }