Skip to content

Commit 5b988af

Browse files
committed
Update workflows.
1 parent 73791ee commit 5b988af

8 files changed

+352
-4
lines changed

.github/workflows/Tools.java

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
/*
2+
* Copyright © 2024 Mark Raynsford <code@io7m.com> https://www.io7m.com
3+
*
4+
* Permission to use, copy, modify, and/or distribute this software for any
5+
* purpose with or without fee is hereby granted, provided that the above
6+
* copyright notice and this permission notice appear in all copies.
7+
*
8+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11+
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
14+
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15+
*/
16+
17+
import org.w3c.dom.Node;
18+
import org.w3c.dom.NodeList;
19+
20+
import javax.xml.parsers.DocumentBuilderFactory;
21+
import javax.xml.xpath.XPathConstants;
22+
import javax.xml.xpath.XPathFactory;
23+
import java.io.File;
24+
import java.io.IOException;
25+
import java.util.List;
26+
import java.util.TreeMap;
27+
28+
public final class Tools
29+
{
30+
private static final TreeMap<String, OpType> OPS =
31+
new TreeMap<>();
32+
33+
static {
34+
final var opsList = List.of(
35+
new ShowProjectVersion(),
36+
new ShowProjectIsSnapshot()
37+
);
38+
39+
for (final var op : opsList) {
40+
OPS.put(op.name(), op);
41+
}
42+
}
43+
44+
private Tools()
45+
{
46+
47+
}
48+
49+
private interface OpType
50+
{
51+
String name();
52+
53+
void execute(String[] args)
54+
throws Exception;
55+
}
56+
57+
private static String getProjectVersion(
58+
final File file)
59+
throws Exception
60+
{
61+
final var documentBuilders =
62+
DocumentBuilderFactory.newInstance();
63+
final var documentBuilder =
64+
documentBuilders.newDocumentBuilder();
65+
final var document =
66+
documentBuilder.parse(file);
67+
68+
final var xPathFactory =
69+
XPathFactory.newInstance();
70+
final var xPath =
71+
xPathFactory.newXPath();
72+
73+
final var nodes =
74+
(NodeList) xPath.evaluate(
75+
"//project/version",
76+
document,
77+
XPathConstants.NODESET
78+
);
79+
80+
for (var i = 0; i < nodes.getLength(); i++) {
81+
final var node = nodes.item(i);
82+
if (node.getNodeType() == Node.ELEMENT_NODE) {
83+
return node.getTextContent().trim();
84+
}
85+
}
86+
87+
throw new IOException(
88+
"Could not locate a //project/version node!"
89+
);
90+
}
91+
92+
private static final class ShowProjectVersion implements OpType
93+
{
94+
ShowProjectVersion()
95+
{
96+
97+
}
98+
99+
@Override
100+
public String name()
101+
{
102+
return "ShowProjectVersion";
103+
}
104+
105+
@Override
106+
public void execute(
107+
final String[] args)
108+
throws Exception
109+
{
110+
System.out.print("IO7M_PROJECT_VERSION=");
111+
System.out.println(getProjectVersion(new File(args[1])));
112+
}
113+
}
114+
115+
private static final class ShowProjectIsSnapshot implements OpType
116+
{
117+
ShowProjectIsSnapshot()
118+
{
119+
120+
}
121+
122+
@Override
123+
public String name()
124+
{
125+
return "ShowProjectIsSnapshot";
126+
}
127+
128+
@Override
129+
public void execute(
130+
final String[] args)
131+
throws Exception
132+
{
133+
System.out.print("IO7M_PROJECT_VERSION_IS_SNAPSHOT=");
134+
System.out.println(
135+
getProjectVersion(new File(args[1])).endsWith("-SNAPSHOT")
136+
);
137+
}
138+
}
139+
140+
public static void main(
141+
final String[] args)
142+
throws Exception
143+
{
144+
if (args.length == 0) {
145+
System.err.println("Usage: command");
146+
System.exit(1);
147+
}
148+
149+
final var op = OPS.get(args[0]);
150+
if (op == null) {
151+
System.err.println("Unrecognized command.");
152+
System.err.println(" Must be one of:");
153+
for (final var name : OPS.keySet()) {
154+
System.err.print(" ");
155+
System.err.println(name);
156+
}
157+
System.exit(1);
158+
}
159+
160+
op.execute(args);
161+
}
162+
}

