Skip to content

Commit af4afba

Browse files
devhawkCopilot
andauthored
Publish to GH Packages (#43)
Also includes a basic versioning scheme that will need to be revisited before shipping the next minor version. # Versioning Scheme The `build.gradle.kts` file includes the following logic for generating the version identifier: `version = "$baseVersion.$commitCount-preview+g$gitHash$safeBranchName"` * `baseVersion` is set to `BASE_VERSION` env var, with `0.5` as a fallback * `commitCount` is the number of commits, retrieved via `git rev-list --count HEAD` * `gitHash` is the short git hash, retrieved via ` git rev-parse --short HEAD` * `safeBranchName` is the branch name, with `/` replaced with `-`. Omitted if branch name is `main` or `HEAD` An example version identifier from my local machine is `0.5.302-preview+ga068c39.devhawk-version`. --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 3717de4 commit af4afba

7 files changed

Lines changed: 111 additions & 14 deletions

File tree

.github/workflows/on_push.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,9 @@ on:
88

99
jobs:
1010
test:
11-
uses: ./.github/workflows/test.yml
11+
uses: ./.github/workflows/test.yml
12+
publish:
13+
uses: ./.github/workflows/publish.yml
14+
secrets:
15+
USERNAME_MAVEN: ${{ secrets.USERNAME_MAVEN }}
16+
TOKEN_MAVEN: ${{ secrets.TOKEN_MAVEN }}

.github/workflows/publish.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Publish
2+
3+
on:
4+
workflow_call:
5+
secrets:
6+
USERNAME_MAVEN:
7+
required: true
8+
TOKEN_MAVEN:
9+
required: true
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0 # fetch-depth 0 needed for version calculation
19+
20+
- name: Set up OpenJDK 21
21+
uses: actions/setup-java@v4
22+
with:
23+
java-version: '21'
24+
distribution: 'temurin'
25+
26+
- name: Publish
27+
uses: gradle/gradle-build-action@v2
28+
with:
29+
arguments: publish
30+
env:
31+
# GitHub Packages credentials stored as repository secrets
32+
USERNAME: ${{ secrets.USERNAME_MAVEN }}
33+
TOKEN: ${{ secrets.TOKEN_MAVEN }}

.github/workflows/test.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ jobs:
5050
PGPASSWORD: dbos
5151

5252
- name: Run tests
53-
run: ./gradlew clean test
53+
uses: gradle/gradle-build-action@v2
54+
with:
55+
arguments: clean test
5456
env:
5557
PGPASSWORD: dbos
5658

@@ -61,4 +63,4 @@ jobs:
6163
name: test-results
6264
path: |
6365
build/reports/tests/
64-
build/test-results/
66+
build/test-results/

build.gradle.kts

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,51 @@
1+
import java.io.ByteArrayOutputStream
2+
3+
// Get the short Git hash
4+
val gitHash: String by lazy {
5+
ByteArrayOutputStream().also { stdout ->
6+
exec {
7+
commandLine = listOf("git", "rev-parse", "--short", "HEAD")
8+
standardOutput = stdout
9+
}
10+
}.toString().trim()
11+
}
12+
13+
// Get the commit count
14+
val commitCount: String by lazy {
15+
ByteArrayOutputStream().also { stdout ->
16+
exec {
17+
commandLine = listOf("git", "rev-list", "--count", "HEAD")
18+
standardOutput = stdout
19+
}
20+
}.toString().trim()
21+
}
22+
23+
// Get the current branch name
24+
val branchName: String by lazy {
25+
// First, try GitHub Actions environment variable
26+
val githubBranch = System.getenv("GITHUB_REF_NAME")
27+
if (!githubBranch.isNullOrBlank()) githubBranch
28+
29+
// Fallback to local git command
30+
else {
31+
ByteArrayOutputStream().also { stdout ->
32+
exec {
33+
commandLine = listOf("git", "rev-parse", "--abbrev-ref", "HEAD")
34+
standardOutput = stdout
35+
}
36+
}.toString().trim()
37+
}
38+
}
39+
40+
// Note, this versioning scheme is fine for preview releases
41+
// but we'll want something more robust once we want to bump
42+
// the major or minor version number
43+
val baseVersion = System.getenv("BASE_VERSION") ?: "0.5"
44+
val safeBranchName = if (branchName == "main" || branchName == "HEAD") "" else ".${branchName.replace("/", "-")}"
45+
version = "$baseVersion.$commitCount-preview+g$gitHash$safeBranchName"
46+
47+
println("Project version: $version") // prints when Gradle evaluates the build
48+
149
plugins {
250
id("java")
351
id("java-library")
@@ -6,7 +54,6 @@ plugins {
654
}
755

856
group = "dev.dbos"
9-
version = "1.0-SNAPSHOT"
1057

1158
tasks.withType<JavaCompile> {
1259
options.release.set(11) // Targets Java 11 bytecode (RECOMMENDED)
@@ -85,15 +132,23 @@ publishing {
85132

86133
publications {
87134
create<MavenPublication>("mavenJava") {
88-
89-
// change in
90-
artifactId = "transact"
91-
92135
from(components["java"])
93-
136+
artifactId = "transact"
137+
groupId = project.group.toString()
138+
version = project.version.toString()
94139
}
95140
}
96141
repositories {
97142
mavenLocal()
143+
maven {
144+
name = "GitHubPackages"
145+
url = uri("https://maven.pkg.github.com/dbos-inc/dbos-transact-java") // replace OWNER/REPO
146+
credentials {
147+
username = project.findProperty("gpr.user")?.toString()
148+
?: System.getenv("USERNAME")
149+
password = project.findProperty("gpr.token")?.toString()
150+
?: System.getenv("TOKEN")
151+
}
152+
}
98153
}
99-
}
154+
}

src/main/java/dev/dbos/transact/conductor/protocol/RetentionRequest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ public static class RetentionBody {
99
public Long timeout_cutoff_epoch_ms;
1010
}
1111

12-
public RetentionRequest() {}
12+
public RetentionRequest() {
13+
}
1314

1415
public RetentionRequest(String requestId, Long gcCutoff, Long gcRowsThreshold, Long timeoutCutoff) {
1516
this.type = MessageType.RETENTION.getValue();

src/test/java/dev/dbos/transact/workflow/GCServiceImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package dev.dbos.transact.workflow;
22

3-
import java.util.concurrent.CountDownLatch;
4-
53
import dev.dbos.transact.DBOS;
64
import dev.dbos.transact.context.DBOSContextHolder;
75

6+
import java.util.concurrent.CountDownLatch;
7+
88
public class GCServiceImpl implements GCService {
99

1010
GCService self;

src/test/java/dev/dbos/transact/workflow/WorkflowMgmtTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,8 @@ void globalTimeout() throws Exception {
527527

528528
Thread.sleep(1000L);
529529

530-
// Wait one second, start one final workflow, then timeout all workflows started more than one second ago
530+
// Wait one second, start one final workflow, then timeout all workflows started
531+
// more than one second ago
531532
WorkflowHandle<String> finalHandle = dbos.startWorkflow(() -> gcService.timeoutBlockedWorkflow());
532533

533534
dbosExecutor.globalTimeout(System.currentTimeMillis() - 1000);

0 commit comments

Comments
 (0)