From 73836dd9fc4330158e0dadd77211723ffe2445bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Zieli=C5=84ski?= Date: Sat, 13 Sep 2025 20:08:32 +0200 Subject: [PATCH] release --- .gitea/workflows/morskaRelease.yml | 90 ++++++++++++++++-------------- 1 file changed, 47 insertions(+), 43 deletions(-) diff --git a/.gitea/workflows/morskaRelease.yml b/.gitea/workflows/morskaRelease.yml index 179c3da..13d2afa 100644 --- a/.gitea/workflows/morskaRelease.yml +++ b/.gitea/workflows/morskaRelease.yml @@ -13,7 +13,7 @@ jobs: REPO: DiunaBI WORKFLOW_NAME: BuildApp steps: - - name: Checkout (for tagging context only) + - name: Checkout (for tag context only) uses: https://github.com/actions/checkout@v4 - name: Install tools @@ -21,68 +21,73 @@ jobs: sudo apt-get update sudo apt-get install -y jq zip - # 1) Find latest successful run of "BuildApp" + # 1) Find latest successful run of "BuildApp" via REST API (/api/v1 ... /actions/tasks) - name: Find latest successful BuildApp run id: find_run shell: bash run: | - # Fetch recent runs and filter client-side + set -euo pipefail + + # NOTE: /api/v1 is the correct REST base for Gitea. RESP="$(curl -fsSL \ -H "Authorization: token ${{ secrets.GITEA_PAT }}" \ - "$GITEA_BASE_URL/api/v1/repos/$OWNER/$REPO/actions/runs?limit=50")" + "$GITEA_BASE_URL/api/v1/repos/$OWNER/$REPO/actions/tasks?limit=100")" - echo "$RESP" | jq . >/dev/null || { echo "Invalid JSON from API"; exit 1; } - - RUN_JSON="$(echo "$RESP" | jq -r \ - --arg W "$WORKFLOW_NAME" ' + # Try to match by various fields (workflow.name in newer versions, fallbacks otherwise) + RUN_JSON="$(jq -r --arg W "$WORKFLOW_NAME" ' .workflow_runs - | map(select(.status=="completed" and .conclusion=="success" and .workflow.name==$W)) - | sort_by(.id) | reverse | .[0] - ')" + | map( + select( + (.status=="completed") and + (.conclusion=="success") and + ( + (.workflow.name? // .workflow_name? // .display_title? // "") == $W + ) + ) + ) + | sort_by(.run_number // .id) + | reverse + | .[0] + ' <<< "$RESP")" - RUN_ID="$(echo "$RUN_JSON" | jq -r '.id')" - RUN_HEAD_SHA="$(echo "$RUN_JSON" | jq -r '.head_sha')" - - if [[ -z "$RUN_ID" || "$RUN_ID" == "null" ]]; then - echo "No successful '$WORKFLOW_NAME' run found." >&2 + if [[ -z "$RUN_JSON" || "$RUN_JSON" == "null" ]]; then + echo "No successful run found for workflow name: $WORKFLOW_NAME" + echo "Available runs (debug):" + echo "$RESP" | jq -r '.workflow_runs[] | {id, status, conclusion, display_title, workflow_name: .workflow_name, wname: .workflow.name}' exit 1 fi + RUN_ID="$(jq -r '.id // .run_id' <<< "$RUN_JSON")" + HEAD_SHA="$(jq -r '.head_sha // .head_commit?.id // empty' <<< "$RUN_JSON")" + echo "run_id=$RUN_ID" >> "$GITHUB_OUTPUT" - echo "head_sha=$RUN_HEAD_SHA" >> "$GITHUB_OUTPUT" - echo "Latest successful $WORKFLOW_NAME run: $RUN_ID ($RUN_HEAD_SHA)" + echo "head_sha=$HEAD_SHA" >> "$GITHUB_OUTPUT" + echo "Latest successful $WORKFLOW_NAME run: $RUN_ID ($HEAD_SHA)" - # 2) List and download artifacts "frontend" and "webapi" via Gitea API - - name: List artifacts for that run - id: list_artifacts - run: | - curl -fsSL \ - -H "Authorization: token ${{ secrets.GITEA_PAT }}" \ - "$GITEA_BASE_URL/api/v1/repos/$OWNER/$REPO/actions/runs/${{ steps.find_run.outputs.run_id }}/artifacts" \ - | tee artifacts.json - - # Fail early if neither artifact is present - (jq -e '.artifacts[] | select(.name=="frontend")' artifacts.json >/dev/null) || { echo "Artifact 'frontend' not found"; exit 1; } - (jq -e '.artifacts[] | select(.name=="webapi")' artifacts.json >/dev/null) || { echo "Artifact 'webapi' not found"; exit 1; } - - - name: Download 'frontend' artifact (zip -> dir) + # 2) Download artifacts using GUI-style URLs + # These URLs serve ZIPs directly. Authorization via token MAY or MAY NOT work depending on instance config. + # If it fails with 302/403, consider using a community download action as a fallback. + - name: Download 'frontend' artifact (GUI URL) + shell: bash run: | + set -euo pipefail mkdir -p artifacts/frontend - ART_ID=$(jq -r '.artifacts[] | select(.name=="frontend") | .id' artifacts.json) - curl -fsSL \ + # -L to follow redirects; --fail-with-body to fail on non-2xx + curl -LfS --fail-with-body \ -H "Authorization: token ${{ secrets.GITEA_PAT }}" \ - "$GITEA_BASE_URL/api/v1/repos/$OWNER/$REPO/actions/artifacts/$ART_ID/zip" \ + "$GITEA_BASE_URL/$OWNER/$REPO/actions/runs/${{ steps.find_run.outputs.run_id }}/artifacts/frontend" \ -o frontend.zip unzip -q frontend.zip -d artifacts/frontend rm -f frontend.zip - - name: Download 'webapi' artifact (zip -> dir) + - name: Download 'webapi' artifact (GUI URL) + shell: bash run: | + set -euo pipefail mkdir -p artifacts/webapi - ART_ID=$(jq -r '.artifacts[] | select(.name=="webapi") | .id' artifacts.json) - curl -fsSL \ + curl -LfS --fail-with-body \ -H "Authorization: token ${{ secrets.GITEA_PAT }}" \ - "$GITEA_BASE_URL/api/v1/repos/$OWNER/$REPO/actions/artifacts/$ART_ID/zip" \ + "$GITEA_BASE_URL/$OWNER/$REPO/actions/runs/${{ steps.find_run.outputs.run_id }}/artifacts/webapi" \ -o webapi.zip unzip -q webapi.zip -d artifacts/webapi rm -f webapi.zip @@ -96,7 +101,7 @@ jobs: ls -laR artifacts/webapi || true echo "::endgroup::" - # 3) Package artifacts as ZIPs for release assets + # 3) Package artifacts as ZIPs for the release assets - name: Package artifacts as ZIPs run: | mkdir -p build @@ -104,11 +109,10 @@ jobs: (cd artifacts/webapi && zip -rq ../../build/webapi.zip .) ls -la build - # 4) Autogenerate tag and title, then create release + upload assets + # 4) Auto-generate tag/title and create the release on Gitea - name: Generate tag and title id: meta run: | - # Tag format: vYYYYMMDD-HHMM-run{RUN_ID} TAG="v$(date -u +%Y%m%d-%H%M)-run${{ steps.find_run.outputs.run_id }}" TITLE="Release ${TAG}" echo "tag=$TAG" >> "$GITHUB_OUTPUT" @@ -120,7 +124,7 @@ jobs: api_key: ${{ secrets.GITEA_PAT }} tag_name: ${{ steps.meta.outputs.tag }} name: ${{ steps.meta.outputs.title }} - body: "Automated release generated from latest successful **${{ env.WORKFLOW_NAME }}** run (`run_id=${{ steps.find_run.outputs.run_id }}`, `commit=${{ steps.find_run.outputs.head_sha }}`)." + body: "Automated release from latest successful **${{ env.WORKFLOW_NAME }}** run (`run_id=${{ steps.find_run.outputs.run_id }}`, `commit=${{ steps.find_run.outputs.head_sha }}`)." files: | build/frontend.zip build/webapi.zip \ No newline at end of file