.github/workflows/deploy-release.sh

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/sh
2+
3+
fatal()
4+
{
5+
echo "fatal: $1" 1>&2
6+
exit 1
7+
}
8+
9+
if [ -z "${MAVEN_CENTRAL_USERNAME}" ]
10+
then
11+
fatal "MAVEN_CENTRAL_USERNAME is not set."
12+
fi
13+
14+
if [ -z "${MAVEN_CENTRAL_PASSWORD}" ]
15+
then
16+
fatal "MAVEN_CENTRAL_PASSWORD is not set."
17+
fi
18+
19+
(cat <<EOF
20+
<settings
21+
xmlns="http://maven.apache.org/SETTINGS/1.0.0"
22+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
23+
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
24+
25+
<profiles>
26+
<profile>
27+
<id>io7m</id>
28+
<properties>
29+
<gpg.useagent>true</gpg.useagent>
30+
<gpg.keyname>github-ci-maven-rsa-key</gpg.keyname>
31+
<io7m.deployment>true</io7m.deployment>
32+
</properties>
33+
</profile>
34+
</profiles>
35+
36+
<servers>
37+
<server>
38+
<id>sonatype-nexus-snapshots</id>
39+
<username>${MAVEN_CENTRAL_USERNAME}</username>
40+
<password>${MAVEN_CENTRAL_PASSWORD}</password>
41+
</server>
42+
<server>
43+
<id>sonatype-nexus-staging</id>
44+
<username>${MAVEN_CENTRAL_USERNAME}</username>
45+
<password>${MAVEN_CENTRAL_PASSWORD}</password>
46+
</server>
47+
</servers>
48+
</settings>
49+
EOF
50+
) > "$HOME/.m2/settings.xml" || fatal "could not update $HOME/.m2/settings.xml"
51+
52+
exec mvn \
53+
-Dio7m.release=true \
54+
-Dio7m.deployment=true \
55+
--batch-mode \
56+
--strict-checksums \
57+
-DskipTests=true \
58+
-DskipITs=true deploy

.github/workflows/deploy-snapshot.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/sh
2+
3+
fatal()
4+
{
5+
echo "fatal: $1" 1>&2
6+
exit 1
7+
}
8+
9+
if [ -z "${MAVEN_CENTRAL_USERNAME}" ]
10+
then
11+
fatal "MAVEN_CENTRAL_USERNAME is not set."
12+
fi
13+
14+
if [ -z "${MAVEN_CENTRAL_PASSWORD}" ]
15+
then
16+
fatal "MAVEN_CENTRAL_PASSWORD is not set."
17+
fi
18+
19+
(cat <<EOF
20+
<settings
21+
xmlns="http://maven.apache.org/SETTINGS/1.0.0"
22+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
23+
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
24+
<servers>
25+
<server>
26+
<id>sonatype-nexus-snapshots</id>
27+
<username>${MAVEN_CENTRAL_USERNAME}</username>
28+
<password>${MAVEN_CENTRAL_PASSWORD}</password>
29+
</server>
30+
<server>
31+
<id>sonatype-nexus-staging</id>
32+
<username>${MAVEN_CENTRAL_USERNAME}</username>
33+
<password>${MAVEN_CENTRAL_PASSWORD}</password>
34+
</server>
35+
</servers>
36+
</settings>
37+
EOF
38+
) > "$HOME/.m2/settings.xml" || fatal "could not update $HOME/.m2/settings.xml"
39+
40+
exec mvn \
41+
--batch-mode \
42+
--strict-checksums \
43+
-DskipTests=true \
44+
-DskipITs=true deploy
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: deploy.linux.temurin.lts
2+
3+
on:
4+
push:
5+
tags: [ com.io7m.cedarbridge-* ]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
13+
- name: JDK
14+
uses: actions/setup-java@v4
15+
with:
16+
java-version: 21
17+
distribution: 'temurin'
18+
19+
- name: Import signing key
20+
env:
21+
PGP_SIGNING_KEY: ${{ secrets.PGP_SIGNING_KEY }}
22+
run: echo "${PGP_SIGNING_KEY}" | gpg --import
23+
24+
- name: Deploy release
25+
env:
26+
MAVEN_CENTRAL_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
27+
MAVEN_CENTRAL_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
28+
run: .github/workflows/deploy-release.sh

