mirror of
https://github.com/SamKirkland/FTP-Deploy-Action.git
synced 2026-04-10 12:32:17 +02:00
Compare commits
29 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d0aa838726 | ||
|
|
f55279346a | ||
|
|
93a0898871 | ||
|
|
1d31526b7a | ||
|
|
d3fa328f10 | ||
|
|
d6ad227aa5 | ||
|
|
c7bb3d9877 | ||
|
|
a7da5e54d2 | ||
|
|
a9644610a0 | ||
|
|
825d1b8f3b | ||
|
|
ba86a1bf13 | ||
|
|
65c6a8f943 | ||
|
|
d2724c6194 | ||
|
|
59992de6c6 | ||
|
|
408fa95d1f | ||
|
|
223d805d5b | ||
|
|
3695ee6be8 | ||
|
|
ca38d85340 | ||
|
|
a7d2862205 | ||
|
|
1cffb780cf | ||
|
|
2d118d9190 | ||
|
|
2a4e9b1312 | ||
|
|
bc95d3edc3 | ||
|
|
5aee445d73 | ||
|
|
3384765d40 | ||
|
|
6d1a190aef | ||
|
|
8da6fdde60 | ||
|
|
f0ef8012ea | ||
|
|
649aa38be8 |
5
.github/workflows/ftp.yml
vendored
5
.github/workflows/ftp.yml
vendored
@@ -2,9 +2,7 @@ name: FTP Test
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
branches: [master]
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
@@ -20,4 +18,3 @@ jobs:
|
||||
server: ftp.samkirkland.com
|
||||
username: test@samkirkland.com
|
||||
password: ${{ secrets.ftp_password }}
|
||||
|
||||
|
||||
7
.github/workflows/ftps.yml
vendored
7
.github/workflows/ftps.yml
vendored
@@ -2,9 +2,7 @@ name: FTPS Test
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
branches: [master]
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
@@ -17,8 +15,7 @@ jobs:
|
||||
- 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
|
||||
|
||||
73
README.md
73
README.md
@@ -20,10 +20,10 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: 🚚 Get latest code
|
||||
uses: actions/checkout@v2.3.2
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: 📂 Sync files
|
||||
uses: SamKirkland/FTP-Deploy-Action@4.0.0
|
||||
uses: SamKirkland/FTP-Deploy-Action@4.3.0
|
||||
with:
|
||||
server: ftp.samkirkland.com
|
||||
username: myFtpUserName
|
||||
@@ -56,18 +56,18 @@ 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 |
|
||||
| `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) |
|
||||
| `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 `/` |
|
||||
| `local-dir` | No | `./myFolderToPublish/` | `./` | Folder to upload from, must end with trailing slash `/` |
|
||||
| `server-dir` | No | `public_html/www/` | `./` | Folder to upload to (on the server), 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 |
|
||||
| `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 | [See Example](#exclude-files) | [See Example](#exclude-files) | An array of glob patterns, these files will not be included in the publish/delete process. [List MUST be in this format](#exclude-files). You can use [a glob tester](https://www.digitalocean.com/community/tools/glob?comments=true&glob=%2A%2A%2F.git%2A%2F%2A%2A&matches=false&tests=test%2Fsam&tests=.git%2F&tests=.github%2F&tests=.git%2Ftest&tests=.gitattributes&tests=.gitignore&tests=.git%2Fconfig&tests=.git%2Ftest%2Ftest&tests=.github%2Fworkflows%2Fmain.yml&tests=test%2F.git%2Fworkflows%2Fmain.yml&tests=node_modules%2Ffolder%2F&tests=node_modules%2Fotherfolder%2F&tests=subfolder%2Fnode_modules%2F) to test your pattern(s). |
|
||||
| `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 |
|
||||
|
||||
@@ -85,12 +85,12 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: 🚚 Get latest code
|
||||
uses: actions/checkout@v2.3.2
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Use Node.js 12
|
||||
uses: actions/setup-node@v2-beta
|
||||
- name: Use Node.js 14
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: '12'
|
||||
node-version: '14'
|
||||
|
||||
- name: 🔨 Build Project
|
||||
run: |
|
||||
@@ -98,7 +98,7 @@ jobs:
|
||||
npm run build
|
||||
|
||||
- name: 📂 Sync files
|
||||
uses: SamKirkland/FTP-Deploy-Action@4.0.0
|
||||
uses: SamKirkland/FTP-Deploy-Action@4.3.0
|
||||
with:
|
||||
server: ftp.samkirkland.com
|
||||
username: myFtpUserName
|
||||
@@ -115,10 +115,10 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: 🚚 Get latest code
|
||||
uses: actions/checkout@v2.3.2
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: 📂 Sync files
|
||||
uses: SamKirkland/FTP-Deploy-Action@4.0.0
|
||||
uses: SamKirkland/FTP-Deploy-Action@4.3.0
|
||||
with:
|
||||
server: ftp.samkirkland.com
|
||||
username: myFtpUserName
|
||||
@@ -127,7 +127,7 @@ jobs:
|
||||
port: 1234 # todo replace with your web hosts ftps port
|
||||
```
|
||||
|
||||
#### Log only dry run: Use this mode for testing
|
||||
#### Log only dry run: Use this option for testing
|
||||
Ouputs a list of files that will be created/modified to sync your source without making any actual changes
|
||||
```yml
|
||||
on: push
|
||||
@@ -138,10 +138,10 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: 🚚 Get latest code
|
||||
uses: actions/checkout@v2.3.2
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: 📂 Sync files
|
||||
uses: SamKirkland/FTP-Deploy-Action@4.0.0
|
||||
uses: SamKirkland/FTP-Deploy-Action@4.3.0
|
||||
with:
|
||||
server: ftp.samkirkland.com
|
||||
username: myFtpUserName
|
||||
@@ -149,6 +149,44 @@ jobs:
|
||||
dry-run: true
|
||||
```
|
||||
|
||||
#### Exclude files
|
||||
Excludes files
|
||||
```yml
|
||||
on: push
|
||||
name: 🚀 Deploy website on push
|
||||
jobs:
|
||||
web-deploy:
|
||||
name: 🎉 Deploy
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: 🚚 Get latest code
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: 📂 Sync files
|
||||
uses: SamKirkland/FTP-Deploy-Action@4.3.0
|
||||
with:
|
||||
server: ftp.samkirkland.com
|
||||
username: myFtpUserName
|
||||
password: ${{ secrets.password }}
|
||||
exclude: |
|
||||
**/.git*
|
||||
**/.git*/**
|
||||
**/node_modules/**
|
||||
fileToExclude.txt
|
||||
```
|
||||
|
||||
`exclude` has the following default value
|
||||
```yml
|
||||
exclude: |
|
||||
**/.git*
|
||||
**/.git*/**
|
||||
**/node_modules/**
|
||||
```
|
||||
if you overwrite the default value you will probably want to respecify them
|
||||
|
||||
|
||||
---
|
||||
|
||||
_Want another example? Let me know by creating a [github issue](https://github.com/SamKirkland/FTP-Deploy-Action/issues/new)_
|
||||
|
||||
---
|
||||
@@ -210,7 +248,8 @@ Git files are excluded by default! If you customize the `exclude` option make su
|
||||
You can use the `exclude` option to ignore specific files/folders from the publish. Keep in mind you will need to re-add the default exclude options if you want to keep them. For example the below option excludes all `.txt` files.
|
||||
|
||||
```yml
|
||||
exclude: '*.txt'
|
||||
exclude:
|
||||
- *.txt
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
40
action.yml
40
action.yml
@@ -1,49 +1,49 @@
|
||||
name: 'FTP Deploy'
|
||||
description: 'Automate deploying websites and more with this GitHub action'
|
||||
author: 'Sam Kirkland'
|
||||
name: "FTP Deploy"
|
||||
description: "Automate deploying websites and more with this GitHub action via FTP and FTPS"
|
||||
author: "Sam Kirkland"
|
||||
inputs:
|
||||
server:
|
||||
required: true
|
||||
description: 'ftp server'
|
||||
description: "ftp server"
|
||||
username:
|
||||
required: true
|
||||
description: 'ftp username'
|
||||
description: "ftp username"
|
||||
password:
|
||||
required: true
|
||||
description: 'ftp password'
|
||||
description: "ftp password"
|
||||
port:
|
||||
required: false
|
||||
description: 'Server port to connect to (read your web hosts docs)'
|
||||
description: "Server port to connect to (read your web hosts docs)"
|
||||
protocol:
|
||||
required: false
|
||||
description: 'protocol to deploy with - ftp, ftps, or ftps-legacy'
|
||||
description: "protocol to deploy with - ftp, ftps, or ftps-legacy"
|
||||
local-dir:
|
||||
required: false
|
||||
description: 'Folder to upload from, must end with trailing slash /'
|
||||
description: "Folder to upload from, must end with trailing slash /"
|
||||
server-dir:
|
||||
required: false
|
||||
description: 'Path to upload to on the server. Must end with trailing slash /'
|
||||
description: "Path to upload to on the server. Must end with trailing slash /"
|
||||
state-name:
|
||||
required: false
|
||||
description: 'Path and name of the state file - this file is used to track which files have been deployed'
|
||||
description: "Path and name of the state file - this file is used to track which files have been deployed"
|
||||
dry-run:
|
||||
required: false
|
||||
description: 'Prints which modifications will be made with current config options, but doesnt actually make any changes'
|
||||
description: "Prints which modifications will be made with current config options, but doesnt actually make any changes"
|
||||
dangerous-clean-slate:
|
||||
required: false
|
||||
description: 'Deletes ALL contents of server-dir, even items in excluded with exclude argument'
|
||||
description: "Deletes ALL contents of server-dir, even items in excluded with exclude argument"
|
||||
exclude:
|
||||
required: false
|
||||
description: 'An array of glob patterns, these files will not be included in the publish/delete process'
|
||||
description: "An array of glob patterns, these files will not be included in the publish/delete process"
|
||||
log-level:
|
||||
required: false
|
||||
description: 'How verbose should the information be - warn, info, debug'
|
||||
description: "How verbose should the information be - minimal, standard, or verbose"
|
||||
security:
|
||||
required: false
|
||||
description: 'strict or loose'
|
||||
description: "strict or loose"
|
||||
runs:
|
||||
using: 'node12'
|
||||
main: 'dist/index.js'
|
||||
using: "node12"
|
||||
main: "dist/index.js"
|
||||
branding:
|
||||
icon: 'upload-cloud'
|
||||
color: 'orange'
|
||||
icon: "upload-cloud"
|
||||
color: "orange"
|
||||
|
||||
2584
dist/index.js
vendored
2584
dist/index.js
vendored
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 12 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 7.9 KiB |
3
jest.config.js
Normal file
3
jest.config.js
Normal file
@@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
preset: "ts-jest"
|
||||
};
|
||||
17
migration.md
17
migration.md
@@ -1,3 +1,18 @@
|
||||
# Migrating from v4.1.0 to v4.2.0
|
||||
|
||||
`v4.2.0` parses the `exclude` option in a more standard way.
|
||||
|
||||
Going forward the `exclude` option **must** be in the following format
|
||||
```yml
|
||||
exclude: |
|
||||
**/.git*
|
||||
**/.git*/**
|
||||
**/node_modules/**
|
||||
fileToExclude.txt
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
# Migrating from v3 to v4
|
||||
|
||||
Migrating from v3 to v4 should be fairly straightforward. Version 4 was designed with speed and ease of initial setup in mind. Going forward version 4 will be the only supported version.
|
||||
@@ -12,7 +27,7 @@ Most features have been carried forward and improved upon. However, some feature
|
||||
### How to upgrade
|
||||
|
||||
1) Remove `with: fetch-depth: 2`. It is no longer needed and removing it will _slightly_ speed up deployments.
|
||||
2) Change the version to `4.X.X`, for example `SamKirkland/FTP-Deploy-Action@4.0.0` (please check readme for latest version)
|
||||
2) Change the version to `4.X.X`, for example `SamKirkland/FTP-Deploy-Action@4.1.0` (please check readme for latest version)
|
||||
3) If you have a `.git-ftp-include` file you should delete it. Version 4 tracks files differently and no longer needs this config file.
|
||||
4) If you have a `.git-ftp-ignore` file, you should transfer the options to the new `exclude` argument. _Note: Version 4 excludes any `.git*` and `node_modules/` files/folders by default_
|
||||
5) Update your arguments to reflect the following changes
|
||||
|
||||
5616
package-lock.json
generated
5616
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
25
package.json
25
package.json
@@ -1,11 +1,12 @@
|
||||
{
|
||||
"name": "ftp-deploy-action",
|
||||
"version": "4.0.0",
|
||||
"version": "4.3.0",
|
||||
"private": true,
|
||||
"description": "Automate deploying websites and more with this GitHub action",
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
"build": "ncc build src/main.ts --no-cache",
|
||||
"test": "jest",
|
||||
"lint": "eslint src/**/*.ts"
|
||||
},
|
||||
"repository": {
|
||||
@@ -13,24 +14,28 @@
|
||||
"url": "git+https://github.com/SamKirkland/FTP-Deploy-Action.git"
|
||||
},
|
||||
"keywords": [
|
||||
"ftp",
|
||||
"website deploy",
|
||||
"continuous integration",
|
||||
"ftp",
|
||||
"ftps"
|
||||
],
|
||||
"author": "Sam Kirkland",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.2.6",
|
||||
"@samkirkland/ftp-deploy": "^1.0.0",
|
||||
"ts-node-dev": "^1.0.0-pre.62"
|
||||
"@actions/core": "^1.6.0",
|
||||
"@samkirkland/ftp-deploy": "^1.2.1",
|
||||
"@types/jest": "^27.0.2",
|
||||
"jest": "^27.2.5",
|
||||
"ts-jest": "^27.0.5",
|
||||
"ts-node-dev": "^1.1.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^14.0.27",
|
||||
"@typescript-eslint/parser": "^4.0.1",
|
||||
"@vercel/ncc": "^0.24.0",
|
||||
"eslint": "^7.8.1",
|
||||
"js-yaml": "^3.14.0",
|
||||
"typescript": "^4.0.2"
|
||||
"@typescript-eslint/eslint-plugin": "^4.28.0",
|
||||
"@typescript-eslint/parser": "^4.33.0",
|
||||
"@vercel/ncc": "^0.31.1",
|
||||
"eslint": "^7.29.0",
|
||||
"eslint-plugin-jest": "^24.3.6",
|
||||
"typescript": "^4.4.3"
|
||||
}
|
||||
}
|
||||
|
||||
105
src/main.test.ts
Normal file
105
src/main.test.ts
Normal file
@@ -0,0 +1,105 @@
|
||||
import { optionalBoolean, optionalInt, optionalLogLevel, optionalProtocol, optionalSecurity, optionalString } 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");
|
||||
});
|
||||
});
|
||||
115
src/main.ts
115
src/main.ts
@@ -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 }),
|
||||
@@ -14,125 +16,16 @@ async function runDeployment() {
|
||||
"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")),
|
||||
"exclude": optionalStringArray("exclude", core.getMultilineInput("exclude")),
|
||||
"log-level": optionalLogLevel("log-level", core.getInput("log-level")),
|
||||
"security": optionalSecurity("security", core.getInput("security"))
|
||||
};
|
||||
|
||||
|
||||
try {
|
||||
await deploy(args);
|
||||
}
|
||||
catch (error) {
|
||||
catch (error: any) {
|
||||
core.setFailed(error);
|
||||
}
|
||||
}
|
||||
|
||||
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(", ");
|
||||
}
|
||||
|
||||
103
src/parse.ts
Normal file
103
src/parse.ts
Normal file
@@ -0,0 +1,103 @@
|
||||
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;
|
||||
}
|
||||
|
||||
if (typeof rawValue === "string") {
|
||||
throw new Error(`${argumentName}: invalid parameter - you provided "${rawValue}". This option expects an list in the EXACT format described in the readme`);
|
||||
}
|
||||
|
||||
return rawValue;
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"moduleResolution": "Node",
|
||||
"target": "ES2019", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
|
||||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
|
||||
"outDir": "./dist", /* Redirect output structure to the directory. */
|
||||
@@ -10,6 +11,7 @@
|
||||
"noEmit": true
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
"node_modules",
|
||||
"**/.test.ts"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user