Skip to content

Commit 540a96f

Browse files
authored
Merge pull request #3 from embedpdf/automation/cloudpdf-sdk-v3.0.0-next.1
chore: generate CloudPDF Java SDK 3.0.0-alpha.1
2 parents 776cb7a + d979d09 commit 540a96f

5 files changed

Lines changed: 268 additions & 12 deletions

File tree

‎.fern/metadata.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"base-exception-class-name": "CloudPDFException",
1111
"base-api-exception-class-name": "CloudPDFApiException"
1212
},
13-
"originGitCommit": "a0adb9e77ef16feaef2358d71b247b4f5a98fd23",
13+
"originGitCommit": "cfc415f2b7501e153280b32bcd6aa4af1353e860",
1414
"originGitCommitIsDirty": false,
1515
"invokedBy": "ci",
1616
"requestedVersion": "3.0.0-alpha.1",

‎.github/workflows/sdk-ci.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ jobs:
1919
distribution: temurin
2020
java-version: '17'
2121
cache: gradle
22-
- run: ./gradlew test --no-daemon
22+
- run: ./gradlew test generatePomFileForMavenPublication jar sourcesJar javadocJar --no-daemon

‎.github/workflows/sdk-release.yml‎

Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
name: SDK Release
2+
3+
on:
4+
push:
5+
branches: [main]
6+
paths-ignore:
7+
- '.github/**'
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: read
12+
13+
concurrency:
14+
group: sdk-release
15+
cancel-in-progress: false
16+
17+
jobs:
18+
release:
19+
name: Publish com.cloudpdf:sdk
20+
if: github.event_name == 'workflow_dispatch' || vars.SDK_AUTO_PUBLISH_ENABLED == 'true'
21+
runs-on: ubuntu-latest
22+
environment: release
23+
permissions:
24+
contents: write
25+
steps:
26+
- uses: actions/checkout@v4
27+
with:
28+
fetch-depth: 0
29+
30+
- uses: actions/setup-java@v4
31+
with:
32+
distribution: temurin
33+
java-version: '17'
34+
cache: gradle
35+
36+
- name: Verify generated release version
37+
id: version
38+
run: |
39+
node <<'NODE'
40+
const fs = require('node:fs');
41+
const generation = JSON.parse(fs.readFileSync('cloudpdf-generation.json', 'utf8'));
42+
const build = fs.readFileSync('build.gradle', 'utf8');
43+
if (generation.language !== 'java') throw new Error('generation language is not java');
44+
const group = build.match(/^group = '([^']+)'$/m)?.[1];
45+
const projectVersion = build.match(/^version = '([^']+)'$/m)?.[1];
46+
const artifact = build.match(/^\s*artifactId = '([^']+)'$/m)?.[1];
47+
if (group !== 'com.cloudpdf' || artifact !== 'sdk') {
48+
throw new Error(`unexpected Maven coordinates ${group}:${artifact}`);
49+
}
50+
if (projectVersion !== generation.sdkVersion) {
51+
throw new Error(`project version ${projectVersion} does not match generated version ${generation.sdkVersion}`);
52+
}
53+
const prerelease = generation.canonicalVersion.includes('-');
54+
fs.appendFileSync(process.env.GITHUB_OUTPUT, `version=${projectVersion}\n`);
55+
fs.appendFileSync(process.env.GITHUB_OUTPUT, `tag=v${projectVersion}\n`);
56+
fs.appendFileSync(process.env.GITHUB_OUTPUT, `prerelease=${prerelease}\n`);
57+
NODE
58+
59+
- name: Build signed Maven Central bundle
60+
env:
61+
MAVEN_GPG_PRIVATE_KEY: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
62+
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
63+
VERSION: ${{ steps.version.outputs.version }}
64+
CENTRAL_BUNDLE: ${{ runner.temp }}/cloudpdf-central-bundle.zip
65+
run: |
66+
./gradlew clean test publishMavenPublicationToCentralStagingRepository --no-daemon
67+
release_directory="build/central-staging/com/cloudpdf/sdk/$VERSION"
68+
required_artifacts=(
69+
"sdk-$VERSION.pom"
70+
"sdk-$VERSION.jar"
71+
"sdk-$VERSION-sources.jar"
72+
"sdk-$VERSION-javadoc.jar"
73+
)
74+
for artifact in "${required_artifacts[@]}"; do
75+
if [ ! -f "$release_directory/$artifact" ]; then
76+
echo "::error::Maven Central bundle is missing $artifact."
77+
exit 1
78+
fi
79+
if [ ! -f "$release_directory/$artifact.asc" ]; then
80+
echo "::error::Maven artifact $artifact is not signed."
81+
exit 1
82+
fi
83+
done
84+
85+
python3 <<'PY'
86+
import os
87+
import xml.etree.ElementTree as ET
88+
89+
version = os.environ['VERSION']
90+
pom = ET.parse(f'build/central-staging/com/cloudpdf/sdk/{version}/sdk-{version}.pom').getroot()
91+
namespace = {'m': 'http://maven.apache.org/POM/4.0.0'}
92+
expected = {
93+
'm:groupId': 'com.cloudpdf',
94+
'm:artifactId': 'sdk',
95+
'm:version': version,
96+
'm:name': 'CloudPDF',
97+
'm:url': 'https://www.cloudpdf.com',
98+
'm:scm/m:url': 'https://github.com/embedpdf/cloudpdf-sdk-java',
99+
}
100+
for path, value in expected.items():
101+
actual = pom.findtext(path, namespaces=namespace)
102+
if actual != value:
103+
raise RuntimeError(f'POM {path} is {actual!r}, expected {value!r}')
104+
PY
105+
106+
bundle_root="$RUNNER_TEMP/cloudpdf-central-bundle"
107+
bundle_release="$bundle_root/com/cloudpdf/sdk/$VERSION"
108+
mkdir -p "$bundle_release"
109+
for artifact in "${required_artifacts[@]}"; do
110+
cp "$release_directory/$artifact" "$bundle_release/$artifact"
111+
cp "$release_directory/$artifact.asc" "$bundle_release/$artifact.asc"
112+
md5sum "$release_directory/$artifact" | awk '{ print $1 }' > "$bundle_release/$artifact.md5"
113+
sha1sum "$release_directory/$artifact" | awk '{ print $1 }' > "$bundle_release/$artifact.sha1"
114+
done
115+
116+
cd "$bundle_root"
117+
zip -q -r "$CENTRAL_BUNDLE" com
118+
119+
- name: Protect immutable release tag
120+
id: release-tag
121+
env:
122+
RELEASE_TAG: ${{ steps.version.outputs.tag }}
123+
run: |
124+
git fetch --force --tags origin
125+
if git rev-parse --quiet --verify "refs/tags/$RELEASE_TAG" >/dev/null; then
126+
tagged_commit="$(git rev-list -n 1 "$RELEASE_TAG")"
127+
if [ "$tagged_commit" != "$GITHUB_SHA" ]; then
128+
if git diff --quiet "$RELEASE_TAG" "$GITHUB_SHA" -- . ':(exclude).github/**'; then
129+
echo "::notice::Reusing $RELEASE_TAG after a workflow-only change."
130+
else
131+
echo "::error::Release tag $RELEASE_TAG already points to different package source at $tagged_commit; bump the SDK version."
132+
exit 1
133+
fi
134+
fi
135+
echo "existed=true" >> "$GITHUB_OUTPUT"
136+
else
137+
git config user.name cloudpdf-sdk-bot
138+
git config user.email hello@cloudpdf.com
139+
git tag -a "$RELEASE_TAG" -m "CloudPDF Java SDK $RELEASE_TAG"
140+
git push origin "refs/tags/$RELEASE_TAG"
141+
echo "existed=false" >> "$GITHUB_OUTPUT"
142+
fi
143+
144+
- name: Check Maven Central publication state
145+
id: registry
146+
env:
147+
VERSION: ${{ steps.version.outputs.version }}
148+
TAG_EXISTED: ${{ steps.release-tag.outputs.existed }}
149+
run: |
150+
package_url="https://repo1.maven.org/maven2/com/cloudpdf/sdk/$VERSION/sdk-$VERSION.pom"
151+
http_status="$(curl --silent --show-error --output /dev/null --write-out '%{http_code}' "$package_url")"
152+
case "$http_status" in
153+
200)
154+
if [ "$TAG_EXISTED" != 'true' ]; then
155+
echo "::error::com.cloudpdf:sdk:$VERSION exists on Maven Central but its release tag did not exist."
156+
exit 1
157+
fi
158+
echo "publish=false" >> "$GITHUB_OUTPUT"
159+
;;
160+
404)
161+
echo "publish=true" >> "$GITHUB_OUTPUT"
162+
;;
163+
*)
164+
echo "::error::Maven Central returned HTTP $http_status while checking com.cloudpdf:sdk:$VERSION."
165+
exit 1
166+
;;
167+
esac
168+
169+
- name: Upload to Maven Central
170+
if: steps.registry.outputs.publish == 'true'
171+
id: central
172+
env:
173+
MAVEN_CENTRAL_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
174+
MAVEN_CENTRAL_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
175+
CENTRAL_BUNDLE: ${{ runner.temp }}/cloudpdf-central-bundle.zip
176+
run: |
177+
central_auth="$(printf '%s:%s' "$MAVEN_CENTRAL_USERNAME" "$MAVEN_CENTRAL_PASSWORD" | base64 --wrap=0)"
178+
echo "::add-mask::$central_auth"
179+
deployment_id="$(curl --fail-with-body --silent --show-error \
180+
--request POST \
181+
--header "Authorization: Bearer $central_auth" \
182+
--form "bundle=@$CENTRAL_BUNDLE;type=application/octet-stream" \
183+
'https://central.sonatype.com/api/v1/publisher/upload?publishingType=AUTOMATIC')"
184+
if ! printf '%s' "$deployment_id" | grep -Eq '^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$'; then
185+
echo "::error::Maven Central returned an invalid deployment ID."
186+
exit 1
187+
fi
188+
echo "deployment_id=$deployment_id" >> "$GITHUB_OUTPUT"
189+
190+
- name: Wait for Maven Central publication
191+
if: steps.registry.outputs.publish == 'true'
192+
env:
193+
MAVEN_CENTRAL_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
194+
MAVEN_CENTRAL_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
195+
DEPLOYMENT_ID: ${{ steps.central.outputs.deployment_id }}
196+
run: |
197+
central_auth="$(printf '%s:%s' "$MAVEN_CENTRAL_USERNAME" "$MAVEN_CENTRAL_PASSWORD" | base64 --wrap=0)"
198+
echo "::add-mask::$central_auth"
199+
status_file="$(mktemp)"
200+
for attempt in $(seq 1 120); do
201+
curl --fail-with-body --silent --show-error \
202+
--request POST \
203+
--header "Authorization: Bearer $central_auth" \
204+
--output "$status_file" \
205+
"https://central.sonatype.com/api/v1/publisher/status?id=$DEPLOYMENT_ID"
206+
deployment_state="$(jq --raw-output '.deploymentState' "$status_file")"
207+
case "$deployment_state" in
208+
PUBLISHED)
209+
exit 0
210+
;;
211+
FAILED)
212+
cat "$status_file"
213+
echo "::error::Maven Central rejected deployment $DEPLOYMENT_ID."
214+
exit 1
215+
;;
216+
PENDING|VALIDATING|VALIDATED|PUBLISHING)
217+
echo "Maven Central deployment is $deployment_state (attempt $attempt/120)."
218+
;;
219+
*)
220+
cat "$status_file"
221+
echo "::error::Maven Central returned unexpected deployment state $deployment_state."
222+
exit 1
223+
;;
224+
esac
225+
sleep 10
226+
done
227+
echo "::error::Maven Central deployment $DEPLOYMENT_ID did not finish within 20 minutes."
228+
exit 1
229+
230+
- name: Create GitHub release
231+
env:
232+
GH_TOKEN: ${{ github.token }}
233+
RELEASE_TAG: ${{ steps.version.outputs.tag }}
234+
PRERELEASE: ${{ steps.version.outputs.prerelease }}
235+
run: |
236+
if gh release view "$RELEASE_TAG" >/dev/null 2>&1; then
237+
exit 0
238+
fi
239+
args=(--verify-tag --generate-notes --title "CloudPDF Java SDK $RELEASE_TAG")
240+
if [ "$PRERELEASE" = 'true' ]; then args+=(--prerelease); fi
241+
gh release create "$RELEASE_TAG" "${args[@]}"

