mirror of
https://github.com/SamKirkland/FTP-Deploy-Action.git
synced 2026-04-10 12:32:17 +02:00
v3.0.0
Complete rewrite! Switched from LFTP to git-ftp Upload diffs based on git history by default lower case kebab argument names Migrated from shell to typescript Added FTP and SFTP tests .git-ftp-ignore and .git-ftp-include support
This commit is contained in:
54
src/main.ts
Normal file
54
src/main.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import * as core from '@actions/core';
|
||||
import * as exec from '@actions/exec';
|
||||
import { IActionArguments } from './types';
|
||||
|
||||
async function run() {
|
||||
const userArguments = getUserArguments();
|
||||
|
||||
try {
|
||||
await syncFiles(userArguments);
|
||||
|
||||
console.log("✅ Deploy Complete");
|
||||
}
|
||||
catch (error) {
|
||||
console.error("⚠️ Error deploying");
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
run();
|
||||
|
||||
|
||||
function getUserArguments(): IActionArguments {
|
||||
return {
|
||||
ftp_server: core.getInput("ftp-server", { required: true }),
|
||||
ftp_username: core.getInput("ftp-username", { required: true }),
|
||||
ftp_password: core.getInput("ftp-password", { required: true }),
|
||||
local_dir: withDefault(core.getInput("local-dir"), "./"),
|
||||
gitFtpArgs: withDefault(core.getInput("git-ftp-args"), "")
|
||||
};
|
||||
}
|
||||
|
||||
function withDefault(value: string, defaultValue: string) {
|
||||
if (value === "" || value === null || value === undefined) {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sync changed files
|
||||
*/
|
||||
async function syncFiles(args: IActionArguments) {
|
||||
try {
|
||||
await core.group("Uploading files", async () => {
|
||||
return await exec.exec(`git ftp push --force --auto-init --verbose --syncroot ${args.local_dir} --user ${args.ftp_username} --passwd ${args.ftp_password} ${args.gitFtpArgs} ${args.ftp_server}`);
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
console.error("⚠️ Failed to upload files");
|
||||
core.setFailed(error.message);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user