Skip to content

Commit

Permalink
🐛 Use fs-extra instead of actions/io #15
Browse files Browse the repository at this point in the history
  • Loading branch information
BetaHuhn committed Apr 16, 2021
1 parent bd44655 commit 9dc51bf
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 25 deletions.
16 changes: 3 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
3 changes: 1 addition & 2 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -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()

Expand Down Expand Up @@ -126,7 +126,6 @@ const parseRepoName = (fullRepo) => {
}
}


const parseFiles = (files) => {
return files.map((item) => {

Expand Down
22 changes: 19 additions & 3 deletions src/helpers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const fs = require('fs')
const fs = require('fs-extra')
const { exec } = require('child_process')
const core = require('@actions/core')

Expand Down Expand Up @@ -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
}
10 changes: 4 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -192,7 +190,7 @@ const run = async () => {
return
}

await io.rmRF(TMP_DIR)
await remove(TMP_DIR)
core.info('Cleanup complete')
}

Expand Down

0 comments on commit 9dc51bf

Please sign in to comment.