name: ReleaseApp (auto from latest successful BuildApp) on: workflow_dispatch: {} # Manual trigger with ZERO inputs jobs: release: runs-on: ubuntu-latest env: # --- Adjust to your instance/repo if needed --- GITEA_BASE_URL: https://code.bim-it.pl OWNER: mz REPO: DiunaBI WORKFLOW_NAME: BuildApp steps: - name: Checkout (for tag context only) uses: https://github.com/actions/checkout@v4 - name: Install tools run: | sudo apt-get update sudo apt-get install -y jq zip # 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: | 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/tasks?limit=100")" # 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? // .workflow_name? // .display_title? // "") == $W ) ) ) | sort_by(.run_number // .id) | reverse | .[0] ' <<< "$RESP")" 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=$HEAD_SHA" >> "$GITHUB_OUTPUT" echo "Latest successful $WORKFLOW_NAME run: $RUN_ID ($HEAD_SHA)" # 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 # -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/$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 (GUI URL) shell: bash run: | set -euo pipefail mkdir -p artifacts/webapi curl -LfS --fail-with-body \ -H "Authorization: token ${{ secrets.GITEA_PAT }}" \ "$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 - name: Show artifact structure run: | echo "::group::frontend" ls -laR artifacts/frontend || true echo "::endgroup::" echo "::group::webapi" ls -laR artifacts/webapi || true echo "::endgroup::" # 3) Package artifacts as ZIPs for the release assets - name: Package artifacts as ZIPs run: | mkdir -p build (cd artifacts/frontend && zip -rq ../../build/frontend.zip .) (cd artifacts/webapi && zip -rq ../../build/webapi.zip .) ls -la build # 4) Auto-generate tag/title and create the release on Gitea - name: Generate tag and title id: meta run: | TAG="v$(date -u +%Y%m%d-%H%M)-run${{ steps.find_run.outputs.run_id }}" TITLE="Release ${TAG}" echo "tag=$TAG" >> "$GITHUB_OUTPUT" echo "title=$TITLE" >> "$GITHUB_OUTPUT" - name: Create Gitea release with assets uses: https://gitea.com/actions/release-action@main with: api_key: ${{ secrets.GITEA_PAT }} tag_name: ${{ steps.meta.outputs.tag }} name: ${{ steps.meta.outputs.title }} 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