Skip to content

Commit beb56cd

Browse files
committed
Merge branch 'develop'
2 parents 27bd32c + a796c9f commit beb56cd

File tree

12 files changed

+27084
-120
lines changed

12 files changed

+27084
-120
lines changed

.github/dependabot.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: github-actions
4+
directory: /
5+
schedule:
6+
interval: weekly
7+
groups:
8+
actions-minor:
9+
update-types:
10+
- minor
11+
- patch
12+
13+
- package-ecosystem: npm
14+
directory: /
15+
schedule:
16+
interval: weekly
17+
groups:
18+
npm-development:
19+
dependency-type: development
20+
update-types:
21+
- minor
22+
- patch
23+
npm-production:
24+
dependency-type: production
25+
update-types:
26+
- patch

.github/workflows/test.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
branches:
66
- main
7+
- develop
78
pull_request:
89

910
jobs:
@@ -22,9 +23,9 @@ jobs:
2223
- name: Test OpenVPN
2324
uses: "./"
2425
with:
25-
config_file: ${{ secrets.VPN_CONFIG_FILE }}
26+
config_file: ${{ secrets.VPN_CONFIG }}
2627
certificate: ${{ secrets.VPN_CERTIFICATE }}
2728
certificate_name: ${{ secrets.VPN_CERTIFICATE_NAME }}
2829

2930
- name: Check if connected
30-
run: curl -v http://172.16.0.61
31+
run: ping -c 1 -W 5 172.16.0.61 >/dev/null && echo 'Successfully pinged device!'

.husky/pre-commit

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
. "$(dirname "$0")/_/husky.sh"
33

