Skip to content

Commit 9dbfb49

Browse files
authored
Add github workflow to test non-zero shard/realm (#11608)
- Add github workflow to test non-zero shard/realm - Don't fail-fast in jobs with matrix Signed-off-by: Xin Li <[email protected]>
1 parent 097895c commit 9dbfb49

File tree

6 files changed

+126
-11
lines changed

6 files changed

+126
-11
lines changed

.github/workflows/cleanup.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
images:
1818
runs-on: hiero-mirror-node-linux-medium
1919
strategy:
20+
fail-fast: false
2021
matrix:
2122
module:
2223
[

.github/workflows/gradle.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ jobs:
2929
name: Build
3030
runs-on: hiero-mirror-node-linux-large
3131
strategy:
32+
fail-fast: false
3233
matrix:
3334
project:
3435
- common
@@ -88,7 +89,7 @@ jobs:
8889
if: ${{ matrix.schema == 'v1' && matrix.project != 'test' && always() && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository) }}
8990
run: ./gradlew :${{ matrix.project }}:uploadCoverage
9091

91-
- name: Execute Gradle using transaction executor
92+
- name: Build and test web3 with modularized code
9293
env:
9394
HIERO_MIRROR_WEB3_EVM_MODULARIZEDSERVICES: "true"
9495
HIERO_MIRROR_WEB3_EVM_MODULARIZEDTRAFFICPERCENT: "1.0"

.github/workflows/non-zero-realm.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
name: "Non-Zero Realm"
4+
on:
5+
schedule:
6+
- cron: "0 0 * * *" # Daily at midnight
7+
workflow_dispatch:
8+
inputs:
9+
branch:
10+
description: "Branch"
11+
required: true
12+
type: string
13+
14+
defaults:
15+
run:
16+
shell: bash
17+
18+
permissions:
19+
contents: read
20+
21+
env:
22+
LC_ALL: C.UTF-8
23+
CGO_ENABLED: 1
24+
25+
jobs:
26+
build:
27+
name: Build
28+
env:
29+
HIERO_MIRROR_COMMON_REALM: 127
30+
HIERO_MIRROR_COMMON_SHARD: 113
31+
HIERO_MIRROR_WEB3_EVM_MODULARIZEDSERVICES: "true"
32+
HIERO_MIRROR_WEB3_EVM_MODULARIZEDTRAFFICPERCENT: "1.0"
33+
runs-on: hiero-mirror-node-linux-large
34+
strategy:
35+
fail-fast: false
36+
matrix:
37+
project:
38+
- common
39+
- graphql
40+
- grpc
41+
- importer
42+
- monitor
43+
- rest
44+
- rest-java
45+
- rosetta
46+
- web3
47+
timeout-minutes: 40 # increase it from 20 minutes since some jobs often run longer on self-hosted runners
48+
steps:
49+
- name: Harden Runner
50+
uses: step-security/harden-runner@6c439dc8bdf85cadbbce9ed30d1c7b959517bc49 # v2.12.2
51+
with:
52+
egress-policy: audit
53+
54+
- name: Checkout Code
55+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
56+
with:
57+
ref: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.branch || github.ref }}
58+
59+
- name: Install JDK
60+
uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4.7.1
61+
with:
62+
distribution: temurin
63+
java-version: 21
64+
65+
- name: Setup Gradle
66+
uses: gradle/actions/setup-gradle@ac638b010cf58a27ee6c972d7336334ccaf61c96 # v4
67+
68+
- name: Execute Gradle
69+
run: ./gradlew :${{matrix.project}}:build

.github/workflows/release-integration.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ env:
2020
jobs:
2121
publish:
2222
strategy:
23+
fail-fast: false
2324
matrix:
2425
project:
2526
- graphql

.github/workflows/release-production.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ env:
2020
jobs:
2121
image:
2222
strategy:
23+
fail-fast: false
2324
matrix:
2425
project:
2526
- graphql

rosetta/app/config/config_test.go

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os"
77
"path/filepath"
88
"reflect"
9+
"strconv"
910
"testing"
1011
"time"
1112

