Compare commits

8 Commits

Author SHA1 Message Date
SamKirkland
2a4e9b1312 Resolving sync state issue, added tests
fixes #124
fixes #122
fixes #120
2020-11-23 01:22:34 -06:00
Sam Kirkland
bc95d3edc3 Merge pull request #119 from SamKirkland/4.0.1-patch
4.0.1 patch
2020-11-13 13:58:32 -06:00
SamKirkland
5aee445d73 Update index.js 2020-11-13 13:49:44 -06:00
SamKirkland
3384765d40 removing array log 2020-11-13 13:49:12 -06:00
SamKirkland
6d1a190aef Fixing server sync state location 2020-11-13 13:42:37 -06:00
SamKirkland
8da6fdde60 exclude param - array parsing 2020-11-13 13:25:32 -06:00
SamKirkland
f0ef8012ea local-dir path, excludes param logging 2020-11-13 12:12:25 -06:00
Sam Kirkland
649aa38be8 Merge pull request #117 from SamKirkland/beta-v4
Version 4.0.0
2020-11-13 01:07:57 -06:00
11 changed files with 3992 additions and 284 deletions

View File

@@ -3,8 +3,6 @@ name: FTP Test
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
deploy:
@@ -12,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: 🚚 Get latest code
uses: actions/checkout@v2
uses: actions/checkout@v2.3.2
- name: 📂 Sync files
uses: ./

View File

@@ -3,8 +3,6 @@ name: FTPS Test
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
deploy:
@@ -12,13 +10,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: 🚚 Get latest code
uses: actions/checkout@v2
uses: actions/checkout@v2.3.2
- name: 📂 Sync files
uses: ./
with:
server: wwwssr16.supercp.com
server: ftp.samkirkland.com
username: test@samkirkland.com
password: ${{ secrets.ftp_password }}
protocol: ftps
secure: strict
security: strict

View File

@@ -56,7 +56,7 @@ To add a `secret` go to the `Settings` tab in your project then select `Secrets`
I strongly recommend you store your `password` as a secret.
| Key Name | Required | Example | Default Value | Description |
|-------------------------|----------|----------------------------|----------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|-------------------------|----------|----------------------------|---------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `server` | Yes | `ftp.samkirkland.com` | | Deployment destination server |
| `username` | Yes | `username@samkirkland.com` | | FTP user name |
| `password` | Yes | `CrazyUniquePassword&%123` | | FTP password, be sure to escape quotes and spaces |
@@ -67,7 +67,7 @@ I strongly recommend you store your `password` as a secret.
| `state-name` | No | `folder/.sync-state.json` | `.ftp-deploy-sync-state.json` | Path and name of the state file - this file is used to track which files have been deployed |
| `dry-run` | No | `true` | `false` | Prints which modifications will be made with current config options, but doesn't actually make any changes |
| `dangerous-clean-slate` | No | `true` | `false` | Deletes ALL contents of server-dir, even items in excluded with 'exclude' argument |
| `exclude` | No | | `.git*` `.git*/**` `node_modules/**` `node_modules/**/*` | An array of glob patterns, these files will not be included in the publish/delete process |
| `exclude` | No | | `[.git*, .git*/**, node_modules/**, node_modules/**/*]` | An array of glob patterns, these files will not be included in the publish/delete process |
| `log-level` | No | `minimal` | `standard` | `minimal`: only important info, `standard`: important info and basic file changes, `verbose`: print everything the script is doing |
| `security` | No | `strict` | `loose` | `strict`: Reject any connection which is not authorized with the list of supplied CAs. `loose`: Allow connection even when the domain is not certificate |

119
dist/index.js vendored
View File

