Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
2ue committed Apr 29, 2024
1 parent 447490a commit fb91bca
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 33 deletions.
24 changes: 8 additions & 16 deletions dist/index.js

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

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

24 changes: 8 additions & 16 deletions main/main.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
const SSH2SftpClient = require('ssh2-sftp-client')
const core = require('@actions/core')
const { execSync } = require('child_process')
const path = require('path')

async function run() {
console.log('-----enter----')
execSync('pwd', { stdio: 'inherit' })
execSync('ls -al', { stdio: 'inherit' })
const sftp = new SSH2SftpClient()
const sftp = new SSH2SftpClient('upload')
const host = core.getInput('host', { required: true })
const port = core.getInput('port') || 22
const username = core.getInput('username', { required: true })
Expand All @@ -24,14 +23,12 @@ async function run() {
// const retry_factor = core.getInput('retry_factor')
// const retry_minTimeout = core.getInput('retry_minTimeout')
// const promiseLimit = core.getInput('promiseLimit')
const localDir1 = core.getInput('local_dir', { required: true })
const localDir = path.join(__dirname, localDir1)
const localDir = core.getInput('local_dir', { required: true })
const remoteBaseDir = core.getInput('remote_base_dir', { required: true })
// const remoteBakPath = core.getInput('remote_bak_path')
try {
console.log('Start connect: ', localDir1, localDir)
execSync('pwd', { stdio: 'inherit' })
execSync(`ls -al ${localDir1}`, { stdio: 'inherit' })
core.info('Start connect: ', localDir, localDir)
execSync(`ls -al ${localDir}`, { stdio: 'inherit' })
await sftp.connect({
host,
port,
Expand All @@ -54,25 +51,20 @@ async function run() {
// console.log('Start Backup: ', remoteBaseDir, '=>', remoteBakPath)
// await sftp.rcopy(remoteBaseDir, `${remoteBakPath}/backup`)
// }
console.log('Start upload: ', localDir1, '=>', remoteBaseDir)
const rslt = await sftp.uploadDir(localDir1, remoteBaseDir, {
core.info('Start upload: ', localDir, '=>', remoteBaseDir)
await sftp.uploadDir(localDir, remoteBaseDir, {
filter: (localPath, isDir) => {
core.debug('Upload: ', localPath, isDir)
return true
}
})
console.log('upload result:', rslt)
console.log(
`Successfully uploaded directory ${localDir} to ${remoteBaseDir}`
)
core.info(`Successfully uploaded directory ${localDir} to ${remoteBaseDir}`)
} catch (error) {
console.log('upload error:', error)
// @ts-ignore
core.setFailed(`Error uploading directory: ${error.message}`)
throw error
} finally {
if (sftp) {
await sftp.end()
sftp.end()
}
}
}
Expand Down

0 comments on commit fb91bca

Please sign in to comment.