@@ -42,7 +43,9 @@ hiero:
4243
host: 192.168.120.51
4344
port: 12000
4445
network: TESTNET`
46+
realmEnvKey = "HIERO_MIRROR_COMMON_REALM"
4547
serviceEndpoint = "192.168.0.1:50211"
48+
shardEnvKey = "HIERO_MIRROR_COMMON_SHARD"
4649
)
4750

4851
var expectedNodeRefreshInterval = 30 * time.Minute
@@ -82,7 +85,7 @@ func TestLoadCustomConfig(t *testing.T) {
8285
if tt.fromCwd {
8386
os.Chdir(tempDir)
8487
} else {
85-
em := envManager{}
88+
em := newEnvManager()
8689
em.SetEnv(apiConfigEnvKey, filePath)
8790
t.Cleanup(em.Cleanup)
8891
}
@@ -108,8 +111,10 @@ func TestLoadCustomConfigFromCwdAndEnvVar(t *testing.T) {
108111
tempDir2, filePath2 := createYamlConfigFile(yml2, t)
109112
defer os.RemoveAll(tempDir2)
110113

111-
em := envManager{}
114+
em := newEnvManager()
112115
em.SetEnv(apiConfigEnvKey, filePath2)
116+
em.UnsetEnv(realmEnvKey)
117+
em.UnsetEnv(shardEnvKey)
113118
t.Cleanup(em.Cleanup)
114119

115120
// when
@@ -131,7 +136,7 @@ func TestLoadCustomConfigFromCwdAndEnvVar(t *testing.T) {
131136
func TestLoadCustomConfigFromEnvVar(t *testing.T) {
132137
// given
133138
dbHost := "192.168.100.200"
134-
em := envManager{}
139+
em := newEnvManager()
135140
em.SetEnv("HIERO_MIRROR_ROSETTA_DB_HOST", dbHost)
136141
t.Cleanup(em.Cleanup)
137142

@@ -165,7 +170,7 @@ func TestLoadCustomConfigInvalidYaml(t *testing.T) {
165170
os.Chdir(tempDir)
166171
}
167172

168-
em := envManager{}
173+
em := newEnvManager()
169174
em.SetEnv(apiConfigEnvKey, filePath)
170175
t.Cleanup(em.Cleanup)
171176

@@ -179,7 +184,7 @@ func TestLoadCustomConfigInvalidYaml(t *testing.T) {
179184

180185
func TestLoadCustomConfigByEnvVarFileNotFound(t *testing.T) {
181186
// given
182-
em := envManager{}
187+
em := newEnvManager()
183188
em.SetEnv(apiConfigEnvKey, "/foo/bar/not_found.yml")
184189
t.Cleanup(em.Cleanup)
185190

@@ -211,7 +216,7 @@ func TestLoadNodeMapFromEnv(t *testing.T) {
211216

212217
for _, tt := range tests {
213218
t.Run(tt.value, func(t *testing.T) {
214-
em := envManager{}
219+
em := newEnvManager()
215220
em.SetEnv("HIERO_MIRROR_ROSETTA_NODES", tt.value)
216221
t.Cleanup(em.Cleanup)
217222

@@ -229,7 +234,7 @@ func TestLoadNodeMapFromEnvError(t *testing.T) {
229234
values := []string{"192.168.0.1:0.0.3", "192.168.0.1:50211:0.3", "192.168.0.1"}
230235
for _, value := range values {
231236
t.Run(value, func(t *testing.T) {
232-
em := envManager{}
237+
em := newEnvManager()
233238
em.SetEnv("HIERO_MIRROR_ROSETTA_NODES", value)
234239
t.Cleanup(em.Cleanup)
235240

@@ -303,22 +308,59 @@ func createYamlConfigFile(content string, t *testing.T) (string, string) {
303308
}
304309

305310
type envManager struct {
306-
keys []string
311+
added []string
312+
overridden map[string]string
307313
}
308314

309315
func (e *envManager) SetEnv(key, value string) {
316+
if oldValue, present := os.LookupEnv(key); present {
317+
e.overridden[key] = oldValue
318+
} else {
319+
e.added = append(e.added, key)
320+
}
310321
os.Setenv(key, value)
311-
e.keys = append(e.keys, key)
322+
}
323+
324+
func (e *envManager) UnsetEnv(key string) {
325+
if value, present := os.LookupEnv(key); present {
326+
e.overridden[key] = value
327+
}
328+
os.Unsetenv(key)
312329
}
313330

314331
func (e *envManager) Cleanup() {
315-
for _, key := range e.keys {
332+
for _, key := range e.added {
316333
os.Unsetenv(key)
317334
}
335+
336+
for key, value := range e.overridden {
337+
os.Setenv(key, value)
338+
}
339+
}
340+
341+
func newEnvManager() envManager {
342+
return envManager{overridden: make(map[string]string)}
318343
}
319344

320345
func getDefaultConfig() *Mirror {
321346
config := fullConfig{}
322347
yaml.Unmarshal([]byte(defaultConfig), &config)
348+
349+
if value, present := os.LookupEnv(realmEnvKey); present {
350+
var err error
351+
config.Hiero.Mirror.Common.Realm, err = strconv.ParseInt(value, 10, 64)
352+
if err != nil {
353+
panic(err)
354+
}
355+
}
356+
357+
if value, present := os.LookupEnv(shardEnvKey); present {
358+
var err error
359+
config.Hiero.Mirror.Common.Shard, err = strconv.ParseInt(value, 10, 64)
360+
if err != nil {
361+
panic(err)
362+
}
363+
}
364+
323365
return &config.Hiero.Mirror
324366
}

0 commit comments

Comments
 (0)