|
17 | 17 | CENTRAL_TOKEN_USERNAME: ${{ secrets.CENTRAL_TOKEN_USERNAME }} |
18 | 18 | CENTRAL_TOKEN_PASSWORD: ${{ secrets.CENTRAL_TOKEN_PASSWORD }} |
19 | 19 | GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} |
| 20 | + CENTRAL_GROUP_ID: io.facturapi |
| 21 | + CENTRAL_ARTIFACT_ID: facturapi-java |
20 | 22 | steps: |
21 | 23 | - name: Checkout |
22 | 24 | uses: actions/checkout@v4 |
|
40 | 42 | set -euo pipefail |
41 | 43 |
|
42 | 44 | python3 <<'PY' >> "$GITHUB_OUTPUT" |
| 45 | + import base64 |
| 46 | + import os |
43 | 47 | import sys |
44 | 48 | import urllib.request |
| 49 | + import urllib.error |
45 | 50 | import xml.etree.ElementTree as ET |
46 | 51 |
|
47 | 52 | ns = {"m": "http://maven.apache.org/POM/4.0.0"} |
@@ -89,10 +94,38 @@ jobs: |
89 | 94 | return left_pre > right_pre |
90 | 95 |
|
91 | 96 | 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 | +
|
92 | 121 | print(f"current_version={version}") |
93 | 122 | print(f"latest_version={latest}") |
94 | 123 | 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}") |
96 | 129 | PY |
97 | 130 |
|
98 | 131 | - name: Publish |
|
0 commit comments