Skip to content

Commit 09fd889

Browse files
author
Sebastian Hahn
committed
Add mysql installation path
1 parent 738f744 commit 09fd889

File tree

2 files changed

+68
-6
lines changed

2 files changed

+68
-6
lines changed

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ inputs:
1515
description: Password for the user
1616
default: ""
1717
required: false
18+
install-directory:
19+
description: Installation path of MySQL. Only relevant on Windows
20+
default: ${{ runner.workspace }}\MySQL
21+
required: false
1822
runs:
1923
using: node12
2024
main: index.js

index.js

Lines changed: 64 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,66 @@ function run(command) {
1212
execSync(command, {stdio: 'inherit', env: env});
1313
}
1414

15+
function copyFileSync( source, target ) {
16+
// Source https://stackoverflow.com/a/26038979/2127939
17+
var targetFile = target;
18+
19+
// If target is a directory, a new file with the same name will be created
20+
if ( fs.existsSync( target ) ) {
21+
if ( fs.lstatSync( target ).isDirectory() ) {
22+
targetFile = path.join( target, path.basename( source ) );
23+
}
24+
}
25+
26+
fs.writeFileSync(targetFile, fs.readFileSync(source));
27+
}
28+
29+
function copyFolderRecursiveSync( source, target ) {
30+
// Source https://stackoverflow.com/a/26038979/2127939
31+
var files = [];
32+
33+
// Check if folder needs to be created or integrated
34+
var targetFolder = path.join( target, path.basename( source ) );
35+
if ( !fs.existsSync( targetFolder ) ) {
36+
fs.mkdirSync( targetFolder );
37+
}
38+
39+
// Copy
40+
if ( fs.lstatSync( source ).isDirectory() ) {
41+
files = fs.readdirSync( source );
42+
files.forEach( function ( file ) {
43+
var curSource = path.join( source, file );
44+
if ( fs.lstatSync( curSource ).isDirectory() ) {
45+
copyFolderRecursiveSync( curSource, targetFolder );
46+
} else {
47+
copyFileSync( curSource, targetFolder );
48+
}
49+
} );
50+
}
51+
}
52+
53+
function integrateFolderRecursiveSync(source, target) {
54+
var files = [];
55+
56+
// Check if folder needs to be created or integrated
57+
var targetFolder = target;
58+
if ( !fs.existsSync( targetFolder ) ) {
59+
fs.mkdirSync( targetFolder );
60+
}
61+
// Copy
62+
if ( fs.lstatSync( source ).isDirectory() ) {
63+
files = fs.readdirSync( source );
64+
files.forEach( function ( file ) {
65+
var curSource = path.join( source, file );
66+
if ( fs.lstatSync( curSource ).isDirectory() ) {
67+
copyFolderRecursiveSync( curSource, targetFolder );
68+
} else {
69+
copyFileSync( curSource, targetFolder );
70+
}
71+
} );
72+
}
73+
}
74+
1575
function runSafe() {
1676
const args = Array.from(arguments);
1777
console.log(args.join(' '));
@@ -43,7 +103,7 @@ const defaultVersion = (image == 'ubuntu16' || image == 'ubuntu18') ? '5.7' : '8
43103
const mysqlVersion = parseFloat(process.env['INPUT_MYSQL-VERSION'] || defaultVersion).toFixed(1);
44104
const username = process.env['INPUT_USERNAME'] || "";
45105
const password = process.env['INPUT_PASSWORD'] || "";
46-
106+
const mysqlInstallDirectory = process.env['INPUT_install-directory'] || "";
47107
// TODO make OS-specific
48108
if (!['8.0', '5.7', '5.6'].includes(mysqlVersion)) {
49109
throw `MySQL version not supported: ${mysqlVersion}`;
@@ -84,15 +144,13 @@ function installWindwos() {
84144
'5.7': '5.7.32',
85145
'5.6': '5.6.50'
86146
};
87-
installDir = "C:\\Program Files\\MySQL";
88-
bin = `C:\\Program Files\\MySQL\\MySQL Server ${mysqlVersion}\\bin`;
89-
if (! fs.existsSync(installDir)) {
147+
bin = `${mysqlInstallDirectory}\\bin`;
148+
if (! fs.existsSync(mysqlInstallDirectory)) {
90149
const fullVersion = versionMap[mysqlVersion];
91150
useTmpDir();
92151
run(`curl -Ls -o mysql.zip https://dev.mysql.com/get/Downloads/MySQL-${mysqlVersion}/mysql-${fullVersion}-winx64.zip`)
93152
run(`unzip -q mysql.zip`);
94-
fs.mkdirSync(installDir);
95-
fs.renameSync(`mysql-${fullVersion}-winx64`, `C:\\Program Files\\MySQL\\MySQL Server ${mysqlVersion}`);
153+
integrateFolderRecursiveSync(`mysql-${fullVersion}-winx64`, mysqlInstallDirectory);
96154

97155
// start
98156
if (mysqlVersion != '5.6') {

0 commit comments

Comments
 (0)