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:
SamKirkland
2020-02-18 00:34:10 -06:00
parent e62d32ee89
commit 4895f6f251
19 changed files with 6597 additions and 178 deletions

54
src/main.ts Normal file
View 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;
}
}

28
src/types.ts Normal file
View File

@@ -0,0 +1,28 @@
export interface IActionArguments {
ftp_server: string | undefined;
ftp_username: string | undefined;
ftp_password: string | undefined;
/** @default "." */
local_dir: string | undefined;
/** @default "" */
gitFtpArgs: string | undefined;
}
/**
* @see https://github.com/git-ftp/git-ftp/blob/master/man/git-ftp.1.md#exit-codes
*/
export enum gitFTPExitCode {
Successful = 0,
UnknownError = 1,
WrongUsage = 2,
MissingArguments = 3,
ErrorWhileUploading = 4,
ErrorWhileDownloading = 5,
UnknownProtocol = 6,
RemoteLocked = 7,
NotAGitProject = 8,
PreFTPPushHookFailed = 9,
LocalFileOperationFailed = 10
}