@@ -1739,12 +1739,11 @@ exports.HashDiff = HashDiff;
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.prettyError = void 0;
const types_1 = __webpack_require__(6703);
function outputOriginalErrorAndExit(logger, error) {
function logOriginalError(logger, error) {
logger.all();
logger.all(`----------------------------------------------------------------`);
logger.all(`---------------------- Full Error below ----------------------`);
logger.all(error);
process.exit();
}
/**
* Converts a exception to helpful debug info
@@ -1755,41 +1754,36 @@ function prettyError(logger, args, error) {
logger.all(`----------------------------------------------------------------`);
logger.all(`--------------- 🔥🔥🔥 A error occurred 🔥🔥🔥 --------------`);
logger.all(`----------------------------------------------------------------`);
const ftpError = error;
if (typeof error.code === "string") {
const errorCode = error.code;
if (errorCode === "ENOTFOUND") {
logger.all(`The server "${args.server}" doesn't seem to exist. Do you have a typo?`);
outputOriginalErrorAndExit(logger, error);
}
}
if (typeof error.name === "string") {
else if (typeof error.name === "string") {
const errorName = error.name;
if (errorName.includes("ERR_TLS_CERT_ALTNAME_INVALID")) {
logger.all(`The certificate for "${args.server}" is likely shared. The host did not place your server on the list of valid domains for this cert.`);
logger.all(`This is a common issue with shared hosts. You have a few options:`);
logger.all(` - Ignore this error by setting security back to loose`);
logger.all(` - Contact your hosting provider and ask them for your servers hostname`);
outputOriginalErrorAndExit(logger, error);
}
}
const ftpError = error;
if (typeof ftpError.code === "number") {
else if (typeof ftpError.code === "number") {
if (ftpError.code === types_1.ErrorCode.NotLoggedIn) {
const serverRequiresFTPS = ftpError.message.toLowerCase().includes("must use encryption");
if (serverRequiresFTPS) {
logger.all(`The server you are connecting to requires encryption (ftps)`);
logger.all(`Enable FTPS by using the protocol option.`);
outputOriginalErrorAndExit(logger, error);
}
else {
logger.all(`Could not login with the username "${args.username}" and password "${args.password}".`);
logger.all(`Make sure you can login with those credentials. If you have a space or a quote in your username or password be sure to escape them!`);
outputOriginalErrorAndExit(logger, error);
}
}
}
// unknown error :(
outputOriginalErrorAndExit(logger, error);
logOriginalError(logger, error);
}
exports.prettyError = prettyError;
@@ -1833,7 +1827,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.deploy = exports.excludeDefaults = void 0;
exports.deploy = exports.getLocalFiles = exports.excludeDefaults = void 0;
const ftp = __importStar(__webpack_require__(7957));
const readdir_enhanced_1 = __importDefault(__webpack_require__(8811));
const crypto_1 = __importDefault(__webpack_require__(6417));
@@ -1902,7 +1896,7 @@ function getLocalFiles(args) {
type: "file",
name: stat.path,
size: stat.size,
hash: yield fileHash(stat.path, "sha256")
hash: yield fileHash(args["local-dir"] + stat.path, "sha256")
});
continue;
}
@@ -1912,12 +1906,13 @@ function getLocalFiles(args) {
}
return {
description: types_1.syncFileDescription,
version: types_1.currentVersion,
version: types_1.currentSyncFileVersion,
generatedTime: new Date().getTime(),
data: records
};
});
}
exports.getLocalFiles = getLocalFiles;
function downloadFileList(client, logger, path) {
return __awaiter(this, void 0, void 0, function* () {
// note: originally this was using a writable stream instead of a buffer file
@@ -2116,7 +2111,7 @@ function getServerFiles(client, logger, timings, args) {
// set the server state to nothing, because we don't know what the server state is
return {
description: types_1.syncFileDescription,
version: types_1.currentVersion,
version: types_1.currentSyncFileVersion,
generatedTime: new Date().getTime(),
data: [],
};
@@ -2182,7 +2177,9 @@ function syncLocalToServer(client, diffs, logger, timings, args) {
}
logger.all(`----------------------------------------------------------------`);
logger.all(`🎉 Sync complete. Saving current server state to "${args["server-dir"] + args["state-name"]}"`);
if (args["dry-run"] === false) {
yield utilities_1.retryRequest(logger, () => __awaiter(this, void 0, void 0, function* () { return yield client.uploadFrom(args["local-dir"] + args["state-name"], args["state-name"]); }));
}
});
}
function deploy(deployArgs) {
@@ -2192,9 +2189,8 @@ function deploy(deployArgs) {
const timings = new utilities_1.Timings();
timings.start("total");
// header
// todo allow swapping out library/version text based on if we are using action
logger.all(`----------------------------------------------------------------`);
logger.all(`🚀 Thanks for using ftp-deploy version ${types_1.currentVersion}. Let's deploy some stuff! `);
logger.all(`🚀 Thanks for using ftp-deploy. Let's deploy some stuff! `);
logger.all(`----------------------------------------------------------------`);
logger.all(`If you found this project helpful, please support it`);
logger.all(`by giving it a ⭐ on Github --> https://github.com/SamKirkland/FTP-Deploy-Action`);
@@ -2216,8 +2212,10 @@ function deploy(deployArgs) {
yield global.reconnect();
try {
const serverFiles = yield getServerFiles(client, logger, timings, args);
timings.start("logging");
const diffTool = new HashDiff_1.HashDiff();
const diffs = diffTool.getDiffs(localFiles, serverFiles, logger);
timings.stop("logging");
totalBytesUploaded = diffs.sizeUpload + diffs.sizeReplace;
timings.start("upload");
try {
@@ -2226,11 +2224,9 @@ function deploy(deployArgs) {
catch (e) {
if (e.code === types_1.ErrorCode.FileNameNotAllowed) {
logger.all("Error 553 FileNameNotAllowed, you don't have access to upload that file");
logger.all(e);
process.exit();
}
logger.all(e);
process.exit();
throw e;
}
finally {
timings.stop("upload");
@@ -2246,6 +2242,7 @@ function deploy(deployArgs) {
}
catch (error) {
errorHandling_1.prettyError(logger, args, error);
throw error;
}
finally {
client.close();
@@ -2258,6 +2255,7 @@ function deploy(deployArgs) {
logger.all(`Time spent connecting to server: ${timings.getTimeFormatted("connecting")}`);
logger.all(`Time spent deploying: ${timings.getTimeFormatted("upload")} (${uploadSpeed}/second)`);
logger.all(` - changing dirs: ${timings.getTimeFormatted("changingDir")}`);
logger.all(` - logging: ${timings.getTimeFormatted("logging")}`);
logger.all(`----------------------------------------------------------------`);
logger.all(`Total time: ${timings.getTimeFormatted("total")}`);
logger.all(`----------------------------------------------------------------`);
@@ -2274,8 +2272,8 @@ exports.deploy = deploy;
"use strict";
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.ErrorCode = exports.syncFileDescription = exports.currentVersion = void 0;
exports.currentVersion = "1.0.0";
exports.ErrorCode = exports.syncFileDescription = exports.currentSyncFileVersion = void 0;
exports.currentSyncFileVersion = "1.0.0";
exports.syncFileDescription = "DO NOT DELETE THIS FILE. This file is used to keep track of which files have been synced in the most recent deployment. If you delete this file a resync will need to be done (which can take a while) - read more: https://github.com/SamKirkland/FTP-Deploy-Action";
var ErrorCode;
(function (ErrorCode) {
@@ -3303,12 +3301,8 @@ class Client {
return res;
}
catch (err) {
// Receiving an FTPError means that the last transfer strategy failed and we should
// try the next one. Any other exception should stop the evaluation of strategies because
// something else went wrong.
if (!(err instanceof FtpContext_1.FTPError)) {
throw err;
}
// Try the next candidate no matter the exact error. It's possible that a server
// answered incorrectly to a strategy, for example a PASV answer to an EPSV.
}
}
throw new Error("None of the available transfer strategies work.");
@@ -3970,9 +3964,10 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.enterPassiveModeIPv6 = exports.enterPassiveModeIPv4 = void 0;
/**
* Public API
*/
@@ -4131,7 +4126,7 @@ function positiveIntermediate(code) {
}
exports.positiveIntermediate = positiveIntermediate;
function isNotBlank(str) {
return str !== "";
return str.trim() !== "";
}
@@ -4157,7 +4152,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
@@ -6556,23 +6551,24 @@ var __importStar = (this && this.__importStar) || function (mod) {
Object.defineProperty(exports, "__esModule", ({ value: true }));
const core = __importStar(__webpack_require__(2186));
const ftp_deploy_1 = __webpack_require__(8347);
const parse_1 = __webpack_require__(6089);
async function runDeployment() {
try {
const args = {
server: core.getInput("server", { required: true }),
username: core.getInput("username", { required: true }),
password: core.getInput("password", { required: true }),
port: optionalInt("port", core.getInput("port")),
protocol: optionalProtocol("protocol", core.getInput("protocol")),
"local-dir": optionalString(core.getInput("local-dir")),
"server-dir": optionalString(core.getInput("server-dir")),
"state-name": optionalString(core.getInput("state-name")),
"dry-run": optionalBoolean("dry-run", core.getInput("dry-run")),
"dangerous-clean-slate": optionalBoolean("dangerous-clean-slate", core.getInput("dangerous-clean-slate")),
"exclude": optionalStringArray("exclude", core.getInput("exclude")),
"log-level": optionalLogLevel("log-level", core.getInput("log-level")),
"security": optionalSecurity("security", core.getInput("security"))
port: parse_1.optionalInt("port", core.getInput("port")),
protocol: parse_1.optionalProtocol("protocol", core.getInput("protocol")),
"local-dir": parse_1.optionalString(core.getInput("local-dir")),
"server-dir": parse_1.optionalString(core.getInput("server-dir")),
"state-name": parse_1.optionalString(core.getInput("state-name")),
"dry-run": parse_1.optionalBoolean("dry-run", core.getInput("dry-run")),
"dangerous-clean-slate": parse_1.optionalBoolean("dangerous-clean-slate", core.getInput("dangerous-clean-slate")),
"exclude": parse_1.optionalStringArray("exclude", core.getInput("exclude")),
"log-level": parse_1.optionalLogLevel("log-level", core.getInput("log-level")),
"security": parse_1.optionalSecurity("security", core.getInput("security"))
};
try {
await ftp_deploy_1.deploy(args);
}
catch (error) {
@@ -6580,12 +6576,24 @@ async function runDeployment() {
}
}
runDeployment();
/***/ }),
/***/ 6089:
/***/ ((__unused_webpack_module, exports) => {
"use strict";
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.optionalStringArray = exports.optionalInt = exports.optionalSecurity = exports.optionalLogLevel = exports.optionalProtocol = exports.optionalBoolean = exports.optionalString = void 0;
function optionalString(rawValue) {
if (rawValue.length === 0) {
return undefined;
}
return rawValue;
}
exports.optionalString = optionalString;
function optionalBoolean(argumentName, rawValue) {
if (rawValue.length === 0) {
return undefined;
@@ -6597,8 +6605,9 @@ function optionalBoolean(argumentName, rawValue) {
if (cleanValue === "false") {
return false;
}
core.setFailed(`${argumentName}: invalid parameter - please use a boolean, you provided "${rawValue}". Try true or false instead.`);
throw new Error(`${argumentName}: invalid parameter - please use a boolean, you provided "${rawValue}". Try true or false instead.`);
}
exports.optionalBoolean = optionalBoolean;
function optionalProtocol(argumentName, rawValue) {
if (rawValue.length === 0) {
return undefined;
@@ -6613,8 +6622,9 @@ function optionalProtocol(argumentName, rawValue) {
if (cleanValue === "ftps-legacy") {
return "ftps-legacy";
}
core.setFailed(`${argumentName}: invalid parameter - you provided "${rawValue}". Try "ftp", "ftps", or "ftps-legacy" instead.`);
throw new Error(`${argumentName}: invalid parameter - you provided "${rawValue}". Try "ftp", "ftps", or "ftps-legacy" instead.`);
}
exports.optionalProtocol = optionalProtocol;
function optionalLogLevel(argumentName, rawValue) {
if (rawValue.length === 0) {
return undefined;
@@ -6629,8 +6639,9 @@ function optionalLogLevel(argumentName, rawValue) {
if (cleanValue === "verbose") {
return "verbose";
}
core.setFailed(`${argumentName}: invalid parameter - you provided "${rawValue}". Try "minimal", "standard", or "verbose" instead.`);
throw new Error(`${argumentName}: invalid parameter - you provided "${rawValue}". Try "minimal", "standard", or "verbose" instead.`);
}
exports.optionalLogLevel = optionalLogLevel;
function optionalSecurity(argumentName, rawValue) {
if (rawValue.length === 0) {
return undefined;
@@ -6642,8 +6653,9 @@ function optionalSecurity(argumentName, rawValue) {
if (cleanValue === "strict") {
return "strict";
}
core.setFailed(`${argumentName}: invalid parameter - you provided "${rawValue}". Try "loose" or "strict" instead.`);
throw new Error(`${argumentName}: invalid parameter - you provided "${rawValue}". Try "loose" or "strict" instead.`);
}
exports.optionalSecurity = optionalSecurity;
function optionalInt(argumentName, rawValue) {
if (rawValue.length === 0) {
return undefined;
@@ -6652,15 +6664,26 @@ function optionalInt(argumentName, rawValue) {
if (Number.isInteger(valueAsNumber)) {
return valueAsNumber;
}
core.setFailed(`${argumentName}: invalid parameter - you provided "${rawValue}". Try a whole number (no decimals) instead like 1234`);
throw new Error(`${argumentName}: invalid parameter - you provided "${rawValue}". Try a whole number (no decimals) instead like 1234`);
}
exports.optionalInt = optionalInt;
function optionalStringArray(argumentName, rawValue) {
if (rawValue.length === 0) {
return undefined;
}
const valueTrim = rawValue.trim();
if (valueTrim.startsWith("[")) {
// remove [ and ] - then convert to array
return rawValue.replace(/[\[\]]/g, "").trim().split(", ").filter(str => str !== "");
}
// split value by space and comma
return rawValue.split(", ");
const valueAsArrayDouble = rawValue.split(" - ").map(str => str.trim()).filter(str => str !== "");
if (valueAsArrayDouble.length) {
return valueAsArrayDouble;
}
throw new Error(`${argumentName}: invalid parameter - you provided "${rawValue}". This option excepts an array in the format [val1, val2] or val1\/n - val2`);
}
exports.optionalStringArray = optionalStringArray;
/***/ }),

3
jest.config.js Normal file
View File

@@ -0,0 +1,3 @@
module.exports = {
preset: "ts-jest"
};

3704
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -6,6 +6,7 @@
"main": "dist/index.js",
"scripts": {
"build": "ncc build src/main.ts --no-cache",
"test": "jest",
"lint": "eslint src/**/*.ts"
},
"repository": {
@@ -22,7 +23,10 @@
"license": "MIT",
"dependencies": {
"@actions/core": "^1.2.6",
"@samkirkland/ftp-deploy": "^1.0.0",
"@samkirkland/ftp-deploy": "^1.0.3",
"@types/jest": "^26.0.15",
"jest": "^26.6.3",
"ts-jest": "^26.4.4",
"ts-node-dev": "^1.0.0-pre.62"
},
"devDependencies": {

135
src/main.test.ts Normal file
View File

@@ -0,0 +1,135 @@
import { optionalBoolean, optionalInt, optionalLogLevel, optionalProtocol, optionalSecurity, optionalString, optionalStringArray } from "./parse";
describe("boolean", () => {
test("false", () => {
expect(optionalBoolean("test", "false")).toBe(false);
});
test("FALSE", () => {
expect(optionalBoolean("test", "FALSE")).toBe(false);
});
test("true", () => {
expect(optionalBoolean("test", "true")).toBe(true);
});
test("TRUE", () => {
expect(optionalBoolean("test", "TRUE")).toBe(true);
});
test("optional", () => {
expect(optionalBoolean("test", "")).toBe(undefined);
});
});
describe("string", () => {
test("empty", () => {
expect(optionalString("")).toBe(undefined);
});
test("populated", () => {
expect(optionalString("test")).toBe("test");
});
});
describe("int", () => {
test("empty", () => {
expect(optionalInt("test", "")).toBe(undefined);
});
test("0", () => {
expect(optionalInt("test", "0")).toBe(0);
});
test("1", () => {
expect(optionalInt("test", "1")).toBe(1);
});
test("500", () => {
expect(optionalInt("test", "500")).toBe(500);
});
test("non-int", () => {
expect(() => optionalInt("test", "12.345")).toThrow();
});
});
describe("protocol", () => {
test("empty", () => {
expect(optionalProtocol("test", "")).toBe(undefined);
});
test("ftp", () => {
expect(optionalProtocol("test", "ftp")).toBe("ftp");
});
test("ftps", () => {
expect(optionalProtocol("test", "ftps")).toBe("ftps");
});
test("ftps-legacy", () => {
expect(optionalProtocol("test", "ftps-legacy")).toBe("ftps-legacy");
});
});
describe("log level", () => {
test("empty", () => {
expect(optionalLogLevel("test", "")).toBe(undefined);
});
test("minimal", () => {
expect(optionalLogLevel("test", "minimal")).toBe("minimal");
});
test("standard", () => {
expect(optionalLogLevel("test", "standard")).toBe("standard");
});
test("verbose", () => {
expect(optionalLogLevel("test", "verbose")).toBe("verbose");
});
});
describe("security", () => {
test("empty", () => {
expect(optionalSecurity("test", "")).toBe(undefined);
});
test("loose", () => {
expect(optionalSecurity("test", "loose")).toBe("loose");
});
test("strict", () => {
expect(optionalSecurity("test", "strict")).toBe("strict");
});
});
describe("array", () => {
test("empty", () => {
expect(optionalStringArray("test", "")).toEqual(undefined);
});
test("empty array", () => {
expect(optionalStringArray("test", "[]")).toEqual([]);
});
test(`["test.txt"]`, () => {
expect(optionalStringArray("test", "[test.txt]")).toEqual(["test.txt"]);
});
test(`[ "test.txt" ]`, () => {
expect(optionalStringArray("test", "[ test.txt ]")).toEqual(["test.txt"]);
});
test(`["test.txt", "folder/**/*"]`, () => {
expect(optionalStringArray("test", "[test.txt, folder/**/*]")).toEqual(["test.txt", "folder/**/*"]);
});
test(`["test.txt", "folder/**/*", "*other"]`, () => {
expect(optionalStringArray("test", `test.txt\n - folder/**/*\n - *other`)).toEqual(["test.txt", "folder/**/*", "*other"]);
});
test(`["test.txt", "folder/**/*", "*other"]`, () => {
expect(optionalStringArray("test", `\n - test.txt\n - folder/**/*\n - *other`)).toEqual(["test.txt", "folder/**/*", "*other"]);
});
});

View File

@@ -1,8 +1,10 @@
import * as core from "@actions/core";
import { deploy } from "@samkirkland/ftp-deploy";
import { IFtpDeployArguments } from "@samkirkland/ftp-deploy/dist/types";
import { optionalInt, optionalProtocol, optionalString, optionalBoolean, optionalStringArray, optionalLogLevel, optionalSecurity } from "./parse";
async function runDeployment() {
try {
const args: IFtpDeployArguments = {
server: core.getInput("server", { required: true }),
username: core.getInput("username", { required: true }),
@@ -19,8 +21,6 @@ async function runDeployment() {
"security": optionalSecurity("security", core.getInput("security"))
};
try {
await deploy(args);
}
catch (error) {
@@ -29,110 +29,3 @@ async function runDeployment() {
}
runDeployment();
function optionalString(rawValue: string): string | undefined {
if (rawValue.length === 0) {
return undefined;
}
return rawValue;
}
function optionalBoolean(argumentName: string, rawValue: string): boolean | undefined {
if (rawValue.length === 0) {
return undefined;
}
const cleanValue = rawValue.toLowerCase();
if (cleanValue === "true") {
return true;
}
if (cleanValue === "false") {
return false;
}
core.setFailed(`${argumentName}: invalid parameter - please use a boolean, you provided "${rawValue}". Try true or false instead.`);
}
function optionalProtocol(argumentName: string, rawValue: string): "ftp" | "ftps" | "ftps-legacy" | undefined {
if (rawValue.length === 0) {
return undefined;
}
const cleanValue = rawValue.toLowerCase();
if (cleanValue === "ftp") {
return "ftp";
}
if (cleanValue === "ftps") {
return "ftps";
}
if (cleanValue === "ftps-legacy") {
return "ftps-legacy";
}
core.setFailed(`${argumentName}: invalid parameter - you provided "${rawValue}". Try "ftp", "ftps", or "ftps-legacy" instead.`);
}
function optionalLogLevel(argumentName: string, rawValue: string): "minimal" | "standard" | "verbose" | undefined {
if (rawValue.length === 0) {
return undefined;
}
const cleanValue = rawValue.toLowerCase();
if (cleanValue === "minimal") {
return "minimal";
}
if (cleanValue === "standard") {
return "standard";
}
if (cleanValue === "verbose") {
return "verbose";
}
core.setFailed(`${argumentName}: invalid parameter - you provided "${rawValue}". Try "minimal", "standard", or "verbose" instead.`);
}
function optionalSecurity(argumentName: string, rawValue: string): "loose" | "strict" | undefined {
if (rawValue.length === 0) {
return undefined;
}
const cleanValue = rawValue.toLowerCase();
if (cleanValue === "loose") {
return "loose";
}
if (cleanValue === "strict") {
return "strict";
}
core.setFailed(`${argumentName}: invalid parameter - you provided "${rawValue}". Try "loose" or "strict" instead.`);
}
function optionalInt(argumentName: string, rawValue: string): number | undefined {
if (rawValue.length === 0) {
return undefined;
}
const valueAsNumber = parseFloat(rawValue);
if (Number.isInteger(valueAsNumber)) {
return valueAsNumber;
}
core.setFailed(`${argumentName}: invalid parameter - you provided "${rawValue}". Try a whole number (no decimals) instead like 1234`);
}
function optionalStringArray(argumentName: string, rawValue: string): string[] | undefined {
if (rawValue.length === 0) {
return undefined;
}
// split value by space and comma
return rawValue.split(", ");
}

113
src/parse.ts Normal file
View File

@@ -0,0 +1,113 @@
export function optionalString(rawValue: string): string | undefined {
if (rawValue.length === 0) {
return undefined;
}
return rawValue;
}
export function optionalBoolean(argumentName: string, rawValue: string): boolean | undefined {
if (rawValue.length === 0) {
return undefined;
}
const cleanValue = rawValue.toLowerCase();
if (cleanValue === "true") {
return true;
}
if (cleanValue === "false") {
return false;
}
throw new Error(`${argumentName}: invalid parameter - please use a boolean, you provided "${rawValue}". Try true or false instead.`);
}
export function optionalProtocol(argumentName: string, rawValue: string): "ftp" | "ftps" | "ftps-legacy" | undefined {
if (rawValue.length === 0) {
return undefined;
}
const cleanValue = rawValue.toLowerCase();
if (cleanValue === "ftp") {
return "ftp";
}
if (cleanValue === "ftps") {
return "ftps";
}
if (cleanValue === "ftps-legacy") {
return "ftps-legacy";
}
throw new Error(`${argumentName}: invalid parameter - you provided "${rawValue}". Try "ftp", "ftps", or "ftps-legacy" instead.`);
}
export function optionalLogLevel(argumentName: string, rawValue: string): "minimal" | "standard" | "verbose" | undefined {
if (rawValue.length === 0) {
return undefined;
}
const cleanValue = rawValue.toLowerCase();
if (cleanValue === "minimal") {
return "minimal";
}
if (cleanValue === "standard") {
return "standard";
}
if (cleanValue === "verbose") {
return "verbose";
}
throw new Error(`${argumentName}: invalid parameter - you provided "${rawValue}". Try "minimal", "standard", or "verbose" instead.`);
}
export function optionalSecurity(argumentName: string, rawValue: string): "loose" | "strict" | undefined {
if (rawValue.length === 0) {
return undefined;
}
const cleanValue = rawValue.toLowerCase();
if (cleanValue === "loose") {
return "loose";
}
if (cleanValue === "strict") {
return "strict";
}
throw new Error(`${argumentName}: invalid parameter - you provided "${rawValue}". Try "loose" or "strict" instead.`);
}
export function optionalInt(argumentName: string, rawValue: string): number | undefined {
if (rawValue.length === 0) {
return undefined;
}
const valueAsNumber = parseFloat(rawValue);
if (Number.isInteger(valueAsNumber)) {
return valueAsNumber;
}
throw new Error(`${argumentName}: invalid parameter - you provided "${rawValue}". Try a whole number (no decimals) instead like 1234`);
}
export function optionalStringArray(argumentName: string, rawValue: string): string[] | undefined {
if (rawValue.length === 0) {
return undefined;
}
const valueTrim = rawValue.trim();
if (valueTrim.startsWith("[")) {
// remove [ and ] - then convert to array
return rawValue.replace(/[\[\]]/g, "").trim().split(", ").filter(str => str !== "");
}
// split value by space and comma
const valueAsArrayDouble = rawValue.split(" - ").map(str => str.trim()).filter(str => str !== "");
if (valueAsArrayDouble.length) {
return valueAsArrayDouble;
}
throw new Error(`${argumentName}: invalid parameter - you provided "${rawValue}". This option excepts an array in the format [val1, val2] or val1\/n - val2`);
}

View File

@@ -10,6 +10,7 @@
"noEmit": true
},
"exclude": [
"node_modules"
"node_modules",
"**/.test.ts"
]
}