.github/workflows/main.linux.temurin.current.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,28 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- uses: actions/checkout@v4
14+
1415
- name: JDK
1516
uses: actions/setup-java@v4
1617
with:
1718
java-version: 22
1819
distribution: 'temurin'
20+
21+
- name: Collect project version
22+
id: project_version
23+
run: java .github/workflows/Tools.java ShowProjectVersion pom.xml >> "$GITHUB_OUTPUT"
24+
25+
- name: Collect project snapshot
26+
id: project_is_snapshot
27+
run: java .github/workflows/Tools.java ShowProjectIsSnapshot pom.xml >> "$GITHUB_OUTPUT"
28+
1929
- name: Build
20-
run: mvn --errors clean verify site
30+
run: mvn --batch-mode --strict-checksums --errors clean verify site
31+
2132
- name: Upload test logs
2233
uses: actions/upload-artifact@v4
2334
if: always()
2435
with:
2536
name: test-logs
2637
path: ./com.io7m.cedarbridge.tests/target/surefire-reports
38+

.github/workflows/main.linux.temurin.lts.yml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,41 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- uses: actions/checkout@v4
14+
1415
- name: JDK
1516
uses: actions/setup-java@v4
1617
with:
1718
java-version: 21
1819
distribution: 'temurin'
20+
21+
- name: Collect project version
22+
id: project_version
23+
run: java .github/workflows/Tools.java ShowProjectVersion pom.xml >> "$GITHUB_OUTPUT"
24+
25+
- name: Collect project snapshot
26+
id: project_is_snapshot
27+
run: java .github/workflows/Tools.java ShowProjectIsSnapshot pom.xml >> "$GITHUB_OUTPUT"
28+
1929
- name: Build
20-
run: mvn --errors clean verify site
30+
run: mvn --batch-mode --strict-checksums --errors clean verify site
31+
2132
- name: Upload test logs
2233
uses: actions/upload-artifact@v4
2334
if: always()
2435
with:
2536
name: test-logs
2637
path: ./com.io7m.cedarbridge.tests/target/surefire-reports
38+
2739
- name: Coverage
2840
uses: codecov/codecov-action@v4.3.1
2941
with:
3042
token: ${{ secrets.CODECOV_TOKEN }}
3143
file: com.io7m.cedarbridge.tests/target/site/jacoco-aggregate/jacoco.xml
44+
45+
- name: Deploy snapshot
46+
if: ${{ steps.project_is_snapshot.outputs.IO7M_PROJECT_VERSION_IS_SNAPSHOT == 'true' }}
47+
env:
48+
MAVEN_CENTRAL_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
49+
MAVEN_CENTRAL_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
50+
run: .github/workflows/deploy-snapshot.sh
51+

.github/workflows/main.windows.temurin.current.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,28 @@ jobs:
1111
runs-on: windows-latest
1212
steps:
1313
- uses: actions/checkout@v4
14+
1415
- name: JDK
1516
uses: actions/setup-java@v4
1617
with:
1718
java-version: 22
1819
distribution: 'temurin'
20+
21+
- name: Collect project version
22+
id: project_version
23+
run: java .github/workflows/Tools.java ShowProjectVersion pom.xml >> "$GITHUB_OUTPUT"
24+
25+
- name: Collect project snapshot
26+
id: project_is_snapshot
27+
run: java .github/workflows/Tools.java ShowProjectIsSnapshot pom.xml >> "$GITHUB_OUTPUT"
28+
1929
- name: Build
20-
run: mvn --errors clean verify site
30+
run: mvn --batch-mode --strict-checksums --errors clean verify site
31+
2132
- name: Upload test logs
2233
uses: actions/upload-artifact@v4
2334
if: always()
2435
with:
2536
name: test-logs
2637
path: ./com.io7m.cedarbridge.tests/target/surefire-reports
38+

0 commit comments

Comments
 (0)