From e0dc50fca49d971fb8938a5eef46f0f90079eeb9 Mon Sep 17 00:00:00 2001 From: kishore Date: Mon, 19 Oct 2026 05:08:46 -0700 Subject: [PATCH 1/3] [INTST-1757] INTST-1757 Add scheduled CI and package smoke checks for Java client --- .github/workflows/code-check.yml | 42 +++++++++ README.md | 35 ++++++++ pom.xml | 39 +++++++- src/it/package-smoke/pom.xml | 55 ++++++++++++ .../src/main/java/PackageSmoke.java | 90 +++++++++++++++++++ 5 files changed, 260 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/code-check.yml create mode 100644 src/it/package-smoke/pom.xml create mode 100644 src/it/package-smoke/src/main/java/PackageSmoke.java diff --git a/.github/workflows/code-check.yml b/.github/workflows/code-check.yml new file mode 100644 index 0000000..ee8e6eb --- /dev/null +++ b/.github/workflows/code-check.yml @@ -0,0 +1,42 @@ +name: Code Quality Check + +on: + push: + branches: [main] + pull_request: + schedule: + # Check runtime compatibility every Monday at 04:27 UTC. + - cron: '27 4 * * 1' + workflow_dispatch: + +permissions: + contents: read + +jobs: + build: + name: Java ${{ matrix.java }} + runs-on: ubuntu-latest + timeout-minutes: 15 + + strategy: + fail-fast: false + matrix: + # Tests require Java 17; current follows the latest stable Temurin JDK. + java: ['17', '21', '25', 'current'] + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Java + uses: actions/setup-java@v5 + with: + distribution: temurin + # A stable version range follows new major releases, not early-access builds. + java-version: ${{ matrix.java == 'current' && '>=17' || matrix.java }} + check-latest: true + cache: maven + overwrite-settings: false + + - name: Test and smoke-test the packaged client + run: mvn --batch-mode --no-transfer-progress clean verify diff --git a/README.md b/README.md index f094c59..6960b28 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,41 @@ A simple client library to remotely access the `Sailthru REST API` as per [http: By default, it will make request in `JSON` format. +Development and compatibility checks +------------------------------------ + +The library is compiled with a Java 8 target. Building and running its test suite +requires JDK 17 or newer. CI checks JDK 17, 21, 25, and the latest stable Eclipse +Temurin JDK. The `current` matrix entry uses the stable version range `>=17` with +`check-latest: true`, so it follows new stable releases without editing the workflow. +Early-access runtimes are not included. + +Run the complete checks locally with Maven 3.9 and JDK 17 or newer: + +```bash +mvn --batch-mode --no-transfer-progress clean verify +``` + +This runs the existing JUnit suite, builds the JAR, and smoke-tests it through a +separate consumer project in `src/it/package-smoke`. The Maven Invoker stages the +fresh JAR and its POM in `target/package-smoke-repository` and runs the consumer +from `target/package-smoke`. The consumer loads the JAR with only its declared +consumer dependencies, creates a client with fake credentials, and sends a POST +to a loopback HTTP server. It checks the request fields, signature format, and +parsed response without contacting the Sailthru API or changing customer data. +Generated files stay under `target` and are removed by `mvn clean`. + +The package smoke check is bound to `verify`, before the normal Maven `install` +and `deploy` phases. The command above validates locally; it does not publish. +For only the existing unit tests, run `mvn test`. + +GitHub Actions runs the complete checks on pull requests, pushes to `main`, and +weekly on Mondays at 04:27 UTC. A manual run is also available. Schedules start +after the workflow is merged into the default branch. Maintainers should check +that schedules remain enabled: GitHub automatically disables scheduled workflows +in public repositories after 60 days without repository activity; see +[GitHub's schedule documentation](https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows#schedule). + Examples -------- diff --git a/pom.xml b/pom.xml index 9d47b99..4acb98a 100644 --- a/pom.xml +++ b/pom.xml @@ -80,6 +80,8 @@ 3.12.0 3.3.1 3.2.8 + 3.10.1 + 3.5.4 @@ -204,6 +206,41 @@ + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + true + + + + org.apache.maven.plugins + maven-invoker-plugin + ${maven-invoker-plugin.version} + + src/it + ${project.build.directory}/package-smoke + ${project.build.directory}/package-smoke-repository + ${java.home} + + verify + + true + 300 + + + + smoke-test-packaged-client + + verify + + install + run + + + + org.apache.maven.plugins maven-release-plugin @@ -293,4 +330,4 @@ - \ No newline at end of file + diff --git a/src/it/package-smoke/pom.xml b/src/it/package-smoke/pom.xml new file mode 100644 index 0000000..8d14933 --- /dev/null +++ b/src/it/package-smoke/pom.xml @@ -0,0 +1,55 @@ + + 4.0.0 + com.sailthru.smoke + packaged-client-consumer + 1.0-SNAPSHOT + + + UTF-8 + 17 + + + + + + @project.groupId@ + @project.artifactId@ + @project.version@ + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.14.1 + + + org.codehaus.mojo + exec-maven-plugin + 3.6.4 + + + exercise-installed-client + verify + + exec + + + ${java.home}/bin/java + + -classpath + + PackageSmoke + + runtime + 30000 + + + + + + + diff --git a/src/it/package-smoke/src/main/java/PackageSmoke.java b/src/it/package-smoke/src/main/java/PackageSmoke.java new file mode 100644 index 0000000..deb16a4 --- /dev/null +++ b/src/it/package-smoke/src/main/java/PackageSmoke.java @@ -0,0 +1,90 @@ +import com.google.gson.Gson; +import com.sailthru.client.ApiAction; +import com.sailthru.client.SailthruClient; +import com.sailthru.client.handler.response.JsonResponse; +import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpServer; +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.atomic.AtomicReference; + +/** A consumer of the packaged JAR, with no library source classes or test dependencies. */ +public class PackageSmoke { + public static void main(String[] args) throws Exception { + String location = SailthruClient.class.getProtectionDomain().getCodeSource().getLocation().getPath(); + check(location.endsWith(".jar"), "The client must load from the installed JAR: " + location); + + AtomicReference serverFailure = new AtomicReference<>(); + HttpServer server = HttpServer.create(new InetSocketAddress("127.0.0.1", 0), 0); + server.createContext("/user", exchange -> { + try { + check("POST".equals(exchange.getRequestMethod()), "Expected a POST request"); + check("/user".equals(exchange.getRequestURI().getPath()), "Expected the /user endpoint"); + Map params = formParameters(exchange); + check("smoke-key".equals(params.get("api_key")), "API key was not preserved"); + check("json".equals(params.get("format")), "Expected the JSON response format"); + Map payload = new Gson().fromJson(params.get("json"), Map.class); + check("smoke@example.com".equals(payload.get("id")), "User payload was not preserved"); + String signature = params.get("sig"); + check(signature != null && signature.matches("[a-f0-9]{32}"), "Missing or malformed signature"); + reply(exchange, 200, "{\"ok\":true}"); + } catch (Exception | AssertionError failure) { + serverFailure.set(failure); + reply(exchange, 500, "{\"error\":\"smoke request validation failed\"}"); + } finally { + exchange.close(); + } + }); + server.start(); + + SailthruClient client = null; + try { + String apiUrl = "http://127.0.0.1:" + server.getAddress().getPort(); + client = new SailthruClient("smoke-key", "smoke-secret", apiUrl); + Map user = new HashMap<>(); + user.put("id", "smoke@example.com"); + JsonResponse result = client.apiPost(ApiAction.user, user); + + if (serverFailure.get() != null) { + throw new AssertionError("Local server rejected the client request", serverFailure.get()); + } + check(result.isOK(), "Client reported an unsuccessful response"); + check(Boolean.TRUE.equals(result.getResponse().get("ok")), "Client did not parse the response"); + System.out.println("Packaged client loaded and completed a local API request."); + } finally { + if (client != null) { + client.getSailthruHttpClient().getConnectionManager().shutdown(); + } + server.stop(0); + } + } + + private static Map formParameters(HttpExchange exchange) throws IOException { + String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8); + Map params = new HashMap<>(); + for (String field : body.split("&")) { + String[] pair = field.split("=", 2); + check(pair.length == 2, "Malformed form field"); + params.put(URLDecoder.decode(pair[0], StandardCharsets.UTF_8), + URLDecoder.decode(pair[1], StandardCharsets.UTF_8)); + } + return params; + } + + private static void reply(HttpExchange exchange, int status, String json) throws IOException { + byte[] body = json.getBytes(StandardCharsets.UTF_8); + exchange.getResponseHeaders().set("Content-Type", "application/json"); + exchange.sendResponseHeaders(status, body.length); + exchange.getResponseBody().write(body); + } + + private static void check(boolean condition, String message) { + if (!condition) { + throw new AssertionError(message); + } + } +} From 6d1170577a9071a0764ca4be13f198d86c5b0582 Mon Sep 17 00:00:00 2001 From: kishore Date: Mon, 19 Oct 2026 09:59:18 -0700 Subject: [PATCH 2/3] [INTST-1757] INTST-1757 Shorten CI documentation --- README.md | 31 +++++-------------------------- 1 file changed, 5 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 6960b28..98d3ca6 100644 --- a/README.md +++ b/README.md @@ -11,37 +11,16 @@ By default, it will make request in `JSON` format. Development and compatibility checks ------------------------------------ -The library is compiled with a Java 8 target. Building and running its test suite -requires JDK 17 or newer. CI checks JDK 17, 21, 25, and the latest stable Eclipse -Temurin JDK. The `current` matrix entry uses the stable version range `>=17` with -`check-latest: true`, so it follows new stable releases without editing the workflow. -Early-access runtimes are not included. - -Run the complete checks locally with Maven 3.9 and JDK 17 or newer: +Use Maven 3.9 and JDK 17+; the library retains its Java 8 compilation target. +CI tests Java 17, 21, 25, and the latest stable Temurin JDK on PRs, pushes to +`main`, weekly, and manual runs. ```bash mvn --batch-mode --no-transfer-progress clean verify ``` -This runs the existing JUnit suite, builds the JAR, and smoke-tests it through a -separate consumer project in `src/it/package-smoke`. The Maven Invoker stages the -fresh JAR and its POM in `target/package-smoke-repository` and runs the consumer -from `target/package-smoke`. The consumer loads the JAR with only its declared -consumer dependencies, creates a client with fake credentials, and sends a POST -to a loopback HTTP server. It checks the request fields, signature format, and -parsed response without contacting the Sailthru API or changing customer data. -Generated files stay under `target` and are removed by `mvn clean`. - -The package smoke check is bound to `verify`, before the normal Maven `install` -and `deploy` phases. The command above validates locally; it does not publish. -For only the existing unit tests, run `mvn test`. - -GitHub Actions runs the complete checks on pull requests, pushes to `main`, and -weekly on Mondays at 04:27 UTC. A manual run is also available. Schedules start -after the workflow is merged into the default branch. Maintainers should check -that schedules remain enabled: GitHub automatically disables scheduled workflows -in public repositories after 60 days without repository activity; see -[GitHub's schedule documentation](https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows#schedule). +This runs unit tests and tests the built JAR through a separate consumer using a +local server and dummy credentials. It does not publish. Use `mvn test` for unit tests only. Examples -------- From cfe4644f61f7f70f59ffc91e27fdf00e6f9cc3a0 Mon Sep 17 00:00:00 2001 From: kishore Date: Mon, 26 Oct 2026 07:53:50 -0700 Subject: [PATCH 3/3] [INTST-1757] INTST-1757 Discover complete stable runtime matrices for CI --- .github/scripts/runtime-matrix.cjs | 25 ++++++++++++++++++ .github/scripts/runtime-matrix.test.cjs | 35 +++++++++++++++++++++++++ .github/workflows/code-check.yml | 24 ++++++++++++++--- README.md | 4 +-- 4 files changed, 82 insertions(+), 6 deletions(-) create mode 100644 .github/scripts/runtime-matrix.cjs create mode 100644 .github/scripts/runtime-matrix.test.cjs diff --git a/.github/scripts/runtime-matrix.cjs b/.github/scripts/runtime-matrix.cjs new file mode 100644 index 0000000..52321b9 --- /dev/null +++ b/.github/scripts/runtime-matrix.cjs @@ -0,0 +1,25 @@ +// Discover every stable release line from the existing CI minimum. +const metadataUrl = 'https://api.adoptium.net/v3/info/available_releases'; +const compare = (a, b) => a.localeCompare(b, 'en', {numeric: true}); + +module.exports = async function discover({core, fetch = globalThis.fetch}) { + const response = await fetch(metadataUrl, { + headers: {'User-Agent': 'sailthru-ci-runtime-matrix'}, + signal: AbortSignal.timeout(30000) + }); + if (!response.ok) throw new Error(`Runtime metadata request failed: ${response.status}`); + const releases = await response.json(); + // The feature release is GA; tip_version/most_recent_feature_version may be EA. + const latest = releases.most_recent_feature_release; + if (!Number.isSafeInteger(latest) || latest < 17 || latest > 272) { + throw new Error('Invalid latest stable Java feature release'); + } + const versions = Array.from({length: latest - 16}, (_, index) => String(index + 17)); + + const matrix = [...new Set(versions)].sort(compare); + if (!matrix.includes('17') || matrix.length > 256) { + throw new Error('Runtime matrix is incomplete or exceeds the GitHub Actions limit'); + } + core.info(`Testing java release lines: ${matrix.join(', ')}`); + core.setOutput('versions', JSON.stringify(matrix)); +}; diff --git a/.github/scripts/runtime-matrix.test.cjs b/.github/scripts/runtime-matrix.test.cjs new file mode 100644 index 0000000..94a7239 --- /dev/null +++ b/.github/scripts/runtime-matrix.test.cjs @@ -0,0 +1,35 @@ +const {test} = require('node:test'); +const assert = require('node:assert/strict'); +const discover = require('./runtime-matrix.cjs'); + +async function resolve(releases) { + let output; + await discover({ + core: {info() {}, setOutput(name, value) { + assert.equal(name, 'versions'); + output = JSON.parse(value); + }}, + fetch: async () => ({ok: true, json: async () => releases}) + }); + return output; +} + +test('includes intermediate and future stable releases, excludes prereleases and duplicates', async () => { + const releases = {most_recent_feature_release: 30, most_recent_feature_version: 31, tip_version: 32}; + assert.deepEqual(await resolve(releases), Array.from({length: 14}, (_, index) => String(index + 17))); +}); + +test('fails rather than quietly running an empty or incomplete matrix', async () => { + await assert.rejects(resolve({})); + await assert.rejects(resolve({most_recent_feature_release: 16})); + await assert.rejects(resolve(null)); +}); + +test('metadata HTTP, JSON and network failures fail discovery without emitting a matrix', async () => { + const core = {info() {}, setOutput() {assert.fail('Must not emit a fallback matrix');}}; + await assert.rejects(discover({core, fetch: async () => ({ok: false, status: 503})}), /503/); + await assert.rejects(discover({core, fetch: async () => ({ + ok: true, json: async () => {throw new SyntaxError('Invalid JSON');} + })}), /Invalid JSON/); + await assert.rejects(discover({core, fetch: async () => {throw new Error('Network failure');}}), /Network failure/); +}); diff --git a/.github/workflows/code-check.yml b/.github/workflows/code-check.yml index ee8e6eb..36c390f 100644 --- a/.github/workflows/code-check.yml +++ b/.github/workflows/code-check.yml @@ -13,7 +13,25 @@ permissions: contents: read jobs: + discover: + name: Discover runtimes + runs-on: ubuntu-latest + timeout-minutes: 5 + outputs: + versions: ${{ steps.versions.outputs.versions }} + steps: + - uses: actions/checkout@v4 + - name: Test discovery and list stable runtimes + id: versions + uses: actions/github-script@v7 + with: + script: | + require('node:child_process').execFileSync(process.execPath, + ['--test', '.github/scripts/runtime-matrix.test.cjs'], {stdio: 'inherit'}); + await require('./.github/scripts/runtime-matrix.cjs')({core}); + build: + needs: discover name: Java ${{ matrix.java }} runs-on: ubuntu-latest timeout-minutes: 15 @@ -21,8 +39,7 @@ jobs: strategy: fail-fast: false matrix: - # Tests require Java 17; current follows the latest stable Temurin JDK. - java: ['17', '21', '25', 'current'] + java: ${{ fromJSON(needs.discover.outputs.versions) }} steps: - name: Checkout @@ -32,8 +49,7 @@ jobs: uses: actions/setup-java@v5 with: distribution: temurin - # A stable version range follows new major releases, not early-access builds. - java-version: ${{ matrix.java == 'current' && '>=17' || matrix.java }} + java-version: ${{ matrix.java }} check-latest: true cache: maven overwrite-settings: false diff --git a/README.md b/README.md index 98d3ca6..969856e 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,8 @@ Development and compatibility checks ------------------------------------ Use Maven 3.9 and JDK 17+; the library retains its Java 8 compilation target. -CI tests Java 17, 21, 25, and the latest stable Temurin JDK on PRs, pushes to -`main`, weekly, and manual runs. +CI discovers every Java feature version from 17 through the latest stable Temurin +JDK on PRs, pushes to `main`, weekly, and manual runs. ```bash mvn --batch-mode --no-transfer-progress clean verify