Skip to content

Commit 8a9a0ba

Browse files
authored
Update Java CI Workflow and fix DatabasePerTenantSpec.groovy (#1408)
* Update Java CI workflow; add env RUN_TESTS_ONLY which would prevent publishing when set to TRUE. * Move test classes to individual files.
1 parent 25bc451 commit 8a9a0ba

File tree

5 files changed

+54
-38
lines changed

5 files changed

+54
-38
lines changed

.github/workflows/gradle.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
env:
1818
WORKSPACE: ${{ github.workspace }}
1919
GRADLE_OPTS: -Xmx1500m -Dfile.encoding=UTF-8
20+
RUN_TESTS_ONLY: false
2021
steps:
2122
- uses: actions/checkout@v2
2223
- uses: actions/cache@v2
@@ -33,17 +34,18 @@ jobs:
3334
run: |
3435
[ -f ./setup.sh ] && ./setup.sh || true
3536
- name: Run Tests
36-
run: ./gradlew check
37+
run: |
38+
./gradlew --no-daemon --refresh-dependencies clean check
3739
- name: Publish Test Report
3840
uses: scacap/action-surefire-report@v1
3941
with:
4042
github_token: ${{ secrets.GITHUB_TOKEN }}
4143
report_paths: '**/build/test-results/test/TEST-*.xml'
4244
- name: Run Assemble
43-
if: success() && github.event_name == 'push' && matrix.java == '8'
45+
if: success() && github.event_name == 'push' && matrix.java == '8' && env.RUN_TESTS_ONLY == false
4446
run: ./gradlew assemble
4547
- name: Publish to repo.grails.org
46-
if: success() && github.event_name == 'push' && matrix.java == '8'
48+
if: success() && github.event_name == 'push' && matrix.java == '8' && env.RUN_TESTS_ONLY == false
4749
env:
4850
SECRING_FILE: ${{ secrets.SECRING_FILE }}
4951
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
@@ -54,15 +56,15 @@ jobs:
5456
echo $SECRING_FILE | base64 -d > secring.gpg
5557
./gradlew -Dorg.gradle.internal.publish.checksums.insecure=true -Psigning.keyId="$SIGNING_KEY" -Psigning.password="$SIGNING_PASSPHRASE" -Psigning.secretKeyRingFile="secring.gpg" publish
5658
- name: Extract branch name
57-
if: success() && github.event_name == 'push' && matrix.java == '8'
59+
if: success() && github.event_name == 'push' && matrix.java == '8' && env.RUN_TESTS_ONLY == false
5860
id: extract_branch
5961
run: echo ::set-output name=value::${GITHUB_REF:11}
6062
- name: Create Snapshot Message for the Workflow Dispatch
61-
if: success() && github.event_name == 'push' && matrix.java == '8'
63+
if: success() && github.event_name == 'push' && matrix.java == '8' && env.RUN_TESTS_ONLY == false
6264
id: dispatch_message
6365
run: echo ::set-output name=value::{\"message\":\"New Core Snapshot $(date) - $GITHUB_SHA\"}
6466
- name: Invoke the Java CI workflow in GORM Hibernate5
65-
if: success() && github.event_name == 'push' && matrix.java == '8'
67+
if: success() && github.event_name == 'push' && matrix.java == '8' && env.RUN_TESTS_ONLY == false
6668
uses: benc-uk/[email protected]
6769
with:
6870
workflow: Java CI
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package grails.gorm.services.multitenancy.database
2+
3+
import grails.gorm.MultiTenant
4+
import grails.gorm.annotation.Entity
5+
6+
@Entity
7+
class Book implements MultiTenant<Book> {
8+
String title
9+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package grails.gorm.services.multitenancy.database
2+
3+
import grails.gorm.multitenancy.CurrentTenant
4+
import grails.gorm.transactions.ReadOnly
5+
import grails.gorm.transactions.Transactional
6+
7+
@CurrentTenant
8+
@Transactional
9+
class BookService {
10+
11+
void saveBook(String title) {
12+
new Book(title: "The Stand").save()
13+
}
14+
15+
@ReadOnly
16+
int countBooks() {
17+
Book.count()
18+
}
19+
}

grails-datastore-gorm-test/src/test/groovy/grails/gorm/services/multitenancy/database/DatabasePerTenantSpec.groovy

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
package grails.gorm.services.multitenancy.database
22

3-
import grails.gorm.MultiTenant
4-
import grails.gorm.annotation.Entity
5-
import grails.gorm.multitenancy.CurrentTenant
6-
import grails.gorm.services.Service
7-
import grails.gorm.transactions.ReadOnly
8-
import grails.gorm.transactions.Transactional
3+
94
import org.grails.datastore.mapping.config.Settings
5+
import org.grails.datastore.mapping.core.DatastoreUtils
106
import org.grails.datastore.mapping.core.connections.ConnectionSource
117
import org.grails.datastore.mapping.multitenancy.MultiTenancySettings
128
import org.grails.datastore.mapping.multitenancy.exceptions.TenantNotFoundException
@@ -22,11 +18,11 @@ import spock.lang.Specification
2218
class DatabasePerTenantSpec extends Specification {
2319

2420
@Shared @AutoCleanup SimpleMapDatastore datastore = new SimpleMapDatastore(
25-
[(Settings.SETTING_MULTI_TENANCY_MODE) : MultiTenancySettings.MultiTenancyMode.DATABASE,
21+
DatastoreUtils.createPropertyResolver([(Settings.SETTING_MULTI_TENANCY_MODE) : MultiTenancySettings.MultiTenancyMode.DATABASE,
2622
(Settings.SETTING_MULTI_TENANT_RESOLVER): new SystemPropertyTenantResolver(),
27-
(Settings.SETTING_DB_CREATE) : "create-drop"],
23+
(Settings.SETTING_DB_CREATE) : "create-drop"]),
2824
[ConnectionSource.DEFAULT, "foo", "bar"],
29-
getClass().getPackage()
25+
Book
3026
)
3127
@Shared IBookService bookDataService = datastore.getService(IBookService)
3228

@@ -66,30 +62,7 @@ class DatabasePerTenantSpec extends Specification {
6662
}
6763
}
6864

69-
@Entity
70-
class Book implements MultiTenant<Book> {
71-
String title
72-
}
73-
74-
@CurrentTenant
75-
@Transactional
76-
class BookService {
77-
78-
void saveBook(String title) {
79-
new Book(title: "The Stand").save()
80-
}
8165

82-
@ReadOnly
83-
int countBooks() {
84-
Book.count()
85-
}
86-
}
8766

88-
@CurrentTenant
89-
@Service(Book)
90-
interface IBookService {
9167

92-
Book saveBook(String title)
9368

94-
Integer countBooks()
95-
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package grails.gorm.services.multitenancy.database
2+
3+
import grails.gorm.multitenancy.CurrentTenant
4+
import grails.gorm.services.Service
5+
6+
@CurrentTenant
7+
@Service(Book)
8+
interface IBookService {
9+
10+
Book saveBook(String title)
11+
12+
Integer countBooks()
13+
}

0 commit comments

Comments
 (0)