Skip to content

Commit e303d4a

Browse files
authored
🚀 ci(publish): Attempting to fix NPM and Maven publishing issues (#306)
[[NT-3351](https://contentful.atlassian.net/browse/NT-3351)]
1 parent 0a99143 commit e303d4a

5 files changed

Lines changed: 58 additions & 9 deletions

File tree

.github/workflows/publish-android.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,41 @@ jobs:
5555

5656
- uses: android-actions/setup-android@40fd30fb8d7440372e1316f5d1809ec01dcd3699 # v4.0.1
5757

58+
- name: Verify Maven Central credentials
59+
if: github.event_name == 'release' || inputs.publish
60+
env:
61+
MAVEN_CENTRAL_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
62+
MAVEN_CENTRAL_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
63+
run: |
64+
set -euo pipefail
65+
66+
if [ -z "$MAVEN_CENTRAL_USERNAME" ] || [ -z "$MAVEN_CENTRAL_PASSWORD" ]; then
67+
echo "MAVEN_CENTRAL_USERNAME and MAVEN_CENTRAL_PASSWORD secrets must be set."
68+
exit 1
69+
fi
70+
71+
TOKEN="$(printf '%s:%s' "$MAVEN_CENTRAL_USERNAME" "$MAVEN_CENTRAL_PASSWORD" | base64 | tr -d '\n')"
72+
CODE="$(curl -sS -o /dev/null -w '%{http_code}' \
73+
-H "Authorization: Bearer $TOKEN" \
74+
"https://central.sonatype.com/api/v1/publisher/published?namespace=com.contentful.java&name=optimization-android&version=0.0.0-probe" || printf '000')"
75+
76+
case "$CODE" in
77+
2*|404)
78+
;;
79+
401|403)
80+
echo "Central Portal rejected the Maven Central token for namespace com.contentful.java (HTTP $CODE)."
81+
echo "Regenerate a Central Portal user token from an account with publisher access to com.contentful.java and update the GitHub Actions secrets."
82+
exit 1
83+
;;
84+
000)
85+
echo "Could not reach the Central Portal API."
86+
exit 1
87+
;;
88+
*)
89+
echo "Central Portal credential preflight returned HTTP $CODE; continuing because the token was not explicitly rejected."
90+
;;
91+
esac
92+
5893
- name: Verify Maven publishing assembles
5994
if: github.event_name == 'workflow_dispatch' && !inputs.publish
6095
working-directory: packages/android/ContentfulOptimization

.github/workflows/publish-npm.yaml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ jobs:
6060
6161
- name: Bump package.json versions
6262
run: |
63-
pnpm -r --filter "@contentful/optimization-*" exec \
63+
pnpm -r --filter "@contentful/optimization-*" \
64+
--filter "!@contentful/optimization-js-bridge" exec \
6465
npm --no-git-tag-version --force version "$RELEASE_VERSION"
6566
env:
6667
RELEASE_VERSION: ${{ env.RELEASE_VERSION }}
@@ -71,12 +72,16 @@ jobs:
7172
RELEASE_VERSION: ${{ env.RELEASE_VERSION }}
7273

7374
- name: Prepare package READMEs for publish
74-
run: pnpm -r --filter "@contentful/optimization-*" exec build-tools rewrite-readme prepare
75+
run: |
76+
pnpm -r --filter "@contentful/optimization-*" \
77+
--filter "!@contentful/optimization-js-bridge" exec build-tools rewrite-readme prepare
7578
env:
7679
RELEASE_TAG: ${{ env.RELEASE_TAG }}
7780

7881
- name: Create packages for troubleshooting
79-
run: pnpm pack --filter "@contentful/optimization-*" --pack-destination pkgs
82+
run: |
83+
pnpm pack --filter "@contentful/optimization-*" \
84+
--filter "!@contentful/optimization-js-bridge" --pack-destination pkgs
8085
8186
- name: Upload packages for troubleshooting
8287
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
@@ -96,10 +101,14 @@ jobs:
96101

97102
- name: Publish
98103
if: github.event_name == 'release' || inputs.publish
99-
run: pnpm -r --filter "@contentful/optimization-*" publish --access public --no-git-checks
104+
run: |
105+
pnpm -r --filter "@contentful/optimization-*" \
106+
--filter "!@contentful/optimization-js-bridge" publish --access public --no-git-checks
100107
env:
101108
NODE_AUTH_TOKEN: ${{ steps.vault.outputs.GITHUB_PACKAGES_WRITE_TOKEN }}
102109

103110
- name: Restore package READMEs after publish
104111
if: always()
105-
run: pnpm -r --filter "@contentful/optimization-*" exec build-tools rewrite-readme restore
112+
run: |
113+
pnpm -r --filter "@contentful/optimization-*" \
114+
--filter "!@contentful/optimization-js-bridge" exec build-tools rewrite-readme restore

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"lint": "eslint lib packages",
3434
"lint:fix": "eslint lib packages --fix",
3535
"notices:generate": "pnpm --filter \"@contentful/*\" licenses list --prod --json | pnpm dlx @quantco/pnpm-licenses generate-disclaimer --json-input --output-file THIRD_PARTY_NOTICES.txt",
36-
"pack:pkgs": "pnpm pack --filter @contentful/* --pack-destination pkgs",
36+
"pack:pkgs": "pnpm pack --filter @contentful/* --filter '!@contentful/optimization-js-bridge' --pack-destination pkgs",
3737
"playwright:install": "pnpm run implementation:run -- --all -- implementation:playwright:install",
3838
"playwright:install-deps": "pnpm run implementation:run -- --all -- implementation:playwright:install-deps",
3939
"pm2:delete:all": "pm2 delete all",

packages/android/ContentfulOptimization/build.gradle.kts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import com.vanniktech.maven.publish.AndroidSingleVariantLibrary
2-
import com.vanniktech.maven.publish.SonatypeHost
32

43
plugins {
54
id("com.android.library")
65
id("org.jetbrains.kotlin.android")
76
id("org.jetbrains.kotlin.plugin.compose")
87
// Version inline so the module builds when included as a subproject (parent builds don't pin it).
9-
id("com.vanniktech.maven.publish") version "0.30.0"
8+
id("com.vanniktech.maven.publish") version "0.34.0"
109
}
1110

1211
// Published coordinate: com.contentful.java:optimization-android. We reuse Contentful's existing,
@@ -97,7 +96,7 @@ mavenPublishing {
9796
)
9897
)
9998

100-
publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL, automaticRelease = true)
99+
publishToMavenCentral(automaticRelease = true)
101100

102101
// Sign with the in-memory GPG key supplied by CI (ORG_GRADLE_PROJECT_signingInMemoryKey*).
103102
// Skipped automatically when no key is configured (e.g. local publishToMavenLocal smoke tests),

packages/universal/optimization-js-bridge/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
{
2+
"private": true,
23
"name": "@contentful/optimization-js-bridge",
34
"version": "0.0.0",
45
"license": "MIT",
6+
"repository": {
7+
"type": "git",
8+
"url": "git+https://github.com/contentful/optimization.git",
9+
"directory": "packages/universal/optimization-js-bridge"
10+
},
511
"type": "module",
612
"main": "./dist/optimization-ios-bridge.umd.js",
713
"files": [

0 commit comments

Comments
 (0)