‎build.gradle‎

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
plugins {
22
id 'java-library'
33
id 'maven-publish'
4+
id 'signing'
45
id 'com.diffplug.spotless' version '6.11.0'
56
}
67

@@ -80,31 +81,45 @@ publishing {
8081
url = 'https://www.cloudpdf.com'
8182
licenses {
8283
license {
83-
name = 'APACHE-2.0'
84+
name = 'Apache License, Version 2.0'
85+
url = 'https://www.apache.org/licenses/LICENSE-2.0.txt'
86+
distribution = 'repo'
8487
}
8588
}
8689
developers {
8790
developer {
91+
id = 'cloudpdf'
8892
name = 'CloudPDF'
8993
email = 'hello@cloudpdf.com'
94+
organization = 'CloudPDF'
95+
organizationUrl = 'https://www.cloudpdf.com'
9096
}
9197
}
9298
scm {
93-
connection = 'scm:git:git://github.com/YOUR-ORG/YOUR-REPO.git'
94-
developerConnection = 'scm:git:git://github.com/YOUR-ORG/YOUR-REPO.git'
95-
url = 'https://github.com/YOUR-ORG/YOUR-REPO'
99+
connection = 'scm:git:https://github.com/embedpdf/cloudpdf-sdk-java.git'
100+
developerConnection = 'scm:git:ssh://git@github.com/embedpdf/cloudpdf-sdk-java.git'
101+
url = 'https://github.com/embedpdf/cloudpdf-sdk-java'
96102
}
97103
}
98104
}
99105
}
100106
repositories {
101107
maven {
102-
url "$System.env.MAVEN_PUBLISH_REGISTRY_URL"
103-
credentials {
104-
username "$System.env.MAVEN_USERNAME"
105-
password "$System.env.MAVEN_PASSWORD"
106-
}
108+
name = 'centralStaging'
109+
url = layout.buildDirectory.dir('central-staging')
107110
}
108111
}
109112
}
110113

114+
115+
tasks.withType(GenerateModuleMetadata) {
116+
enabled = false
117+
}
118+
119+
signing {
120+
useInMemoryPgpKeys(
121+
System.getenv('MAVEN_GPG_PRIVATE_KEY'),
122+
System.getenv('MAVEN_GPG_PASSPHRASE')
123+
)
124+
sign publishing.publications.maven
125+
}

‎cloudpdf-generation.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"repository": "embedpdf/embed-pdf-viewer",
77
"openapi": "cloudpdf/contract/openapi.json",
88
"openapiSha256": "6858ce7912e9063d8fb171ade95fc473db01c5971a3af241a612dda79cc05100",
9-
"gitCommit": "a0adb9e77ef16feaef2358d71b247b4f5a98fd23",
9+
"gitCommit": "cfc415f2b7501e153280b32bcd6aa4af1353e860",
1010
"gitCommitIsDirty": false
1111
},
1212
"fern": {

0 commit comments

Comments
 (0)