Skip to content

Commit 730f03f

Browse files
authored
Fix release signing gate; bump next version shape; refresh Maven badge; CI improvements (#1781)
* Fix release signing gate; bump next version shape; refresh Maven badge. * CI: drop runner-wide apt upgrade, cache samtools build, modernize actions, upgrade to latest samtools * CI: use gradle/actions/setup-gradle to cache the wrapper distribution. * Make samtools version test a ">=" check.
1 parent fb57878 commit 730f03f

7 files changed

Lines changed: 118 additions & 34 deletions

File tree

.github/workflows/tests.yml

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ on:
1010
jobs:
1111
test:
1212
env:
13-
HTSJDK_SAMTOOLS_BIN: /usr/bin/samtools
13+
HTSJDK_SAMTOOLS_BIN: /usr/local/bin/samtools
14+
SAMTOOLS_VERSION: 1.23.1
1415
runs-on: ubuntu-latest
1516
strategy:
1617
matrix:
@@ -20,20 +21,28 @@ jobs:
2021
continue-on-error: ${{ matrix.experimental }}
2122
name: Java ${{ matrix.Java }} build and test
2223
steps:
23-
- uses: actions/checkout@v3
24+
- uses: actions/checkout@v4
2425
with:
2526
fetch-depth: 0 # full history + tags so palantir/git-version sees the latest release tag
2627
- name: Set up java ${{ matrix.Java }}
27-
uses: actions/setup-java@v3
28+
uses: actions/setup-java@v4
2829
with:
2930
java-version: ${{ matrix.Java }}
30-
distribution: 'adopt'
31-
cache: gradle
31+
distribution: 'temurin'
32+
- name: Set up Gradle
33+
uses: gradle/actions/setup-gradle@v4
3234
- name: Grant execute permission for gradlew
3335
run: chmod +x gradlew
3436
- name: Compile with Gradle
3537
run: ./gradlew compileJava
38+
- name: Cache samtools
39+
id: cache-samtools
40+
uses: actions/cache@v4
41+
with:
42+
path: /usr/local/bin/samtools
43+
key: samtools-${{ env.SAMTOOLS_VERSION }}-${{ runner.os }}
3644
- name: Install Samtools
45+
if: steps.cache-samtools.outputs.cache-hit != 'true'
3746
run: scripts/install-samtools.sh
3847
- name: Start the htsget server
3948
run: scripts/htsget-scripts/start-htsget-test-server.sh
@@ -50,15 +59,16 @@ jobs:
5059
runs-on: ubuntu-latest
5160
name: Tests that require external APIs
5261
steps:
53-
- uses: actions/checkout@v3
62+
- uses: actions/checkout@v4
5463
with:
5564
fetch-depth: 0 # full history + tags so palantir/git-version sees the latest release tag
5665
- name: Set up java 17
57-
uses: actions/setup-java@v3
66+
uses: actions/setup-java@v4
5867
with:
5968
java-version: '17'
60-
distribution: 'adopt'
61-
cache: gradle
69+
distribution: 'temurin'
70+
- name: Set up Gradle
71+
uses: gradle/actions/setup-gradle@v4
6272
- name: Grant execute permission for gradlew
6373
run: chmod +x gradlew
6474
- name: Compile with Gradle
@@ -75,15 +85,16 @@ jobs:
7585
runs-on: ubuntu-latest
7686
name: Java Format Check
7787
steps:
78-
- uses: actions/checkout@v3
88+
- uses: actions/checkout@v4
7989
with:
8090
fetch-depth: 0 # full history + tags so palantir/git-version sees the latest release tag
8191
- name: Set up java 17
82-
uses: actions/setup-java@v3
92+
uses: actions/setup-java@v4
8393
with:
8494
java-version: '17'
85-
distribution: 'adopt'
86-
cache: gradle
95+
distribution: 'temurin'
96+
- name: Set up Gradle
97+
uses: gradle/actions/setup-gradle@v4
8798
- name: Grant execute permission for gradlew
8899
run: chmod +x gradlew
89100
- name: Verify formatting
@@ -92,15 +103,16 @@ jobs:
92103
runs-on: ubuntu-latest
93104
name: SpotBugs
94105
steps:
95-
- uses: actions/checkout@v3
106+
- uses: actions/checkout@v4
96107
with:
97108
fetch-depth: 0 # full history + tags so palantir/git-version sees the latest release tag
98109
- name: Set up java 17
99-
uses: actions/setup-java@v3
110+
uses: actions/setup-java@v4
100111
with:
101112
java-version: '17'
102-
distribution: 'adopt'
103-
cache: gradle
113+
distribution: 'temurin'
114+
- name: Set up Gradle
115+
uses: gradle/actions/setup-gradle@v4
104116
- name: Grant execute permission for gradlew
105117
run: chmod +x gradlew
106118
- name: Compile with Gradle
@@ -111,6 +123,3 @@ jobs:
111123
with:
112124
name: spotBugs-Report
113125
path: build/reports/spotbugs
114-
115-
116-

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[![Build and Test](https://github.com/samtools/htsjdk/actions/workflows/tests.yml/badge.svg?branch=master&event=push)](https://github.com/samtools/htsjdk/actions/workflows/tests.yml)
2-
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.samtools/htsjdk/badge.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.github.samtools%22%20AND%20a%3A%22htsjdk%22)
2+
[![Maven Central](https://img.shields.io/maven-central/v/com.github.samtools/htsjdk.svg?label=Maven%20Central)](https://central.sonatype.com/artifact/com.github.samtools/htsjdk)
33
[![License](http://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/samtools/htsjdk)
44
[![Language](http://img.shields.io/badge/language-java-brightgreen.svg)](https://www.java.com/)
55
## A Java API for high-throughput sequencing data (HTS) formats.

build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ java {
102102
//
103103
// To change the planned bump (e.g. after a release lands), update nextVersionBump
104104
// below and commit.
105-
final nextVersionBump = "x"
105+
final nextVersionBump = "x.x.x"
106106

107107
final isRelease = Boolean.getBoolean("release")
108108
final details = versionDetails()
@@ -189,7 +189,7 @@ tasks.withType(Test).configureEach { task ->
189189

190190
// set heap size for the test JVM(s)
191191
task.minHeapSize = "1G"
192-
task.maxHeapSize = "12G"
192+
task.maxHeapSize = "14G"
193193

194194
task.jvmArgs '-Djava.awt.headless=true' //this prevents awt from displaying a java icon while the tests are running
195195

@@ -352,9 +352,9 @@ publishing {
352352
signing {
353353
useGpgCmd()
354354
sign(publishing.publications.htsjdk)
355-
required = { isRelease && gradle.taskGraph.hasTask("publishAllPublicationsToCentralPortal") }
355+
required = { isRelease }
356356
tasks.withType(Sign).configureEach {
357-
onlyIf { isRelease && gradle.taskGraph.hasTask("publishAllPublicationsToCentralPortal") }
357+
onlyIf { isRelease }
358358
}
359359
}
360360

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.gradle.jvmargs=-Xmx512m -XX:MaxMetaspaceSize=256m

scripts/install-samtools.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
#!/bin/sh
22
set -ex
3-
#ubuntu specific
3+
# ubuntu specific
44
sudo apt-get update
5-
sudo apt-get upgrade
65
sudo apt-get install -y libncurses-dev libbz2-dev liblzma-dev
76

8-
#install from the github tar
9-
export SAMTOOLS_VERSION=1.21
7+
# install from the github tar
8+
export SAMTOOLS_VERSION=1.23.1
109
wget https://github.com/samtools/samtools/releases/download/${SAMTOOLS_VERSION}/samtools-${SAMTOOLS_VERSION}.tar.bz2
1110
tar -xjvf samtools-${SAMTOOLS_VERSION}.tar.bz2
12-
cd samtools-${SAMTOOLS_VERSION} && ./configure --prefix=/usr && make && sudo make install
11+
cd samtools-${SAMTOOLS_VERSION} && ./configure --prefix=/usr/local && make && sudo make install

src/test/java/htsjdk/utils/SamtoolsTestUtils.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,46 @@
88
import java.nio.file.Files;
99
import java.nio.file.Path;
1010
import java.nio.file.Paths;
11+
import java.util.regex.Matcher;
12+
import java.util.regex.Pattern;
1113

1214
/**
1315
* Test utilities for running samtools from htsjdk tests.
1416
*/
1517
public class SamtoolsTestUtils {
1618
private static final String SAMTOOLS_BINARY_ENV_VARIABLE = "HTSJDK_SAMTOOLS_BIN";
17-
public static final String expectedSamtoolsVersion = "1.21";
19+
public static final String minimumSamtoolsVersion = "1.23.1";
20+
21+
private static final Pattern SAMTOOLS_VERSION_PATTERN = Pattern.compile("(?m)^samtools\\s+(\\d+(?:\\.\\d+)*)");
22+
23+
/**
24+
* Extracts the version string (e.g. "1.23.1") from the output of `samtools --version`,
25+
* which begins with a line of the form {@code samtools <version>}.
26+
*
27+
* @return the version string, or null if no version line was found.
28+
*/
29+
static String parseSamtoolsVersion(final String samtoolsVersionOutput) {
30+
final Matcher m = SAMTOOLS_VERSION_PATTERN.matcher(samtoolsVersionOutput);
31+
return m.find() ? m.group(1) : null;
32+
}
33+
34+
/**
35+
* Compares two dotted-numeric version strings (e.g. "1.23.1") component-by-component.
36+
* Missing trailing components are treated as zero, so "1.23" is equal to "1.23.0".
37+
*/
38+
static int compareVersions(final String a, final String b) {
39+
final String[] aParts = a.split("\\.");
40+
final String[] bParts = b.split("\\.");
41+
final int len = Math.max(aParts.length, bParts.length);
42+
for (int i = 0; i < len; i++) {
43+
final int av = i < aParts.length ? Integer.parseInt(aParts[i]) : 0;
44+
final int bv = i < bParts.length ? Integer.parseInt(bParts[i]) : 0;
45+
if (av != bv) {
46+
return Integer.compare(av, bv);
47+
}
48+
}
49+
return 0;
50+
}
1851

1952
/**
2053
* @return true if samtools is available, otherwise false

src/test/java/htsjdk/utils/SamtoolsTestUtilsTest.java

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,52 @@ public void testSamtoolsVersion() {
2727
if (!SamtoolsTestUtils.isSamtoolsAvailable()) {
2828
throw new SkipException("Samtools not available on local device");
2929
}
30-
// If this test runs, but fails because version validation fails, then the local samtools version is
31-
// not the one expected by the htsjdk tests
3230
final ProcessExecutor.ExitStatusAndOutput processStatus = SamtoolsTestUtils.executeSamToolsCommand("--version");
33-
Assert.assertTrue(processStatus.stdout.contains(SamtoolsTestUtils.expectedSamtoolsVersion));
31+
final String localVersion = SamtoolsTestUtils.parseSamtoolsVersion(processStatus.stdout);
32+
Assert.assertNotNull(
33+
localVersion,
34+
"Could not parse samtools version from `samtools --version` output: " + processStatus.stdout);
35+
Assert.assertTrue(
36+
SamtoolsTestUtils.compareVersions(localVersion, SamtoolsTestUtils.minimumSamtoolsVersion) >= 0,
37+
"Local samtools version " + localVersion + " is older than the minimum required by htsjdk tests ("
38+
+ SamtoolsTestUtils.minimumSamtoolsVersion + ")");
39+
}
40+
41+
@Test
42+
public void testParseSamtoolsVersionFromTypicalOutput() {
43+
final String stdout = "samtools 1.23.1\nUsing htslib 1.23.1\nCopyright (C) 2024 Genome Research Ltd.\n";
44+
Assert.assertEquals(SamtoolsTestUtils.parseSamtoolsVersion(stdout), "1.23.1");
45+
}
46+
47+
@Test
48+
public void testParseSamtoolsVersionTwoComponent() {
49+
Assert.assertEquals(SamtoolsTestUtils.parseSamtoolsVersion("samtools 1.21\n"), "1.21");
50+
}
51+
52+
@Test
53+
public void testParseSamtoolsVersionReturnsNullWhenAbsent() {
54+
Assert.assertNull(SamtoolsTestUtils.parseSamtoolsVersion("nothing recognizable here\n"));
55+
}
56+
57+
@Test
58+
public void testCompareVersionsEqualWithImplicitZero() {
59+
Assert.assertEquals(SamtoolsTestUtils.compareVersions("1.23", "1.23.0"), 0);
60+
}
61+
62+
@Test
63+
public void testCompareVersionsPatchGreater() {
64+
Assert.assertTrue(SamtoolsTestUtils.compareVersions("1.23.1", "1.23") > 0);
65+
}
66+
67+
@Test
68+
public void testCompareVersionsMajorLess() {
69+
Assert.assertTrue(SamtoolsTestUtils.compareVersions("1.21", "1.23.1") < 0);
70+
}
71+
72+
@Test
73+
public void testCompareVersionsNumericNotLexical() {
74+
// 1.10 is greater than 1.9 numerically, even though "1.10" sorts before "1.9" lexically.
75+
Assert.assertTrue(SamtoolsTestUtils.compareVersions("1.10", "1.9") > 0);
3476
}
3577

3678
@Test(expectedExceptions = RuntimeException.class)

0 commit comments

Comments
 (0)