Skip to content

Commit c6b6f7f

Browse files
committed
ci: log publish skip reason and keep workflow green
1 parent bb96e5f commit c6b6f7f

1 file changed

Lines changed: 34 additions & 1 deletion

File tree

‎.github/workflows/publish.yml‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ jobs:
1717
CENTRAL_TOKEN_USERNAME: ${{ secrets.CENTRAL_TOKEN_USERNAME }}
1818
CENTRAL_TOKEN_PASSWORD: ${{ secrets.CENTRAL_TOKEN_PASSWORD }}
1919
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
20+
CENTRAL_GROUP_ID: io.facturapi
21+
CENTRAL_ARTIFACT_ID: facturapi-java
2022
steps:
2123
- name: Checkout
2224
uses: actions/checkout@v4
@@ -40,8 +42,11 @@ jobs:
4042
set -euo pipefail
4143
4244
python3 <<'PY' >> "$GITHUB_OUTPUT"
45+
import base64
46+
import os
4347
import sys
4448
import urllib.request
49+
import urllib.error
4550
import xml.etree.ElementTree as ET
4651
4752
ns = {"m": "http://maven.apache.org/POM/4.0.0"}
@@ -89,10 +94,38 @@ jobs:
8994
return left_pre > right_pre
9095
9196
publish = is_greater(version, latest)
97+
reason = "current version is newer than published version"
98+
if publish:
99+
# If a deployment for this exact version is already staged/ongoing in the Portal,
100+
# skip a duplicate publish attempt and leave the workflow green.
101+
username = os.environ.get("CENTRAL_TOKEN_USERNAME", "")
102+
password = os.environ.get("CENTRAL_TOKEN_PASSWORD", "")
103+
group_id = os.environ.get("CENTRAL_GROUP_ID", "io.facturapi")
104+
artifact_id = os.environ.get("CENTRAL_ARTIFACT_ID", "facturapi-java")
105+
if username and password:
106+
token = base64.b64encode(f"{username}:{password}".encode("utf-8")).decode("utf-8")
107+
rel_path = f"{group_id.replace('.', '/')}/{artifact_id}/{version}/{artifact_id}-{version}.pom"
108+
url = f"https://central.sonatype.com/api/v1/publisher/deployments/download/{rel_path}"
109+
req = urllib.request.Request(url, headers={"Authorization": f"Bearer {token}"}, method="HEAD")
110+
try:
111+
with urllib.request.urlopen(req, timeout=20) as response:
112+
if response.status == 200:
113+
publish = False
114+
reason = "version already staged or publishing in Central Portal"
115+
except urllib.error.HTTPError as err:
116+
if err.code != 404:
117+
print(f"portal_stage_check_status={err.code}")
118+
except Exception:
119+
pass
120+
92121
print(f"current_version={version}")
93122
print(f"latest_version={latest}")
94123
print(f"publish={'true' if publish else 'false'}")
95-
print(f"reason={'current version is newer than published version' if publish else 'published version is current or newer'}")
124+
if publish:
125+
reason = "current version is newer than published version"
126+
elif reason == "current version is newer than published version":
127+
reason = "published version is current or newer"
128+
print(f"reason={reason}")
96129
PY
97130
98131
- name: Publish

0 commit comments

Comments
 (0)