mirror of
				https://github.com/SamKirkland/FTP-Deploy-Action.git
				synced 2025-10-31 19:54:01 +00:00 
			
		
		
		
	Resolving sync state issue, added tests
fixes #124 fixes #122 fixes #120
This commit is contained in:
		
							parent
							
								
									bc95d3edc3
								
							
						
					
					
						commit
						2a4e9b1312
					
				
							
								
								
									
										2
									
								
								.github/workflows/ftps.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.github/workflows/ftps.yml
									
									
									
									
										vendored
									
									
								
							| @ -15,7 +15,7 @@ jobs: | |||||||
|       - name: 📂 Sync files |       - name: 📂 Sync files | ||||||
|         uses: ./ |         uses: ./ | ||||||
|         with: |         with: | ||||||
|           server: wwwssr16.supercp.com |           server: ftp.samkirkland.com | ||||||
|           username: test@samkirkland.com |           username: test@samkirkland.com | ||||||
|           password: ${{ secrets.ftp_password }} |           password: ${{ secrets.ftp_password }} | ||||||
|           protocol: ftps |           protocol: ftps | ||||||
|  | |||||||
							
								
								
									
										30
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										30
									
								
								README.md
									
									
									
									
									
								
							| @ -55,21 +55,21 @@ Keys can be added directly to your .yml config file or referenced from your proj | |||||||
| To add a `secret` go to the `Settings` tab in your project then select `Secrets`. | 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. | I strongly recommend you store your `password` as a secret. | ||||||
| 
 | 
 | ||||||
