Skip to content

Commit 18e4691

Browse files
Refactored options object
1 parent 29870d6 commit 18e4691

2 files changed

Lines changed: 16 additions & 17 deletions

File tree

index.js

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,24 @@ import core from '@actions/core'
22
import {runCommands, ServerConnection} from "./ssh.js"
33
import {findLoadbalancersWithServer, findServer, Hetzner} from "./hetzner.js"
44

5-
const SSH_KEY = core.getInput('ssh_key', { required: true })
6-
let SSH_PORT = core.getInput('ssh_port') || "22"
7-
const SSH_USER = core.getInput('ssh_port') || "root"
8-
const HETZNER_API_TOKEN = core.getInput('hetzner_token', { required: true })
9-
const COMMANDS = core.getMultilineInput('commands', { required: true })
10-
let GRACEFUL_WAIT = core.getInput('graceful_wait_seconds') || 30
11-
const SERVERS = core.getInput('servers', { required: true }).split(',').map(s => s.trim())
12-
13-
GRACEFUL_WAIT = parseInt(GRACEFUL_WAIT)
14-
SSH_PORT = parseInt(SSH_PORT)
5+
const options = {
6+
SSH_KEY: core.getInput('ssh_key', { required: true }),
7+
SSH_PORT: core.getInput('ssh_port') || "22",
8+
SSH_USER: core.getInput('ssh_port') || "root",
9+
HETZNER_API_TOKEN: core.getInput('hetzner_token', { required: true }),
10+
COMMANDS: core.getMultilineInput('commands', { required: true }),
11+
GRACEFUL_WAIT: core.getInput('graceful_wait_seconds') || 30,
12+
SERVERS: core.getInput('servers', { required: true }).split(',').map(s => s.trim())
13+
}
1514

16-
const hetzner = new Hetzner(HETZNER_API_TOKEN)
15+
const hetzner = new Hetzner(options.HETZNER_API_TOKEN)
1716

1817
async function run() {
1918
const hetznerServers = await hetzner.getServers()
2019
const hetznerLoadbalancers = await hetzner.getLoadbalancers()
2120

22-
for (let ip of SERVERS) {
23-
const sshConnection = new ServerConnection(ip, SSH_PORT, SSH_USER, SSH_KEY)
21+
for (let ip of options.SERVERS) {
22+
const sshConnection = new ServerConnection(ip, options.SSH_PORT, options.SSH_USER, options.SSH_KEY)
2423
const server = findServer(hetznerServers, ip)
2524
const lbsWithThisServer = findLoadbalancersWithServer(hetznerLoadbalancers, server.id)
2625

@@ -32,13 +31,13 @@ async function run() {
3231
throw new Error("Failed to remove the target server from the loadbalancer")
3332
}
3433

35-
core.info(`Waiting ${GRACEFUL_WAIT} seconds for the server to finish inflight requests`)
34+
core.info(`Waiting ${options.GRACEFUL_WAIT} seconds for the server to finish inflight requests`)
3635

3736
// Wait a few seconds so the server can finish the inflight requests
38-
await sleep(GRACEFUL_WAIT * 1000)
37+
await sleep(parseInt(options.GRACEFUL_WAIT) * 1000)
3938

4039
core.info(`Running deploy commands`)
41-
const deployOutput = await runCommands(sshConnection, COMMANDS)
40+
const deployOutput = await runCommands(sshConnection, options.COMMANDS)
4241

4342
core.startGroup('Commands output')
4443
deployOutput.forEach(o => core.info)

ssh.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const runCommands = (sshConnection, commands) => {
3131

3232
conn.connect({
3333
host: sshConnection.host,
34-
port: sshConnection.port,
34+
port: parseInt(sshConnection.port),
3535
username: sshConnection.username,
3636
privateKey: sshConnection.key
3737
})

0 commit comments

Comments
 (0)