Skip to content

Commit 83c7de3

Browse files
committed
feat: Added tmp directory location to save all files to
1 parent 38e30b5 commit 83c7de3

File tree

5 files changed

+28
-14
lines changed

5 files changed

+28
-14
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jobs:
2626
config_file: ${{ secrets.VPN_CONFIG }}
2727
certificate: ${{ secrets.VPN_CERTIFICATE }}
2828
certificate_name: ${{ secrets.VPN_CERTIFICATE_NAME }}
29+
tmp_dir: "/tmp"
2930

3031
- name: Wait for VPN to connect
3132
if: success()

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
# Optional npm cache directory
55
.npm
66

7+
# dev files
8+
dev/
9+
710
# Optional eslint cache
811
.eslintcache
912

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ inputs:
1414
description: "The OpenVPN certificate name as declared in the configuration file"
1515
required: true
1616
default: "certificate.p12"
17+
tmp_dir:
18+
description: "The temporary directory to store the OpenVPN configuration and certificate"
19+
required: true
20+
default: "/tmp"
1721
runs:
1822
using: "node20"
1923
main: "dist_main/index.js"

dist_main/index.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25405,24 +25405,27 @@ const Tail = (__nccwpck_require__(5824)/* .Tail */ .x);
2540525405
/*eslint no-undef: "error"*/
2540625406

2540725407
const run = (callback) => {
25408+
const tmpDir = core.getInput("tmp_dir", { required: true });
2540825409
const configFile = core.getInput("config_file", { required: true });
2540925410
const configFileName = "config.ovpn";
2541025411
const certificate = core.getInput("certificate", { required: true });
2541125412
const certificateName = core.getInput("certificate_name", { required: true });
25413+
const configFilePath = `${tmpDir}/${configFileName}`;
25414+
const certificatePath = `${tmpDir}/${certificateName}`;
2541225415
const openVpnLog = "openvpn.log";
2541325416

2541425417
// If the certificate is base64 encoded, decode it and write it to a temporary file
25415-
exec(`echo "${configFile}" > ${configFileName}`);
25418+
exec(`echo "${configFile}" > ${configFilePath}`);
2541625419

25417-
if (!fs.existsSync(configFileName)) {
25418-
throw new Error(`Config file not found: ${configFileName}`);
25420+
if (!fs.existsSync(configFilePath)) {
25421+
throw new Error(`Config file not found: ${configFilePath}`);
2541925422
}
2542025423

2542125424
// If the certificate is base64 encoded, decode it and write it to a temporary file
25422-
exec(`echo "${certificate}" | base64 -d > ${certificateName}`);
25425+
exec(`echo "${certificate}" | base64 -d > ${certificatePath}`);
2542325426

25424-
if (!fs.existsSync(`${certificateName}`)) {
25425-
throw new Error(`Config file not found: ${certificateName}`);
25427+
if (!fs.existsSync(`${certificatePath}`)) {
25428+
throw new Error(`Config file not found: ${certificatePath}`);
2542625429
}
2542725430

2542825431
fs.appendFileSync(configFile, "\n# -- GHA Modified --\n");
@@ -25432,7 +25435,7 @@ const run = (callback) => {
2543225435

2543325436
try {
2543425437
exec(
25435-
`sudo openvpn --config ${configFileName} --pkcs12 ${certificateName} --daemon --log ${openVpnLog} --writepid openvpn.pid`,
25438+
`sudo openvpn --config ${configFilePath} --pkcs12 ${certificatePath} --daemon --log ${openVpnLog} --writepid openvpn.pid`,
2543625439
);
2543725440
} catch (error) {
2543825441
core.error(`Error starting OpenVPN: ${error.message}`);

src/main.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,27 @@ const Tail = require("tail").Tail;
77
/*eslint no-undef: "error"*/
88

99
const run = (callback) => {
10+
const tmpDir = core.getInput("tmp_dir", { required: true });
1011
const configFile = core.getInput("config_file", { required: true });
1112
const configFileName = "config.ovpn";
1213
const certificate = core.getInput("certificate", { required: true });
1314
const certificateName = core.getInput("certificate_name", { required: true });
15+
const configFilePath = `${tmpDir}/${configFileName}`;
16+
const certificatePath = `${tmpDir}/${certificateName}`;
1417
const openVpnLog = "openvpn.log";
1518

1619
// If the certificate is base64 encoded, decode it and write it to a temporary file
17-
exec(`echo "${configFile}" > ${configFileName}`);
20+
exec(`echo "${configFile}" > ${configFilePath}`);
1821

19-
if (!fs.existsSync(configFileName)) {
20-
throw new Error(`Config file not found: ${configFileName}`);
22+
if (!fs.existsSync(configFilePath)) {
23+
throw new Error(`Config file not found: ${configFilePath}`);
2124
}
2225

2326
// If the certificate is base64 encoded, decode it and write it to a temporary file
24-
exec(`echo "${certificate}" | base64 -d > ${certificateName}`);
27+
exec(`echo "${certificate}" | base64 -d > ${certificatePath}`);
2528

26-
if (!fs.existsSync(`${certificateName}`)) {
27-
throw new Error(`Config file not found: ${certificateName}`);
29+
if (!fs.existsSync(`${certificatePath}`)) {
30+
throw new Error(`Config file not found: ${certificatePath}`);
2831
}
2932

3033
fs.appendFileSync(configFile, "\n# -- GHA Modified --\n");
@@ -34,7 +37,7 @@ const run = (callback) => {
3437

3538
try {
3639
exec(
37-
`sudo openvpn --config ${configFileName} --pkcs12 ${certificateName} --daemon --log ${openVpnLog} --writepid openvpn.pid`,
40+
`sudo openvpn --config ${configFilePath} --pkcs12 ${certificatePath} --daemon --log ${openVpnLog} --writepid openvpn.pid`,
3841
);
3942
} catch (error) {
4043
core.error(`Error starting OpenVPN: ${error.message}`);

0 commit comments

Comments
 (0)