| | Key Name                | Required | Example                    | Default Value                                            | Description                                                                                                                                                        | | | Key Name                | Required | Example                    | Default Value                                           | Description                                                                                                                                                        | | ||||||
| |-------------------------|----------|----------------------------|----------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------| | |-------------------------|----------|----------------------------|---------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ||||||
| | `server`                | Yes      | `ftp.samkirkland.com`      |                                                          | Deployment destination server                                                                                                                                      | | | `server`                | Yes      | `ftp.samkirkland.com`      |                                                         | Deployment destination server                                                                                                                                      | | ||||||
| | `username`              | Yes      | `username@samkirkland.com` |                                                          | FTP user name                                                                                                                                                      | | | `username`              | Yes      | `username@samkirkland.com` |                                                         | FTP user name                                                                                                                                                      | | ||||||
| | `password`              | Yes      | `CrazyUniquePassword&%123` |                                                          | FTP password, be sure to escape quotes and spaces                                                                                                                  | | | `password`              | Yes      | `CrazyUniquePassword&%123` |                                                         | FTP password, be sure to escape quotes and spaces                                                                                                                  | | ||||||
| | `port`                  | No       | `990`                      | `21`                                                     | Server port to connect to (read your web hosts docs)                                                                                                               | | | `port`                  | No       | `990`                      | `21`                                                    | Server port to connect to (read your web hosts docs)                                                                                                               | | ||||||
| | `protocol`              | No       | `ftps`                     | `ftp`                                                    | `ftp`: provides no encryption, `ftps`: full encryption newest standard (aka "explicit" ftps), `ftps-legacy`: full encryption legacy standard (aka "implicit" ftps) | | | `protocol`              | No       | `ftps`                     | `ftp`                                                   | `ftp`: provides no encryption, `ftps`: full encryption newest standard (aka "explicit" ftps), `ftps-legacy`: full encryption legacy standard (aka "implicit" ftps) | | ||||||
| | `local-dir`             | No       | `./myFolderToPublish/`     | `./`                                                     | Path to upload to on the server, must end with trailing slash `/`                                                                                                  | | | `local-dir`             | No       | `./myFolderToPublish/`     | `./`                                                    | Path to upload to on the server, must end with trailing slash `/`                                                                                                  | | ||||||
| | `server-dir`            | No       | `public_html/www/`         | `./`                                                     | Folder to upload from, must end with trailing slash `/`                                                                                                            | | | `server-dir`            | No       | `public_html/www/`         | `./`                                                    | Folder to upload from, must end with trailing slash `/`                                                                                                            | | ||||||
| | `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                                                                        | | | `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                                                         | | | `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                                                                                 | | | `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                                 | | | `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           | | | `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           | | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| # Common Examples | # Common Examples | ||||||
|  | |||||||
							
								
								
									
										75
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										75
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
								
							| @ -2178,7 +2178,7 @@ function syncLocalToServer(client, diffs, logger, timings, args) { | |||||||
|         logger.all(`----------------------------------------------------------------`); |         logger.all(`----------------------------------------------------------------`); | ||||||
|         logger.all(`🎉 Sync complete. Saving current server state to "${args["server-dir"] + args["state-name"]}"`); |         logger.all(`🎉 Sync complete. Saving current server state to "${args["server-dir"] + args["state-name"]}"`); | ||||||
|         if (args["dry-run"] === false) { |         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["server-dir"] + args["state-name"]); })); |             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"]); })); | ||||||
|         } |         } | ||||||
|     }); |     }); | ||||||
| } | } | ||||||
| @ -2189,9 +2189,8 @@ function deploy(deployArgs) { | |||||||
|         const timings = new utilities_1.Timings(); |         const timings = new utilities_1.Timings(); | ||||||
|         timings.start("total"); |         timings.start("total"); | ||||||
|         // header
 |         // header
 | ||||||
|         // todo allow swapping out library/version text based on if we are using action
 |  | ||||||
|         logger.all(`----------------------------------------------------------------`); |         logger.all(`----------------------------------------------------------------`); | ||||||
|         logger.all(`🚀 Thanks for using ftp-deploy version ${types_1.currentSyncFileVersion}. Let's deploy some stuff!   `); |         logger.all(`🚀 Thanks for using ftp-deploy. Let's deploy some stuff!   `); | ||||||
|         logger.all(`----------------------------------------------------------------`); |         logger.all(`----------------------------------------------------------------`); | ||||||
|         logger.all(`If you found this project helpful, please support it`); |         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`); |         logger.all(`by giving it a ⭐ on Github --> https://github.com/SamKirkland/FTP-Deploy-Action`); | ||||||
| @ -6552,23 +6551,24 @@ var __importStar = (this && this.__importStar) || function (mod) { | |||||||
| Object.defineProperty(exports, "__esModule", ({ value: true })); | Object.defineProperty(exports, "__esModule", ({ value: true })); | ||||||
| const core = __importStar(__webpack_require__(2186)); | const core = __importStar(__webpack_require__(2186)); | ||||||
| const ftp_deploy_1 = __webpack_require__(8347); | const ftp_deploy_1 = __webpack_require__(8347); | ||||||
|  | const parse_1 = __webpack_require__(6089); | ||||||
| async function runDeployment() { | async function runDeployment() { | ||||||
|     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")) |  | ||||||
|     }; |  | ||||||
|     try { |     try { | ||||||
|  |         const args = { | ||||||
|  |             server: core.getInput("server", { required: true }), | ||||||
|  |             username: core.getInput("username", { required: true }), | ||||||
|  |             password: core.getInput("password", { required: true }), | ||||||
|  |             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")) | ||||||
|  |         }; | ||||||
|         await ftp_deploy_1.deploy(args); |         await ftp_deploy_1.deploy(args); | ||||||
|     } |     } | ||||||
|     catch (error) { |     catch (error) { | ||||||
| @ -6576,12 +6576,24 @@ async function runDeployment() { | |||||||
|     } |     } | ||||||
| } | } | ||||||
| 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) { | function optionalString(rawValue) { | ||||||
|     if (rawValue.length === 0) { |     if (rawValue.length === 0) { | ||||||
|         return undefined; |         return undefined; | ||||||
|     } |     } | ||||||
|     return rawValue; |     return rawValue; | ||||||
| } | } | ||||||
|  | exports.optionalString = optionalString; | ||||||
| function optionalBoolean(argumentName, rawValue) { | function optionalBoolean(argumentName, rawValue) { | ||||||
|     if (rawValue.length === 0) { |     if (rawValue.length === 0) { | ||||||
|         return undefined; |         return undefined; | ||||||
| @ -6593,8 +6605,9 @@ function optionalBoolean(argumentName, rawValue) { | |||||||
|     if (cleanValue === "false") { |     if (cleanValue === "false") { | ||||||
|         return 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) { | function optionalProtocol(argumentName, rawValue) { | ||||||
|     if (rawValue.length === 0) { |     if (rawValue.length === 0) { | ||||||
|         return undefined; |         return undefined; | ||||||
| @ -6609,8 +6622,9 @@ function optionalProtocol(argumentName, rawValue) { | |||||||
|     if (cleanValue === "ftps-legacy") { |     if (cleanValue === "ftps-legacy") { | ||||||
|         return "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) { | function optionalLogLevel(argumentName, rawValue) { | ||||||
|     if (rawValue.length === 0) { |     if (rawValue.length === 0) { | ||||||
|         return undefined; |         return undefined; | ||||||
| @ -6625,8 +6639,9 @@ function optionalLogLevel(argumentName, rawValue) { | |||||||
|     if (cleanValue === "verbose") { |     if (cleanValue === "verbose") { | ||||||
|         return "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) { | function optionalSecurity(argumentName, rawValue) { | ||||||
|     if (rawValue.length === 0) { |     if (rawValue.length === 0) { | ||||||
|         return undefined; |         return undefined; | ||||||
| @ -6638,8 +6653,9 @@ function optionalSecurity(argumentName, rawValue) { | |||||||
|     if (cleanValue === "strict") { |     if (cleanValue === "strict") { | ||||||
|         return "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) { | function optionalInt(argumentName, rawValue) { | ||||||
|     if (rawValue.length === 0) { |     if (rawValue.length === 0) { | ||||||
|         return undefined; |         return undefined; | ||||||
| @ -6648,15 +6664,26 @@ function optionalInt(argumentName, rawValue) { | |||||||
|     if (Number.isInteger(valueAsNumber)) { |     if (Number.isInteger(valueAsNumber)) { | ||||||
|         return 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) { | function optionalStringArray(argumentName, rawValue) { | ||||||
|     if (rawValue.length === 0) { |     if (rawValue.length === 0) { | ||||||
|         return undefined; |         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
 |     // split value by space and comma
 | ||||||
|     return rawValue.split(" - ").filter(str => str !== ""); |     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
									
								
							
							
						
						
									
										3
									
								
								jest.config.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,3 @@ | |||||||
|  | module.exports = { | ||||||
|  |     preset: "ts-jest" | ||||||
|  | }; | ||||||
							
								
								
									
										3696
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										3696
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @ -1,11 +1,12 @@ | |||||||
| { | { | ||||||
|   "name": "ftp-deploy-action", |   "name": "ftp-deploy-action", | ||||||
|   "version": "4.0.1", |   "version": "4.0.0", | ||||||
|   "private": true, |   "private": true, | ||||||
|   "description": "Automate deploying websites and more with this GitHub action", |   "description": "Automate deploying websites and more with this GitHub action", | ||||||
|   "main": "dist/index.js", |   "main": "dist/index.js", | ||||||
|   "scripts": { |   "scripts": { | ||||||
|     "build": "ncc build src/main.ts --no-cache", |     "build": "ncc build src/main.ts --no-cache", | ||||||
|  |     "test": "jest", | ||||||
|     "lint": "eslint src/**/*.ts" |     "lint": "eslint src/**/*.ts" | ||||||
|   }, |   }, | ||||||
|   "repository": { |   "repository": { | ||||||
| @ -22,7 +23,10 @@ | |||||||
|   "license": "MIT", |   "license": "MIT", | ||||||
|   "dependencies": { |   "dependencies": { | ||||||
|     "@actions/core": "^1.2.6", |     "@actions/core": "^1.2.6", | ||||||
|     "@samkirkland/ftp-deploy": "^1.0.2", |     "@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" |     "ts-node-dev": "^1.0.0-pre.62" | ||||||
|   }, |   }, | ||||||
|   "devDependencies": { |   "devDependencies": { | ||||||
|  | |||||||
							
								
								
									
										135
									
								
								src/main.test.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										135
									
								
								src/main.test.ts
									
									
									
									
									
										Normal 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"]); | ||||||
|  |     }); | ||||||
|  | }); | ||||||
							
								
								
									
										141
									
								
								src/main.ts
									
									
									
									
									
								
							
							
						
						
									
										141
									
								
								src/main.ts
									
									
									
									
									
								
							| @ -1,26 +1,26 @@ | |||||||
| import * as core from "@actions/core"; | import * as core from "@actions/core"; | ||||||
| import { deploy } from "@samkirkland/ftp-deploy"; | import { deploy } from "@samkirkland/ftp-deploy"; | ||||||
| import { IFtpDeployArguments } from "@samkirkland/ftp-deploy/dist/types"; | import { IFtpDeployArguments } from "@samkirkland/ftp-deploy/dist/types"; | ||||||
|  | import { optionalInt, optionalProtocol, optionalString, optionalBoolean, optionalStringArray, optionalLogLevel, optionalSecurity } from "./parse"; | ||||||
| 
 | 
 | ||||||
| async function runDeployment() { | async function runDeployment() { | ||||||
|   const args: IFtpDeployArguments = { |  | ||||||
|     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")) |  | ||||||
|   }; |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
|   try { |   try { | ||||||
|  |     const args: IFtpDeployArguments = { | ||||||
|  |       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")) | ||||||
|  |     }; | ||||||
|  | 
 | ||||||
|     await deploy(args); |     await deploy(args); | ||||||
|   } |   } | ||||||
|   catch (error) { |   catch (error) { | ||||||
| @ -29,110 +29,3 @@ async function runDeployment() { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 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(" - ").filter(str => str !== ""); |  | ||||||
| } |  | ||||||
|  | |||||||
							
								
								
									
										113
									
								
								src/parse.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										113
									
								
								src/parse.ts
									
									
									
									
									
										Normal 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`); | ||||||
|  | } | ||||||
| @ -10,6 +10,7 @@ | |||||||
|     "noEmit": true |     "noEmit": true | ||||||
|   }, |   }, | ||||||
|   "exclude": [ |   "exclude": [ | ||||||
|     "node_modules" |     "node_modules", | ||||||
|  |     "**/.test.ts" | ||||||
|   ] |   ] | ||||||
| } | } | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user