Skip to content

Commit c6f372a

Browse files
committed
Add Publish Workflow
1 parent 25cba58 commit c6f372a

5 files changed

Lines changed: 149 additions & 10 deletions

File tree

.github/workflows/publish-api.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Publish API
2+
3+
on:
4+
push:
5+
tags:
6+
- "api-v*"
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
publish:
13+
name: Publish liquidjava-api to Maven Central
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
21+
22+
- name: Ensure tag is on main
23+
run: |
24+
git fetch origin main
25+
TAG_COMMIT="$(git rev-list -n 1 "$GITHUB_REF_NAME")"
26+
git merge-base --is-ancestor "$TAG_COMMIT" origin/main
27+
28+
- name: Set up JDK 20
29+
uses: actions/setup-java@v4
30+
with:
31+
distribution: temurin
32+
java-version: "20"
33+
cache: maven
34+
server-id: central
35+
server-username: CENTRAL_USERNAME
36+
server-password: CENTRAL_PASSWORD
37+
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
38+
gpg-passphrase: GPG_PASSPHRASE
39+
40+
- name: Publish API
41+
run: ./mvnw -f liquidjava-api/pom.xml -B --fail-fast -Dgpg.skip=false -Dmaven.deploy.skip=false clean deploy
42+
env:
43+
CENTRAL_USERNAME: ${{ secrets.CENTRAL_USERNAME }}
44+
CENTRAL_PASSWORD: ${{ secrets.CENTRAL_PASSWORD }}
45+
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Publish verifier
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
publish:
13+
name: Publish liquidjava-verifier to Maven Central
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
21+
22+
- name: Ensure tag is on main
23+
run: |
24+
git fetch origin main
25+
TAG_COMMIT="$(git rev-list -n 1 "$GITHUB_REF_NAME")"
26+
git merge-base --is-ancestor "$TAG_COMMIT" origin/main
27+
28+
- name: Set up JDK 20
29+
uses: actions/setup-java@v4
30+
with:
31+
distribution: temurin
32+
java-version: "20"
33+
cache: maven
34+
server-id: central
35+
server-username: CENTRAL_USERNAME
36+
server-password: CENTRAL_PASSWORD
37+
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
38+
gpg-passphrase: GPG_PASSPHRASE
39+
40+
- name: Publish verifier
41+
run: ./mvnw -f liquidjava-verifier/pom.xml -B --fail-fast -Dgpg.skip=false -Dmaven.deploy.skip=false clean deploy
42+
env:
43+
CENTRAL_USERNAME: ${{ secrets.CENTRAL_USERNAME }}
44+
CENTRAL_PASSWORD: ${{ secrets.CENTRAL_PASSWORD }}
45+
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}

liquidjava-api/pom.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@
142142
<configuration>
143143
<publishingServerId>central</publishingServerId>
144144
<skipPublishing>${maven.deploy.skip}</skipPublishing>
145-
<!-- <autoPublish>true</autoPublish> -->
145+
<autoPublish>true</autoPublish>
146+
<waitUntil>published</waitUntil>
146147
</configuration>
147148
</plugin>
148149
</plugins>
@@ -163,4 +164,4 @@
163164
<gpg.skip>true</gpg.skip>
164165
<maven.deploy.skip>true</maven.deploy.skip>
165166
</properties>
166-
</project>
167+
</project>

liquidjava-verifier/pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@
213213
<configuration>
214214
<publishingServerId>central</publishingServerId>
215215
<skipPublishing>${maven.deploy.skip}</skipPublishing>
216-
<!-- <autoPublish>true</autoPublish> -->
216+
<autoPublish>true</autoPublish>
217+
<waitUntil>published</waitUntil>
217218
</configuration>
218219
</plugin>
219220
</plugins>

release.sh

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,67 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

3-
if [ -z "$1" ]; then
4-
echo "Usage: $0 <api|verifier>"
3+
set -euo pipefail
4+
5+
if [ $# -ne 2 ]; then
6+
echo "Usage: $0 <api|verifier> <version>"
57
exit 1
68
fi
79

810
MODULE=$1
11+
VERSION=$2
912

1013
if [ "$MODULE" != "api" ] && [ "$MODULE" != "verifier" ]; then
1114
echo "Invalid module: $MODULE"
12-
echo "Usage: $0 <api|verifier>"
15+
echo "Usage: $0 <api|verifier> <version>"
16+
exit 1
17+
fi
18+
19+
if ! [[ "$VERSION" =~ ^[0-9]+(\.[0-9]+){1,2}(-[A-Za-z0-9.-]+)?$ ]]; then
20+
echo "Invalid version: $VERSION"
21+
echo "Expected format: 1.2.3"
1322
exit 1
1423
fi
1524

1625
MODULE_DIR="liquidjava-$MODULE"
26+
POM="$MODULE_DIR/pom.xml"
27+
28+
if [ "$MODULE" = "api" ]; then
29+
TAG="api-v$VERSION"
30+
else
31+
TAG="v$VERSION"
32+
fi
33+
34+
CURRENT_BRANCH=$(git branch --show-current)
35+
if [ "$CURRENT_BRANCH" != "main" ]; then
36+
echo "Release must be run from main. Current branch: $CURRENT_BRANCH"
37+
exit 1
38+
fi
39+
40+
if [ -n "$(git status --porcelain)" ]; then
41+
echo "Worktree must be clean before releasing."
42+
git status --short
43+
exit 1
44+
fi
45+
46+
if git rev-parse "$TAG" >/dev/null 2>&1; then
47+
echo "Tag already exists: $TAG"
48+
exit 1
49+
fi
50+
51+
perl -0pi -e "s#(<artifactId>$MODULE_DIR</artifactId>\\s*<version>)[^<]+(</version>)#\${1}$VERSION\${2}#" "$POM"
52+
53+
if git diff --quiet -- "$POM"; then
54+
echo "$POM is already at version $VERSION"
55+
exit 1
56+
fi
57+
58+
./mvnw -f "$POM" -B --fail-fast -Dgpg.skip=true -Dmaven.deploy.skip=true clean verify
59+
60+
git add "$POM"
61+
git commit -m "Release $MODULE_DIR $VERSION"
62+
git tag "$TAG"
63+
64+
git push origin main
65+
git push origin "$TAG"
1766

18-
cd "$MODULE_DIR"
19-
mvn -Dgpg.skip=false -Dmaven.deploy.skip=false clean deploy
20-
cd ..
67+
echo "Created and pushed $TAG. GitHub Actions will publish $MODULE_DIR to Maven Central."

0 commit comments

Comments
 (0)