Skip to content

Commit b4acb09

Browse files
authored
added static option to set server, harden build (#16)
1 parent 5bc9097 commit b4acb09

File tree

4 files changed

+66
-17
lines changed

4 files changed

+66
-17
lines changed

.github/workflows/build.yml renamed to .github/workflows/build-merge-or-release.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
name: GitHub Build Actions For Nats Server Runner
1+
name: GitHub Merge Or Release Build Actions For Nats Server Runner
22

33
on:
4-
pull_request:
5-
types: [opened, synchronize, edited, reopened]
64
push:
75
branches:
86
- main
@@ -46,8 +44,7 @@ jobs:
4644
uses: actions/checkout@v2
4745
- name: Build and Test
4846
run: chmod +x gradlew && ./gradlew clean test
49-
- name: On Pull Request, Verify Javadoc
50-
if: ${{ success() && github.event_name == 'pull_request' }}
47+
- name: Verify Javadoc
5148
run: ./gradlew javadoc
5249
- name: On Merge to Main, Verify and Publish Snapshot
5350
if: ${{ success() && github.event_name == 'push' }}

.github/workflows/build-pr.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: GitHub PR Build Actions For Nats Server Runner
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, edited, reopened]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
env:
11+
BUILD_EVENT: ${{ github.event_name }}
12+
steps:
13+
- name: Setup JDK 8
14+
uses: actions/setup-java@v2
15+
with:
16+
java-version: '8'
17+
distribution: 'adopt'
18+
- name: Setup GO
19+
uses: actions/setup-go@v2
20+
with:
21+
go-version: 1.16.3
22+
- name: Install Nats Server
23+
run: |
24+
cd $GITHUB_WORKSPACE
25+
git clone https://github.com/nats-io/nats-server.git
26+
cd nats-server
27+
go build main.go
28+
mkdir -p ~/.local/bin
29+
cp main ~/.local/bin/nats-server
30+
cd ..
31+
rm -rf nats-server
32+
nats-server -v
33+
- name: Check out code
34+
uses: actions/checkout@v2
35+
- name: Build and Test
36+
run: chmod +x gradlew && ./gradlew clean test
37+
- name: Verify Javadoc
38+
run: ./gradlew javadoc

build.gradle

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ plugins {
88
id 'signing'
99
}
1010

11-
def jarVersion = "1.0.7"
11+
def jarVersion = "1.0.8"
1212
group = 'io.nats'
1313

14-
def isPr = System.getenv("BUILD_EVENT") == "pull_request"
1514
def isMerge = System.getenv("BUILD_EVENT") == "push"
1615
def isRelease = System.getenv("BUILD_EVENT") == "release"
1716

@@ -74,11 +73,13 @@ artifacts {
7473
archives javadocJar, sourcesJar
7574
}
7675

77-
nexusPublishing {
78-
repositories {
79-
sonatype {
80-
username = System.getenv('OSSRH_USERNAME')
81-
password = System.getenv('OSSRH_PASSWORD')
76+
if (isMerge || isRelease) {
77+
nexusPublishing {
78+
repositories {
79+
sonatype {
80+
username = System.getenv('OSSRH_USERNAME')
81+
password = System.getenv('OSSRH_PASSWORD')
82+
}
8283
}
8384
}
8485
}

src/main/java/nats/io/NatsRunnerUtils.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class NatsRunnerUtils {
3232
public static final String PORT_REGEX = "port: (\\d+)";
3333
public static final String PORT_PROPERTY = "port: ";
3434

35+
private static String SERVER_PATH = null;
3536

3637
/**
3738
* Build a standard nats://localhost:port uri
@@ -42,6 +43,18 @@ public static String getURIForPort(int port) {
4243
return "nats://localhost:" + port;
4344
}
4445

46+
/**
47+
* Set the path for the
48+
* @param serverPath
49+
*/
50+
public static void setServerPath(String serverPath) {
51+
SERVER_PATH = serverPath;
52+
}
53+
54+
public static void clearServerPath() {
55+
SERVER_PATH = null;
56+
}
57+
4558
/**
4659
* Get a port number automatically allocated by the system, typically from an ephemeral port range.
4760
* @return the port number
@@ -67,13 +80,13 @@ public static int nextPort() throws IOException {
6780
public static String getNatsServerVersionString() {
6881
ArrayList<String> cmd = new ArrayList<String>();
6982

70-
String server_path = System.getenv(NATS_SERVER_PATH_ENV);
71-
72-
if(server_path == null){
73-
server_path = DEFAULT_NATS_SERVER;
83+
// order of precedence is environment, value set statically, default
84+
String serverPath = System.getenv(NATS_SERVER_PATH_ENV);
85+
if (serverPath == null){
86+
serverPath = SERVER_PATH == null ? DEFAULT_NATS_SERVER : SERVER_PATH;
7487
}
7588

76-
cmd.add(server_path);
89+
cmd.add(serverPath);
7790
cmd.add(VERSION_OPTION);
7891

7992
try {

0 commit comments

Comments
 (0)