44
npm install
5-
nom run build
6-
git add dist/index.js
5+
npm run build
6+
git add dist_main/index.js dist_post/index.js

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,19 @@ To use this action, you need to provide the necessary configuration details for
2121
certificate_name: ${{ secrets.VPN_CERTIFICATE_NAME }}
2222
```
2323
24-
Make sure to store your sensitive information (such as the config, certificate, and certificate_name) as secrets in your GitHub repository to keep them secure.
24+
Make sure to store your sensitive information (such as the config, certificate, and certificate_name) as secrets in your GitHub repository to keep them secure.
2525
26-
For more information on how to use this action, please refer to the [GitHub Action documentation](https://docs.github.com/actions).
26+
The certificate will need to be converted to base 64 before you can save the value as a GitHub secret.
27+
28+
```shell
29+
# Mac/Linux
30+
base64 <file_name> > output.txt
31+
32+
# Windows
33+
certutil -encode <file_name> output.txt
34+
```
35+
Replace `<file_name>` with the name of the file you want to encode. The encoded output will be saved in `output.txt`.
36+
37+
Remember to replace `<file_name>` with the actual name of the file you want to encode.
2738

39+
For more information on how to use this action, please refer to the [GitHub Action documentation](https://docs.github.com/actions).

action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ inputs:
1616
default: "certificate.p12"
1717
runs:
1818
using: "node20"
19-
main: "dist/index.js"
20-
post: "dist/index.js"
19+
main: "dist_main/index.js"
20+
post: "dist_post/index.js"

dist/index.js renamed to dist_main/index.js

Lines changed: 33 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -25378,6 +25378,7 @@ const core = __nccwpck_require__(2186);
2537825378
const exec = (command) => {
2537925379
core.info(`Executing ${command}`);
2538025380
const result = shelljsExec(command);
25381+
core.debug(JSON.stringify(result));
2538125382
if (result.code !== 0) {
2538225383
core.warning(result.stdout);
2538325384
throw new Error(
@@ -25397,89 +25398,69 @@ module.exports = exec;
2539725398

2539825399
const fs = __nccwpck_require__(7147);
2539925400
const core = __nccwpck_require__(2186);
25400-
const exec = __nccwpck_require__(1861);
25401+
const exec = __nccwpck_require__(3264);
2540125402
const Tail = (__nccwpck_require__(5824)/* .Tail */ .x);
2540225403

2540325404
/*global clearTimeout, setTimeout*/
2540425405
/*eslint no-undef: "error"*/
2540525406

2540625407
const run = (callback) => {
2540725408
const configFile = core.getInput("config_file", { required: true });
25409+
const configFileName = "config.ovpn";
2540825410
const certificate = core.getInput("certificate", { required: true });
25411+
const certificateName = core.getInput("certificate_name", { required: true });
25412+
const openVpnLog = "openvpn.log";
2540925413

25410-
if (!fs.existsSync(configFile)) {
25411-
throw new Error(`Config file not found: ${configFile}`);
25412-
}
25414+
// If the certificate is base64 encoded, decode it and write it to a temporary file
25415+
exec(`echo "${configFile}" > ${configFileName}`);
2541325416

25414-
fs.appendFileSync(configFile, "\n# -- GHA Modified --\n");
25417+
if (!fs.existsSync(configFileName)) {
25418+
throw new Error(`Config file not found: ${configFileName}`);
25419+
}
2541525420

2541625421
// If the certificate is base64 encoded, decode it and write it to a temporary file
25417-
exec(`echo "${certificate}" | base64 -d > /tmp/certificate.p12`);
25422+
exec(`echo "${certificate}" | base64 -d > ${certificateName}`);
2541825423

25419-
fs.writeFileSync("/tmp/openvpn.log", "");
25420-
const tail = new Tail("/tmp/openvpn.log");
25424+
if (!fs.existsSync(`${certificateName}`)) {
25425+
throw new Error(`Config file not found: ${certificateName}`);
25426+
}
25427+
25428+
fs.appendFileSync(configFile, "\n# -- GHA Modified --\n");
25429+
25430+
fs.writeFileSync(openVpnLog, "");
25431+
const tail = new Tail(openVpnLog);
2542125432

2542225433
try {
2542325434
exec(
25424-
`sudo openvpn --config ${configFile} --pkcs12 /tmp/certificate.p12 --daemon --log /tmp/openvpn.log --writepid openvpn.pid`,
25435+
`sudo openvpn --config ${configFileName} --pkcs12 ${certificateName} --daemon --log ${openVpnLog} --writepid openvpn.pid`,
2542525436
);
2542625437
} catch (error) {
2542725438
core.error(`Error starting OpenVPN: ${error.message}`);
2542825439
throw error;
2542925440
}
2543025441

2543125442
tail.on("line", (line) => {
25432-
core.info(line);
25433-
if (line.includes("Initialization Sequence Completed")) {
25434-
core.info("OpenVPN started successfully");
25443+
core.debug(line);
25444+
if (line.includes("Peer Connection Initiated with")) {
2543525445
tail.unwatch();
2543625446
clearTimeout(timer);
2543725447
const pid = fs.readFileSync("openvpn.pid", "utf8").trim();
2543825448
core.info(`OpenVPN connected successfully with PID ${pid}`);
25449+
core.info(`Sleeping for 5 seconds to allow connection to stabilize`);
25450+
exec(`sleep 5`);
2543925451
callback(pid);
2544025452
}
2544125453
});
2544225454

2544325455
const timer = setTimeout(() => {
25444-
core.setFailed("OpenVPN failed to start within 30 seconds");
25445-
}, 30000);
25456+
core.setFailed("OpenVPN failed to start within 15 seconds");
25457+
tail.unwatch();
25458+
}, 15000);
2544625459
};
2544725460

2544825461
module.exports = run;
2544925462

2545025463

25451-
/***/ }),
25452-
25453-
/***/ 8303:
25454-
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
25455-
25456-
const core = __nccwpck_require__(2186);
25457-
const exec = __nccwpck_require__(3264);
25458-
25459-
const post = (pid) => {
25460-
if (!pid) {
25461-
core.warning("No OpenVPN PID found");
25462-
return;
25463-
}
25464-
25465-
try {
25466-
exec(`sudo kill ${pid} || true`);
25467-
} catch (error) {
25468-
core.warning(`Error stopping OpenVPN: ${error.message}`);
25469-
}
25470-
};
25471-
25472-
module.exports = post;
25473-
25474-
25475-
/***/ }),
25476-
25477-
/***/ 1861:
25478-
/***/ ((module) => {
25479-
25480-
module.exports = eval("require")(".exec");
25481-
25482-
2548325464
/***/ }),
2548425465

2548525466
/***/ 9491:
@@ -27382,30 +27363,13 @@ var __webpack_exports__ = {};
2738227363
(() => {
2738327364
const core = __nccwpck_require__(2186);
2738427365
const main = __nccwpck_require__(1713);
27385-
const post = __nccwpck_require__(8303);
27386-
27387-
// Detect the current running mode
27388-
const isPost = core.getState("isPost");
2738927366

27390-
if (isPost) {
27391-
// If it's in post mode, then clean up the environment
27392-
const pid = core.getState("pid");
27393-
try {
27394-
post(pid);
27395-
} catch (error) {
27396-
core.setFailed(error.message);
27397-
}
27398-
} else {
27399-
// If it's in pre mode, then run the main function
27400-
try {
27401-
main((pid) => {
27402-
core.saveState("pid", pid);
27403-
});
27404-
} catch (error) {
27405-
core.setFailed(error.message);
27406-
} finally {
27407-
core.saveState("isPost", true);
27408-
}
27367+
try {
27368+
main((pid) => {
27369+
core.saveState("pid", pid);
27370+
});
27371+
} catch (error) {
27372+
core.setFailed(error.message);
2740927373
}
2741027374

2741127375
})();

0 commit comments

Comments
 (0)