ci: fix sync-gitea-only job nesting and YAML structure
This commit is contained in:
+152
-152
@@ -177,15 +177,15 @@ jobs:
|
|||||||
|
|
||||||
base = "https://gitea.emulab.it/api/v1"
|
base = "https://gitea.emulab.it/api/v1"
|
||||||
repo = "Simone/nsis-plugin-ns7zip"
|
repo = "Simone/nsis-plugin-ns7zip"
|
||||||
tag = os.environ.get("GITEA_TAG", "").strip()
|
tag = os.environ.get("GITEA_TAG", "").strip()
|
||||||
if not tag or tag == "main":
|
if not tag or tag == "main":
|
||||||
tag = os.environ.get("INPUT_TAG", "").strip()
|
tag = os.environ.get("INPUT_TAG", "").strip()
|
||||||
token = os.environ.get("GITEA_TOKEN", "").strip()
|
token = os.environ.get("GITEA_TOKEN", "").strip()
|
||||||
|
|
||||||
if not tag:
|
if not tag:
|
||||||
raise SystemExit("Tag non disponibile: imposta input 'tag' in workflow_dispatch")
|
raise SystemExit("Tag non disponibile: imposta input 'tag' in workflow_dispatch")
|
||||||
if not token:
|
if not token:
|
||||||
raise SystemExit("GITEA_TOKEN is missing or empty")
|
raise SystemExit("GITEA_TOKEN is missing or empty")
|
||||||
|
|
||||||
with open("release_body.md", "r", encoding="utf-8") as f:
|
with open("release_body.md", "r", encoding="utf-8") as f:
|
||||||
body = f.read()
|
body = f.read()
|
||||||
@@ -197,7 +197,7 @@ jobs:
|
|||||||
data=data,
|
data=data,
|
||||||
method=method,
|
method=method,
|
||||||
headers={
|
headers={
|
||||||
"Authorization": f"{auth_scheme} {token}",
|
"Authorization": f"{auth_scheme} {token}",
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"Accept": "application/json",
|
"Accept": "application/json",
|
||||||
},
|
},
|
||||||
@@ -208,164 +208,164 @@ jobs:
|
|||||||
auth_scheme = None
|
auth_scheme = None
|
||||||
last_error = None
|
last_error = None
|
||||||
for scheme in ("token", "Bearer"):
|
for scheme in ("token", "Bearer"):
|
||||||
|
try:
|
||||||
|
user = request("GET", "/user", auth_scheme=scheme)
|
||||||
|
auth_scheme = scheme
|
||||||
|
print(f"Gitea auth OK via '{scheme}' as user: {user.get('login', '<unknown>')}")
|
||||||
|
break
|
||||||
|
except urllib.error.HTTPError as e:
|
||||||
try:
|
try:
|
||||||
user = request("GET", "/user", auth_scheme=scheme)
|
details = e.read().decode("utf-8", errors="replace")
|
||||||
auth_scheme = scheme
|
except Exception:
|
||||||
print(f"Gitea auth OK via '{scheme}' as user: {user.get('login', '<unknown>')}")
|
details = ""
|
||||||
break
|
last_error = f"HTTP {e.code} {e.reason} ({scheme}) {details}".strip()
|
||||||
except urllib.error.HTTPError as e:
|
|
||||||
try:
|
|
||||||
details = e.read().decode("utf-8", errors="replace")
|
|
||||||
except Exception:
|
|
||||||
details = ""
|
|
||||||
last_error = f"HTTP {e.code} {e.reason} ({scheme}) {details}".strip()
|
|
||||||
|
|
||||||
if not auth_scheme:
|
if not auth_scheme:
|
||||||
raise SystemExit(
|
raise SystemExit(
|
||||||
"Gitea authentication failed for both 'token' and 'Bearer'. "
|
"Gitea authentication failed for both 'token' and 'Bearer'. "
|
||||||
"Check secret GITEA_TOKEN value and permissions (Repository Read+Write). "
|
"Check secret GITEA_TOKEN value and permissions (Repository Read+Write). "
|
||||||
f"Last error: {last_error}"
|
f"Last error: {last_error}"
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
release = request("GET", f"/repos/{repo}/releases/tags/{tag}", auth_scheme=auth_scheme)
|
release = request("GET", f"/repos/{repo}/releases/tags/{tag}", auth_scheme=auth_scheme)
|
||||||
rid = release["id"]
|
rid = release["id"]
|
||||||
request("PATCH", f"/repos/{repo}/releases/{rid}", {"body": body}, auth_scheme=auth_scheme)
|
request("PATCH", f"/repos/{repo}/releases/{rid}", {"body": body}, auth_scheme=auth_scheme)
|
||||||
print(f"Updated existing Gitea release id={rid} for tag {tag}")
|
print(f"Updated existing Gitea release id={rid} for tag {tag}")
|
||||||
except urllib.error.HTTPError as e:
|
except urllib.error.HTTPError as e:
|
||||||
if e.code != 404:
|
if e.code != 404:
|
||||||
try:
|
try:
|
||||||
details = e.read().decode("utf-8", errors="replace")
|
details = e.read().decode("utf-8", errors="replace")
|
||||||
except Exception:
|
except Exception:
|
||||||
details = ""
|
details = ""
|
||||||
raise SystemExit(f"Gitea release lookup/update failed: HTTP {e.code} {e.reason}. {details}".strip())
|
raise SystemExit(f"Gitea release lookup/update failed: HTTP {e.code} {e.reason}. {details}".strip())
|
||||||
|
|
||||||
created = request(
|
created = request(
|
||||||
"POST",
|
"POST",
|
||||||
f"/repos/{repo}/releases",
|
f"/repos/{repo}/releases",
|
||||||
{
|
{
|
||||||
"tag_name": tag,
|
"tag_name": tag,
|
||||||
"name": tag,
|
"name": tag,
|
||||||
"body": body,
|
"body": body,
|
||||||
"draft": False,
|
"draft": False,
|
||||||
"prerelease": False,
|
"prerelease": False,
|
||||||
},
|
},
|
||||||
auth_scheme=auth_scheme,
|
auth_scheme=auth_scheme,
|
||||||
)
|
)
|
||||||
print(f"Created Gitea release id={created['id']} for tag {tag}")
|
print(f"Created Gitea release id={created['id']} for tag {tag}")
|
||||||
PY
|
PY
|
||||||
|
|
||||||
sync-gitea-only:
|
sync-gitea-only:
|
||||||
if: ${{ github.event_name == 'workflow_dispatch' && inputs.gitea_only }}
|
if: ${{ github.event_name == 'workflow_dispatch' && inputs.gitea_only }}
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v6
|
- uses: actions/checkout@v6
|
||||||
|
|
||||||
- name: Extract changelog section
|
- name: Extract changelog section
|
||||||
run: |
|
run: |
|
||||||
tag="${{ inputs.tag }}"
|
tag="${{ inputs.tag }}"
|
||||||
version="${tag#v}"
|
version="${tag#v}"
|
||||||
awk -v ver="[$version]" '
|
awk -v ver="[$version]" '
|
||||||
/^## / && index($0, ver) { found=1; next }
|
/^## / && index($0, ver) { found=1; next }
|
||||||
found && /^## / { exit }
|
found && /^## / { exit }
|
||||||
found { print }
|
found { print }
|
||||||
' CHANGELOG.md > release_body.md
|
' CHANGELOG.md > release_body.md
|
||||||
if [ ! -s release_body.md ]; then
|
if [ ! -s release_body.md ]; then
|
||||||
echo "Sezione CHANGELOG non trovata per $tag"
|
echo "Sezione CHANGELOG non trovata per $tag"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo "" >> release_body.md
|
echo "" >> release_body.md
|
||||||
echo "---" >> release_body.md
|
echo "---" >> release_body.md
|
||||||
echo "_Repository primario: vedi link Gitea nel README. Il mirror GitHub è generato automaticamente._" >> release_body.md
|
echo "_Repository primario: vedi link Gitea nel README. Il mirror GitHub è generato automaticamente._" >> release_body.md
|
||||||
|
|
||||||
- name: Update Gitea Release body
|
- name: Update Gitea Release body
|
||||||
env:
|
env:
|
||||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||||
INPUT_TAG: ${{ inputs.tag }}
|
INPUT_TAG: ${{ inputs.tag }}
|
||||||
GITEA_TAG: ${{ github.ref_name }}
|
GITEA_TAG: ${{ github.ref_name }}
|
||||||
run: |
|
run: |
|
||||||
python3 - <<'PY'
|
python3 - <<'PY'
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import urllib.error
|
import urllib.error
|
||||||
import urllib.request
|
import urllib.request
|
||||||
|
|
||||||
base = "https://gitea.emulab.it/api/v1"
|
base = "https://gitea.emulab.it/api/v1"
|
||||||
repo = "Simone/nsis-plugin-ns7zip"
|
repo = "Simone/nsis-plugin-ns7zip"
|
||||||
tag = os.environ.get("GITEA_TAG", "").strip()
|
tag = os.environ.get("GITEA_TAG", "").strip()
|
||||||
if not tag or tag == "main":
|
if not tag or tag == "main":
|
||||||
tag = os.environ.get("INPUT_TAG", "").strip()
|
tag = os.environ.get("INPUT_TAG", "").strip()
|
||||||
token = os.environ.get("GITEA_TOKEN", "").strip()
|
token = os.environ.get("GITEA_TOKEN", "").strip()
|
||||||
|
|
||||||
if not tag:
|
if not tag:
|
||||||
raise SystemExit("Tag non disponibile: imposta input 'tag' in workflow_dispatch")
|
raise SystemExit("Tag non disponibile: imposta input 'tag' in workflow_dispatch")
|
||||||
if not token:
|
if not token:
|
||||||
raise SystemExit("GITEA_TOKEN is missing or empty")
|
raise SystemExit("GITEA_TOKEN is missing or empty")
|
||||||
|
|
||||||
with open("release_body.md", "r", encoding="utf-8") as f:
|
with open("release_body.md", "r", encoding="utf-8") as f:
|
||||||
body = f.read()
|
body = f.read()
|
||||||
|
|
||||||
def request(method, path, payload=None, auth_scheme="token"):
|
def request(method, path, payload=None, auth_scheme="token"):
|
||||||
data = json.dumps(payload).encode("utf-8") if payload is not None else None
|
data = json.dumps(payload).encode("utf-8") if payload is not None else None
|
||||||
req = urllib.request.Request(
|
req = urllib.request.Request(
|
||||||
f"{base}{path}",
|
f"{base}{path}",
|
||||||
data=data,
|
data=data,
|
||||||
method=method,
|
method=method,
|
||||||
headers={
|
headers={
|
||||||
"Authorization": f"{auth_scheme} {token}",
|
"Authorization": f"{auth_scheme} {token}",
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"Accept": "application/json",
|
"Accept": "application/json",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
with urllib.request.urlopen(req) as resp:
|
with urllib.request.urlopen(req) as resp:
|
||||||
return json.loads(resp.read().decode("utf-8"))
|
return json.loads(resp.read().decode("utf-8"))
|
||||||
|
|
||||||
auth_scheme = None
|
|
||||||
last_error = None
|
|
||||||
for scheme in ("token", "Bearer"):
|
|
||||||
try:
|
|
||||||
user = request("GET", "/user", auth_scheme=scheme)
|
|
||||||
auth_scheme = scheme
|
|
||||||
print(f"Gitea auth OK via '{scheme}' as user: {user.get('login', '<unknown>')}")
|
|
||||||
break
|
|
||||||
except urllib.error.HTTPError as e:
|
|
||||||
try:
|
|
||||||
details = e.read().decode("utf-8", errors="replace")
|
|
||||||
except Exception:
|
|
||||||
details = ""
|
|
||||||
last_error = f"HTTP {e.code} {e.reason} ({scheme}) {details}".strip()
|
|
||||||
|
|
||||||
if not auth_scheme:
|
|
||||||
raise SystemExit(
|
|
||||||
"Gitea authentication failed for both 'token' and 'Bearer'. "
|
|
||||||
"Check secret GITEA_TOKEN value and permissions (Repository Read+Write). "
|
|
||||||
f"Last error: {last_error}"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
auth_scheme = None
|
||||||
|
last_error = None
|
||||||
|
for scheme in ("token", "Bearer"):
|
||||||
|
try:
|
||||||
|
user = request("GET", "/user", auth_scheme=scheme)
|
||||||
|
auth_scheme = scheme
|
||||||
|
print(f"Gitea auth OK via '{scheme}' as user: {user.get('login', '<unknown>')}")
|
||||||
|
break
|
||||||
|
except urllib.error.HTTPError as e:
|
||||||
try:
|
try:
|
||||||
release = request("GET", f"/repos/{repo}/releases/tags/{tag}", auth_scheme=auth_scheme)
|
details = e.read().decode("utf-8", errors="replace")
|
||||||
rid = release["id"]
|
except Exception:
|
||||||
request("PATCH", f"/repos/{repo}/releases/{rid}", {"body": body}, auth_scheme=auth_scheme)
|
details = ""
|
||||||
print(f"Updated existing Gitea release id={rid} for tag {tag}")
|
last_error = f"HTTP {e.code} {e.reason} ({scheme}) {details}".strip()
|
||||||
except urllib.error.HTTPError as e:
|
|
||||||
if e.code != 404:
|
|
||||||
try:
|
|
||||||
details = e.read().decode("utf-8", errors="replace")
|
|
||||||
except Exception:
|
|
||||||
details = ""
|
|
||||||
raise SystemExit(f"Gitea release lookup/update failed: HTTP {e.code} {e.reason}. {details}".strip())
|
|
||||||
|
|
||||||
created = request(
|
if not auth_scheme:
|
||||||
"POST",
|
raise SystemExit(
|
||||||
f"/repos/{repo}/releases",
|
"Gitea authentication failed for both 'token' and 'Bearer'. "
|
||||||
{
|
"Check secret GITEA_TOKEN value and permissions (Repository Read+Write). "
|
||||||
"tag_name": tag,
|
f"Last error: {last_error}"
|
||||||
"name": tag,
|
)
|
||||||
"body": body,
|
|
||||||
"draft": False,
|
try:
|
||||||
"prerelease": False,
|
release = request("GET", f"/repos/{repo}/releases/tags/{tag}", auth_scheme=auth_scheme)
|
||||||
},
|
rid = release["id"]
|
||||||
auth_scheme=auth_scheme,
|
request("PATCH", f"/repos/{repo}/releases/{rid}", {"body": body}, auth_scheme=auth_scheme)
|
||||||
)
|
print(f"Updated existing Gitea release id={rid} for tag {tag}")
|
||||||
print(f"Created Gitea release id={created['id']} for tag {tag}")
|
except urllib.error.HTTPError as e:
|
||||||
PY
|
if e.code != 404:
|
||||||
|
try:
|
||||||
|
details = e.read().decode("utf-8", errors="replace")
|
||||||
|
except Exception:
|
||||||
|
details = ""
|
||||||
|
raise SystemExit(f"Gitea release lookup/update failed: HTTP {e.code} {e.reason}. {details}".strip())
|
||||||
|
|
||||||
|
created = request(
|
||||||
|
"POST",
|
||||||
|
f"/repos/{repo}/releases",
|
||||||
|
{
|
||||||
|
"tag_name": tag,
|
||||||
|
"name": tag,
|
||||||
|
"body": body,
|
||||||
|
"draft": False,
|
||||||
|
"prerelease": False,
|
||||||
|
},
|
||||||
|
auth_scheme=auth_scheme,
|
||||||
|
)
|
||||||
|
print(f"Created Gitea release id={created['id']} for tag {tag}")
|
||||||
|
PY
|
||||||
|
|||||||
Reference in New Issue
Block a user