Skip to content

Commit 738f744

Browse files
author
Sebastian Hahn
committed
extend tests
* add two user * test admin * test first and second user
1 parent 9e5636b commit 738f744

File tree

3 files changed

+64
-17
lines changed

3 files changed

+64
-17
lines changed

.github/workflows/build.yml

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,12 @@ jobs:
1010
include:
1111
- os: ubuntu-20.04
1212
mysql-version: 8.0
13+
- os: ubuntu-20.04
14+
mysql-version: 5.7
1315
- os: ubuntu-18.04
1416
mysql-version: 8.0
1517
- os: ubuntu-18.04
1618
mysql-version: 5.7
17-
- os: ubuntu-16.04
18-
mysql-version: 8.0
19-
- os: ubuntu-16.04
20-
mysql-version: 5.7
2119
- os: macos-11.0
2220
mysql-version: 8.0
2321
- os: macos-11.0
@@ -44,14 +42,47 @@ jobs:
4442
mysql-version: 5.6
4543
steps:
4644
- uses: actions/checkout@v2
47-
- uses: ./.
45+
46+
- name: Install mysql
47+
uses: ./.
48+
with:
49+
mysql-version: ${{ matrix.mysql-version }}
50+
database: testdb
51+
username: "1234"
52+
password: "abcd"
53+
54+
- name: Install mysql second time
55+
uses: ./.
4856
with:
4957
mysql-version: ${{ matrix.mysql-version }}
5058
database: testdb
51-
- run: mysql --version
52-
- run: mysql -e 'SELECT VERSION()'
53-
- run: mysql -e 'SELECT CURRENT_USER()'
54-
- run: mysql -e 'SELECT DATABASE()'
55-
- run: mysql -e "SHOW VARIABLES LIKE 'socket'"
56-
- run: mysqladmin create testdb2
57-
- run: mysql -D testdb -e 'SELECT DATABASE()'
59+
username: "5678"
60+
password: "efgh"
61+
62+
- name: Test admin
63+
run: |
64+
mysql --version
65+
mysql -uroot -e 'SELECT * FROM mysql.user;'
66+
mysql -uroot -e 'SELECT VERSION()'
67+
mysql -uroot -e 'SELECT CURRENT_USER()'
68+
mysql -uroot -e 'SELECT DATABASE()'
69+
mysql -uroot -e "SHOW VARIABLES LIKE 'socket'"
70+
mysqladmin -uroot create testdb2
71+
mysql -uroot -D testdb2 -e 'SELECT DATABASE()'
72+
echo Y | mysqladmin -uroot drop testdb2
73+
74+
- name: Test first user
75+
run: |
76+
mysql --version
77+
mysql -u1234 -pabcd -e 'SELECT VERSION()'
78+
mysql -u1234 -pabcd -e 'SELECT CURRENT_USER()'
79+
mysql -u1234 -pabcd -e 'SELECT DATABASE()'
80+
mysql -u1234 -pabcd -e "SHOW VARIABLES LIKE 'socket'"
81+
82+
- name: Test second user
83+
run: |
84+
mysql --version
85+
mysql -u5678 -pefgh -e 'SELECT VERSION()'
86+
mysql -u5678 -pefgh -e 'SELECT CURRENT_USER()'
87+
mysql -u5678 -pefgh -e 'SELECT DATABASE()'
88+
mysql -u5678 -pefgh -e "SHOW VARIABLES LIKE 'socket'"

action.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
name: Setup MySQL
2+
description: install and start the mysql server
23
inputs:
34
mysql-version:
45
description: The MySQL version to download (if necessary) and use

index.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ function installMac() {
7474
}
7575
// set path
7676
addToPath(bin);
77+
return bin;
7778
}
7879

7980
function installWindwos() {
@@ -84,6 +85,7 @@ function installWindwos() {
8485
'5.6': '5.6.50'
8586
};
8687
installDir = "C:\\Program Files\\MySQL";
88+
bin = `C:\\Program Files\\MySQL\\MySQL Server ${mysqlVersion}\\bin`;
8789
if (! fs.existsSync(installDir)) {
8890
const fullVersion = versionMap[mysqlVersion];
8991
useTmpDir();
@@ -93,14 +95,16 @@ function installWindwos() {
9395
fs.renameSync(`mysql-${fullVersion}-winx64`, `C:\\Program Files\\MySQL\\MySQL Server ${mysqlVersion}`);
9496

9597
// start
96-
bin = `C:\\Program Files\\MySQL\\MySQL Server ${mysqlVersion}\\bin`;
9798
if (mysqlVersion != '5.6') {
9899
run(`"${bin}\\mysqld" --initialize-insecure`);
99100
}
100101
run(`"${bin}\\mysqld" --install`);
101102
run(`net start MySQL`);
102-
103103
addToPath(bin);
104+
// create windows only user odbc
105+
run(`"${bin}\\mysql" -u root -e "CREATE USER 'ODBC'@'localhost' IDENTIFIED BY ''"`);
106+
run(`"${bin}\\mysql" -u root -e "GRANT ALL PRIVILEGES ON *.* TO 'ODBC'@'localhost'"`);
107+
run(`"${bin}\\mysql" -u root -e "FLUSH PRIVILEGES"`);
104108
}
105109

106110
run(`"${bin}\\mysql" -u root -e "SELECT VERSION()"`);
@@ -111,6 +115,7 @@ function installWindwos() {
111115
run(`"${bin}\\mysql" -u root -e "GRANT ALL PRIVILEGES ON *.* TO '${username}'@'localhost'"`);
112116
run(`"${bin}\\mysql" -u root -e "FLUSH PRIVILEGES"`);
113117
}
118+
return bin;
114119
}
115120

116121
function installLinux() {
@@ -143,7 +148,11 @@ function installLinux() {
143148
run('sudo systemctl start mysql');
144149

145150
// remove root password
146-
run(`sudo mysqladmin -proot password ''`);
151+
try {
152+
run(`sudo mysqladmin -proot password ''`);
153+
} catch (error) {
154+
console.log("error on remove password: ", error);
155+
}
147156

148157
// add user
149158
if(username && username !== "") {
@@ -152,11 +161,12 @@ function installLinux() {
152161
run(`sudo mysql -e "FLUSH PRIVILEGES"`);
153162
}
154163
bin = `/usr/bin`;
164+
return bin;
155165
}
156166

157167

158168
if (process.platform == 'darwin') {
159-
installMac();
169+
bin = installMac();
160170
} else if (process.platform == 'win32') {
161171
bin = installWindwos();
162172
} else if (process.platform == 'linux') {
@@ -166,5 +176,10 @@ if (process.platform == 'darwin') {
166176
}
167177

168178
if (database) {
169-
runSafe(path.join(bin, 'mysqladmin'), 'create', database);
179+
try {
180+
run(path.join(bin, 'mysqladmin'), ' -u root create', database);
181+
} catch (error) {
182+
console.log("error on create database: ", error);
183+
}
184+
170185
}

0 commit comments

Comments
 (0)