diff --git a/README.md b/README.md index ccde115..4873b60 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ I recommend you store your `ftp-password` as a secret. | `local-dir` | No | deploy/ | ./ | Which local folder to deploy, path should be relative to the root and should include trailing slash. `./` is the root of the project | | `git-ftp-args` | No | See `git-ftp-args` section below | | Custom git-ftp arguments, this field is passed through directly into the git-ftp script | | `known-hosts` | No | hostname ssh-rsa AAAAB3NzaC1y ... | | The desired contents of your .ssh/known_hosts file. See [known hosts setup](#known-hosts-setup) | +| `ignore-github` | No | false | true | Ignore the `.github` folder when deploying. For security reasons, the `.github`-folder is excluded from the deployed files per default | #### Advanced options using `git-ftp-args` Custom arguments, this field is passed through directly into the git-ftp script. See [git-ftp's manual](https://github.com/git-ftp/git-ftp/blob/master/man/git-ftp.1.md) for all options. diff --git a/action.yml b/action.yml index 42ba065..89cbde7 100644 --- a/action.yml +++ b/action.yml @@ -15,6 +15,10 @@ inputs: description: 'The local folder to copy, defaults to root project folder' defaults: ./ required: false + ignore-github: + description: 'Whether the .github directory should be excluded from synchronization' + default: "true" + required: false git-ftp-args: description: 'Passes through options into git-ftp' defaults: diff --git a/src/main.ts b/src/main.ts index ffb3699..1cf718f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -5,12 +5,14 @@ import { promisify } from 'util'; import { IActionArguments } from './types'; const writeFileAsync = promisify(fs.writeFile); +const appendFileAsync = promisify(fs.appendFile); async function run() { const userArguments = getUserArguments(); try { await configureHost(userArguments); + await excludeGithub(userArguments); await syncFiles(userArguments); console.log("✅ Deploy Complete"); @@ -33,7 +35,7 @@ async function configureHost(args: IActionArguments): Promise { await exec.exec(`mkdir -v -p ${sshFolder}`); await exec.exec(`chmod 700 ${sshFolder}`); - writeFileAsync(`${sshFolder}/known_hosts`, args.knownHosts); + await writeFileAsync(`${sshFolder}/known_hosts`, args.knownHosts); await exec.exec(`chmod 755 ${sshFolder}/known_hosts`); console.log("✅ Configured known_hosts"); @@ -44,6 +46,19 @@ async function configureHost(args: IActionArguments): Promise { } } +async function excludeGithub(args: IActionArguments) { + if (args.ignoreGithub?.toLowerCase() != "true") { + return; + } + + try { + await appendFileAsync(".git-ftp-ignore", "\n.github"); + } catch (error) { + console.error("⚠️ Error adding .github-folder to .git-ftp-ignore", error); + core.setFailed(error); + throw error; + } +} function getUserArguments(): IActionArguments { return { ftp_server: core.getInput("ftp-server", { required: true }), @@ -51,7 +66,8 @@ function getUserArguments(): IActionArguments { ftp_password: core.getInput("ftp-password", { required: true }), local_dir: withDefault(core.getInput("local-dir"), "./"), gitFtpArgs: withDefault(core.getInput("git-ftp-args"), ""), - knownHosts: withDefault(core.getInput("known-hosts"), "") + knownHosts: withDefault(core.getInput("known-hosts"), ""), + ignoreGithub: withDefault(core.getInput("ignore-github"), "true"), }; } diff --git a/src/types.ts b/src/types.ts index 9110ddc..1dc4be4 100644 --- a/src/types.ts +++ b/src/types.ts @@ -11,6 +11,9 @@ export interface IActionArguments { /** @default "" */ knownHosts: string | undefined; + + /** @default "true" */ + ignoreGithub: string | undefined; } /**