Repository navigation
122 lines (109 loc) · 4.37 KB
/
Copy pathjava-publish.yml
File metadata and controls
122 lines (109 loc) · 4.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
name: Maven Central Publish
on:
release:
types: [published]
workflow_dispatch:
inputs:
version:
description: Maven package version to publish (for example, 0.2.0)
required: true
type: string
permissions:
contents: read
concurrency:
group: maven-central-publish
cancel-in-progress: false
jobs:
publish:
if: github.event_name == 'workflow_dispatch' || startsWith(github.ref_name, 'java-v')
runs-on: ubuntu-latest
environment:
name: maven-central
url: https://central.sonatype.com/artifact/io.github.mini-software/minipdf
defaults:
run:
working-directory: minipdf-java
env:
MAVEN_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.MAVEN_CENTRAL_TOKEN }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
RELEASE_VERSION: ${{ github.event_name == 'workflow_dispatch' && inputs.version || github.ref_name }}
steps:
- name: Checkout
uses: actions/checkout@v6
with:
persist-credentials: false
- name: Validate release credentials
shell: bash
run: |
missing=0
for name in MAVEN_USERNAME MAVEN_PASSWORD MAVEN_GPG_PASSPHRASE GPG_PRIVATE_KEY; do
if [ -z "${!name:-}" ]; then
echo "::error::$name is not configured."
missing=1
fi
done
exit "$missing"
- name: Setup Java
uses: actions/setup-java@v6
with:
distribution: temurin
java-version: '17'
cache: maven
cache-dependency-path: minipdf-java/**/pom.xml
server-id: central
server-username-env-var: MAVEN_USERNAME
server-password-env-var: MAVEN_PASSWORD
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
gpg-passphrase-env-var: MAVEN_GPG_PASSPHRASE
- name: Validate release version
id: version
shell: bash
run: |
VERSION="${RELEASE_VERSION#java-v}"
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "::error::Version '$VERSION' must use stable semantic version format."
exit 1
fi
POM_VERSION="$(./mvnw -q -DforceStdout help:evaluate -Dexpression=project.version)"
if [ "$VERSION" != "$POM_VERSION" ]; then
echo "::error::Release version '$VERSION' does not match POM version '$POM_VERSION'."
exit 1
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Install CJK fonts
run: sudo apt-get update && sudo apt-get install --yes fonts-noto-cjk fonts-wqy-microhei
- name: Test release candidate
run: ./mvnw -B -ntp clean verify
- name: Verify Maven Central artifacts
shell: bash
run: |
./mvnw -B -ntp -P release -DskipTests -Dgpg.skip=true -pl minipdf,minipdf-cli -am package
VERSION="${{ steps.version.outputs.version }}"
for artifact in \
"minipdf/target/minipdf-$VERSION.jar" \
"minipdf/target/minipdf-$VERSION-sources.jar" \
"minipdf/target/minipdf-$VERSION-javadoc.jar" \
"minipdf-cli/target/minipdf-cli-$VERSION.jar" \
"minipdf-cli/target/minipdf-cli-$VERSION-sources.jar" \
"minipdf-cli/target/minipdf-cli-$VERSION-javadoc.jar"; do
if [ ! -s "$artifact" ]; then
echo "::error::Missing release artifact: $artifact"
exit 1
fi
done
CLI_VERSION="$(java -jar "minipdf-cli/target/minipdf-cli-$VERSION.jar" --version)"
if [ "$CLI_VERSION" != "minipdf-java $VERSION" ]; then
echo "::error::CLI reported '$CLI_VERSION'."
exit 1
fi
- name: Publish to Maven Central
run: ./mvnw -B -ntp -P release -DskipTests -pl minipdf,minipdf-cli -am deploy
- name: Summarize publication
shell: bash
run: |
echo "### MiniPdf Java ${{ steps.version.outputs.version }} published" >> "$GITHUB_STEP_SUMMARY"
echo "Maven Central coordinates:" >> "$GITHUB_STEP_SUMMARY"
echo '- `io.github.mini-software:minipdf:${{ steps.version.outputs.version }}`' >> "$GITHUB_STEP_SUMMARY"
echo '- `io.github.mini-software:minipdf-cli:${{ steps.version.outputs.version }}`' >> "$GITHUB_STEP_SUMMARY"