Skip to content

Commit 6119f92

Browse files
committed
Update main.workflow
1 parent 5a4947a commit 6119f92

File tree

8 files changed

+44
-9
lines changed

8 files changed

+44
-9
lines changed

.github/main.workflow

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
workflow "New workflow" {
1+
workflow "publish" {
22
on = "push"
33
resolves = ["maven-publish"]
44
}
55

66
action "maven-publish" {
7-
uses = "./gradlew"
8-
runs = "./gradlew"
9-
args = "build"
7+
uses = "./"
8+
secrets = [
9+
"GNUPG_KEY",
10+
"GRADLE_CONFIG",
11+
]
1012
}

Dockerfile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM openjdk:8-jdk
2+
3+
ADD . .
4+
5+
ENTRYPOINT ["/entrypoint.sh"]

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ buildscript {
1010
}
1111

1212
group 'info.purocean'
13-
version '1.1.0'
13+
version '1.2.0'
1414

1515
apply plugin: 'kotlin'
1616
apply plugin: 'maven-publish'

entrypoint.sh

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh -l
2+
3+
echo $GNUPG_KEY | sed 's/ //g' | base64 -d > ./secring.gpg
4+
echo $GRADLE_CONFIG | sed 's/ //g' | base64 -d > ./gradle.properties
5+
6+
./gradlew -Dgradle.user.home=./ publishMavenJavaPublicationToMavenRepository

gradlew

100644100755
File mode changed.
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package info.purocean.dbmigration
22

3-
import java.sql.Connection
4-
53
interface CodeMigration <in T> {
6-
fun run(context: T, connection: Connection)
4+
fun run(context: T, db: DB)
75
}

src/main/kotlin/info/purocean/dbmigration/DB.kt

+20
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,26 @@ class DB(dbUrl: String, dbUsername: String, dbPassword: String) {
1818
this.conn = DriverManager.getConnection(url, dbUsername, dbPassword)
1919
}
2020

21+
fun exec (sql: String) {
22+
this.conn.autoCommit = false
23+
val stmt = this.conn.createStatement()
24+
25+
try {
26+
println("Migrate ----------- 执行SQL ------------")
27+
println(sql)
28+
29+
stmt.execute(sql)
30+
this.conn.commit()
31+
} catch (e: Exception) {
32+
this.conn.rollback()
33+
e.printStackTrace()
34+
throw e
35+
} finally {
36+
stmt.close()
37+
this.conn.autoCommit = true
38+
}
39+
}
40+
2141
fun createScheme () {
2242
val stmt = this.getStmt()
2343

src/main/kotlin/info/purocean/dbmigration/Migrate.kt

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ import java.util.regex.Pattern
1111
class Migrate(dbUrl: String, dbUsername: String, dbPassword: String, private var migrationPackage: String = "db.migrations") {
1212
private var db: DB = DB(dbUrl, dbUsername, dbPassword)
1313

14+
fun getDb (): DB {
15+
return this.db
16+
}
17+
1418
fun run (dryRun: Boolean = false) {
1519
val newList = this.getNew()
1620
println("Migrate ${if (dryRun) "[dry run] " else ""}----------- start ${newList.size} ------------")
@@ -68,7 +72,7 @@ class Migrate(dbUrl: String, dbUsername: String, dbPassword: String, private var
6872

6973
val obj = cls.newInstance()
7074

71-
cls.getMethod("run", Object::class.java).invoke(obj, context, this.db.getConnection())
75+
cls.getMethod("run", Object::class.java).invoke(obj, context, this.db)
7276
}
7377

7478
this.db.writeRecord(migration)

0 commit comments

Comments
 (0)