Skip to content

Commit 4100f21

Browse files
Fix package imports
1 parent 87be85a commit 4100f21

4 files changed

Lines changed: 25 additions & 19 deletions

File tree

hetzner.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import axios from 'axios'
1+
const axios = require("axios")
22

3-
export class Hetzner {
3+
class Hetzner {
44
constructor(token) {
55
this.axios = axios.create({
66
baseURL: 'https://api.hetzner.cloud/v1',
@@ -44,11 +44,11 @@ export class Hetzner {
4444
}
4545
}
4646

47-
export const findServer = (hetznerServerResponse, ip) => {
47+
const findServer = (hetznerServerResponse, ip) => {
4848
return hetznerServerResponse.servers.find(s => s.public_net.ipv4.ip === ip)
4949
}
5050

51-
export const findLoadbalancersWithServer = (hetznerLoadbalancersResponse, serverId) => {
51+
const findLoadbalancersWithServer = (hetznerLoadbalancersResponse, serverId) => {
5252
const lbs = []
5353

5454
for (const lb of hetznerLoadbalancersResponse.load_balancers) {
@@ -59,3 +59,9 @@ export const findLoadbalancersWithServer = (hetznerLoadbalancersResponse, server
5959

6060
return lbs
6161
}
62+
63+
module.exports = {
64+
Hetzner,
65+
findServer,
66+
findLoadbalancersWithServer
67+
}

index.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import core from '@actions/core'
2-
import {runCommands, ServerConnection} from "./ssh.js"
3-
import {findLoadbalancersWithServer, findServer, Hetzner} from "./hetzner.js"
1+
const core = require("@actions/core")
2+
const {ServerConnection, runCommands} = require("./ssh")
3+
const {Hetzner, findServer, findLoadbalancersWithServer} = require("./hetzner")
44

55
const options = {
66
SSH_KEY: core.getInput('ssh_key', { required: true }),
@@ -40,7 +40,7 @@ async function run() {
4040
const deployOutput = await runCommands(sshConnection, options.COMMANDS)
4141

4242
core.startGroup('Commands output')
43-
deployOutput.forEach(o => core.info)
43+
deployOutput.forEach(core.info)
4444
core.endGroup()
4545

4646
core.info(`Inserting ${server.name}(${ip}) into loadbalancer (${lb.name})`)
@@ -88,10 +88,6 @@ function sleep(ms) {
8888
return new Promise(resolve => setTimeout(resolve, ms))
8989
}
9090

91-
try {
92-
core.info('Starting deploy')
93-
await run()
94-
}
95-
catch (err) {
96-
core.setFailed(`Action failed with error ${err}`);
97-
}
91+
core.info('Starting deploy')
92+
run().catch(err => core.setFailed(`Action failed with error ${err}`))
93+

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"version": "1.0.0",
44
"description": "Rolling deployments using Hetzner Loadbalancers for zero downtime deployments.",
55
"main": "index.js",
6-
"type": "module",
76
"scripts": {
87
"start": "index.js"
98
},

ssh.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import {Client} from 'ssh2'
1+
const {Client} = require('ssh2')
22

3-
export class ServerConnection {
3+
class ServerConnection {
44
constructor(host, port, username, key) {
55
this.host = host
66
this.port = port
@@ -9,7 +9,7 @@ export class ServerConnection {
99
}
1010
}
1111

12-
export const runCommands = (sshConnection, commands) => {
12+
const runCommands = (sshConnection, commands) => {
1313
return new Promise((resolve, reject) => {
1414
const conn = new Client()
1515

@@ -60,3 +60,8 @@ function executeCommand(conn, cmd) {
6060
})
6161
})
6262
}
63+
64+
module.exports = {
65+
ServerConnection,
66+
runCommands
67+
}

0 commit comments

Comments
 (0)