From 68d949aa5b0974bd9d7c48f67f1c518e525b8c74 Mon Sep 17 00:00:00 2001 From: Simone Date: Sat, 2 May 2026 22:30:53 +0200 Subject: [PATCH] ci: fix sync-gitea-only job nesting and YAML structure --- .github/workflows/release.yml | 304 +++++++++++++++++----------------- 1 file changed, 152 insertions(+), 152 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ab38778..2f01526 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -177,15 +177,15 @@ jobs: base = "https://gitea.emulab.it/api/v1" repo = "Simone/nsis-plugin-ns7zip" - tag = os.environ.get("GITEA_TAG", "").strip() - if not tag or tag == "main": - tag = os.environ.get("INPUT_TAG", "").strip() - token = os.environ.get("GITEA_TOKEN", "").strip() + tag = os.environ.get("GITEA_TAG", "").strip() + if not tag or tag == "main": + tag = os.environ.get("INPUT_TAG", "").strip() + token = os.environ.get("GITEA_TOKEN", "").strip() - if not tag: - raise SystemExit("Tag non disponibile: imposta input 'tag' in workflow_dispatch") - if not token: - raise SystemExit("GITEA_TOKEN is missing or empty") + if not tag: + raise SystemExit("Tag non disponibile: imposta input 'tag' in workflow_dispatch") + if not token: + raise SystemExit("GITEA_TOKEN is missing or empty") with open("release_body.md", "r", encoding="utf-8") as f: body = f.read() @@ -197,7 +197,7 @@ jobs: data=data, method=method, headers={ - "Authorization": f"{auth_scheme} {token}", + "Authorization": f"{auth_scheme} {token}", "Content-Type": "application/json", "Accept": "application/json", }, @@ -208,164 +208,164 @@ jobs: 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', '')}") + break + except urllib.error.HTTPError as e: try: - user = request("GET", "/user", auth_scheme=scheme) - auth_scheme = scheme - print(f"Gitea auth OK via '{scheme}' as user: {user.get('login', '')}") - 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() + 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}" - ) + 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}" + ) try: - release = request("GET", f"/repos/{repo}/releases/tags/{tag}", auth_scheme=auth_scheme) - rid = release["id"] - request("PATCH", f"/repos/{repo}/releases/{rid}", {"body": body}, auth_scheme=auth_scheme) - print(f"Updated existing Gitea release id={rid} for tag {tag}") + release = request("GET", f"/repos/{repo}/releases/tags/{tag}", auth_scheme=auth_scheme) + rid = release["id"] + request("PATCH", f"/repos/{repo}/releases/{rid}", {"body": body}, auth_scheme=auth_scheme) + print(f"Updated existing Gitea release id={rid} for tag {tag}") 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()) + 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}") + 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 - sync-gitea-only: - if: ${{ github.event_name == 'workflow_dispatch' && inputs.gitea_only }} - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v6 + sync-gitea-only: + if: ${{ github.event_name == 'workflow_dispatch' && inputs.gitea_only }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 - - name: Extract changelog section - run: | - tag="${{ inputs.tag }}" - version="${tag#v}" - awk -v ver="[$version]" ' - /^## / && index($0, ver) { found=1; next } - found && /^## / { exit } - found { print } - ' CHANGELOG.md > release_body.md - if [ ! -s release_body.md ]; then - echo "Sezione CHANGELOG non trovata per $tag" - exit 1 - fi - echo "" >> release_body.md - echo "---" >> release_body.md - echo "_Repository primario: vedi link Gitea nel README. Il mirror GitHub è generato automaticamente._" >> release_body.md + - name: Extract changelog section + run: | + tag="${{ inputs.tag }}" + version="${tag#v}" + awk -v ver="[$version]" ' + /^## / && index($0, ver) { found=1; next } + found && /^## / { exit } + found { print } + ' CHANGELOG.md > release_body.md + if [ ! -s release_body.md ]; then + echo "Sezione CHANGELOG non trovata per $tag" + exit 1 + fi + echo "" >> release_body.md + echo "---" >> release_body.md + echo "_Repository primario: vedi link Gitea nel README. Il mirror GitHub è generato automaticamente._" >> release_body.md - - name: Update Gitea Release body - env: - GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} - INPUT_TAG: ${{ inputs.tag }} - GITEA_TAG: ${{ github.ref_name }} - run: | - python3 - <<'PY' - import json - import os - import urllib.error - import urllib.request + - name: Update Gitea Release body + env: + GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} + INPUT_TAG: ${{ inputs.tag }} + GITEA_TAG: ${{ github.ref_name }} + run: | + python3 - <<'PY' + import json + import os + import urllib.error + import urllib.request - base = "https://gitea.emulab.it/api/v1" - repo = "Simone/nsis-plugin-ns7zip" - tag = os.environ.get("GITEA_TAG", "").strip() - if not tag or tag == "main": - tag = os.environ.get("INPUT_TAG", "").strip() - token = os.environ.get("GITEA_TOKEN", "").strip() + base = "https://gitea.emulab.it/api/v1" + repo = "Simone/nsis-plugin-ns7zip" + tag = os.environ.get("GITEA_TAG", "").strip() + if not tag or tag == "main": + tag = os.environ.get("INPUT_TAG", "").strip() + token = os.environ.get("GITEA_TOKEN", "").strip() - if not tag: - raise SystemExit("Tag non disponibile: imposta input 'tag' in workflow_dispatch") - if not token: - raise SystemExit("GITEA_TOKEN is missing or empty") + if not tag: + raise SystemExit("Tag non disponibile: imposta input 'tag' in workflow_dispatch") + if not token: + raise SystemExit("GITEA_TOKEN is missing or empty") - with open("release_body.md", "r", encoding="utf-8") as f: - body = f.read() + with open("release_body.md", "r", encoding="utf-8") as f: + body = f.read() - def request(method, path, payload=None, auth_scheme="token"): - data = json.dumps(payload).encode("utf-8") if payload is not None else None - req = urllib.request.Request( - f"{base}{path}", - data=data, - method=method, - headers={ - "Authorization": f"{auth_scheme} {token}", - "Content-Type": "application/json", - "Accept": "application/json", - }, - ) - with urllib.request.urlopen(req) as resp: - 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', '')}") - 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}" - ) + def request(method, path, payload=None, auth_scheme="token"): + data = json.dumps(payload).encode("utf-8") if payload is not None else None + req = urllib.request.Request( + f"{base}{path}", + data=data, + method=method, + headers={ + "Authorization": f"{auth_scheme} {token}", + "Content-Type": "application/json", + "Accept": "application/json", + }, + ) + with urllib.request.urlopen(req) as resp: + 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', '')}") + break + except urllib.error.HTTPError as e: try: - release = request("GET", f"/repos/{repo}/releases/tags/{tag}", auth_scheme=auth_scheme) - rid = release["id"] - request("PATCH", f"/repos/{repo}/releases/{rid}", {"body": body}, auth_scheme=auth_scheme) - print(f"Updated existing Gitea release id={rid} for tag {tag}") - 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()) + details = e.read().decode("utf-8", errors="replace") + except Exception: + details = "" + last_error = f"HTTP {e.code} {e.reason} ({scheme}) {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 + 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}" + ) + + try: + release = request("GET", f"/repos/{repo}/releases/tags/{tag}", auth_scheme=auth_scheme) + rid = release["id"] + request("PATCH", f"/repos/{repo}/releases/{rid}", {"body": body}, auth_scheme=auth_scheme) + print(f"Updated existing Gitea release id={rid} for tag {tag}") + 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( + "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