From 2942ab87405f87525e0aebd5eeb3cce21af468fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Zieli=C5=84ski?= Date: Sat, 13 Sep 2025 15:20:45 +0200 Subject: [PATCH] wip --- .gitea/workflows/morskaRelease.yml | 99 +++++------------------------- 1 file changed, 16 insertions(+), 83 deletions(-) diff --git a/.gitea/workflows/morskaRelease.yml b/.gitea/workflows/morskaRelease.yml index 91636e6..55c6a01 100644 --- a/.gitea/workflows/morskaRelease.yml +++ b/.gitea/workflows/morskaRelease.yml @@ -1,4 +1,4 @@ -name: Release Morska (latest successful build) +name: Release Morska (from latest build cache) on: workflow_dispatch: {} @@ -8,8 +8,6 @@ env: DEPLOY_USER: "mz" DEPLOY_PATH: "./deployment/" SSH_KEYFILE: "/ci-keys/morska" - BUILD_WORKFLOW_PATH: ".gitea/workflows/build.yml" - API_BASE: "https://code.bim-it.pl/api/v1" jobs: release: @@ -18,95 +16,30 @@ jobs: - name: Checkout (for completeness) uses: https://github.com/actions/checkout@v4 - - name: Install tools + - name: Tools run: | set -euo pipefail apt-get update -y - apt-get install -y jq unzip zip openssh-client + apt-get install -y zip openssh-client - - name: Resolve repo/env - id: repo + - name: Verify runner cache env: - GITHUB_REPOSITORY: ${{ github.repository }} # owner/repo - API_BASE: ${{ env.API_BASE }} + SRC: /runner-cache/builds/latest run: | set -euo pipefail - OWNER="${GITHUB_REPOSITORY%%/*}" - REPO="${GITHUB_REPOSITORY##*/}" - echo "owner=$OWNER" >> $GITHUB_OUTPUT - echo "repo=$REPO" >> $GITHUB_OUTPUT - echo "api=$API_BASE" >> $GITHUB_OUTPUT + echo "Expecting artifacts in: $SRC" + test -d "$SRC/frontend" || { echo "Missing $SRC/frontend"; exit 1; } + test -d "$SRC/webapi" || { echo "Missing $SRC/webapi"; exit 1; } + ls -la "$SRC" - - name: Probe API & auth + - name: Create archives env: - API: ${{ steps.repo.outputs.api }} - OWNER: ${{ steps.repo.outputs.owner }} - REPO: ${{ steps.repo.outputs.repo }} - TOKEN: ${{ secrets.GITEATOKEN }} - run: | - set -euo pipefail - echo "Probing: $API/repos/$OWNER/$REPO" - curl -sfSL -H "Authorization: token $TOKEN" "$API/repos/$OWNER/$REPO" >/dev/null - echo "OK" - - - name: Pick latest successful build (main) - id: pick - env: - API: ${{ steps.repo.outputs.api }} - OWNER: ${{ steps.repo.outputs.owner }} - REPO: ${{ steps.repo.outputs.repo }} - TOKEN: ${{ secrets.GITEATOKEN }} - BUILD_PATH: ${{ env.BUILD_WORKFLOW_PATH }} - run: | - set -euo pipefail - URL="$API/repos/$OWNER/$REPO/actions/runs?status=success&branch=main&per_page=20" - echo "GET $URL" - RESP="$(curl -sfSL -H "Authorization: token $TOKEN" "$URL")" - echo "$RESP" | jq -e '.workflow_runs' >/dev/null - RUN_ID="$(echo "$RESP" | jq -r --arg p "$BUILD_PATH" ' - .workflow_runs - | map(select( - (.head_branch=="main") - and (.status=="completed") - and (.conclusion=="success") - and ( - (.path? // .workflow_path? // .workflow?.path? // "") - | test($p + "$") - ) - )) - | sort_by(.run_number) | reverse | .[0].id // empty - ')" - test -n "$RUN_ID" && echo "run_id=$RUN_ID" >> $GITHUB_OUTPUT || { echo "No successful build found"; exit 1; } - - - name: Download artifacts (frontend, webapi) - env: - API: ${{ steps.repo.outputs.api }} - OWNER: ${{ steps.repo.outputs.owner }} - REPO: ${{ steps.repo.outputs.repo }} - TOKEN: ${{ secrets.GITEATOKEN }} - RUN_ID: ${{ steps.pick.outputs.run_id }} + SRC: /runner-cache/builds/latest run: | set -euo pipefail mkdir -p release - LIST="$(curl -sfSL -H "Authorization: token $TOKEN" \ - "$API/repos/$OWNER/$REPO/actions/runs/$RUN_ID/artifacts")" - echo "Artifacts:"; echo "$LIST" | jq -r '.artifacts[]?.name' - - download_artifact () { - local NAME="$1" - local URL - URL="$(echo "$LIST" | jq -r --arg n "$NAME" ' - (.artifacts // []) | map(select(.name==$n)) | .[0].archive_download_url // .[0].url // empty - ')" - [ -n "$URL" ] && [ "$URL" != "null" ] || { echo "Artifact $NAME not found"; exit 1; } - curl -sfSL -H "Authorization: token $TOKEN" -o "$NAME.zip" "$URL" - unzip -o "$NAME.zip" -d "./$NAME" - } - - download_artifact frontend - download_artifact webapi - (cd frontend && zip -r ../DiunaBI-Morska-Frontend.zip .) - (cd webapi && zip -r ../DiunaBI-Morska-WebApi.zip .) + (cd "$SRC/frontend" && zip -r "$GITHUB_WORKSPACE/release/DiunaBI-Morska-Frontend.zip" .) + (cd "$SRC/webapi" && zip -r "$GITHUB_WORKSPACE/release/DiunaBI-Morska-WebApi.zip" .) ls -la release - name: Prepare known_hosts @@ -115,7 +48,7 @@ jobs: mkdir -p ~/.ssh ssh-keyscan -H "${{ env.DEPLOY_HOST }}" >> ~/.ssh/known_hosts 2>/dev/null || true - - name: Send artifacts to PROD + - name: Upload via SCP run: | set -euo pipefail scp -i "${{ env.SSH_KEYFILE }}" -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes \ @@ -125,10 +58,10 @@ jobs: ./release/DiunaBI-Morska-WebApi.zip \ "${{ env.DEPLOY_USER }}@${{ env.DEPLOY_HOST }}:${{ env.DEPLOY_PATH }}" - - name: Run remote deploy script + - name: Remote deploy run: | set -euo pipefail ssh -i "${{ env.SSH_KEYFILE }}" -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes \ "${{ env.DEPLOY_USER }}@${{ env.DEPLOY_HOST }}" << 'EOF' ./deployment/DiunaBI-Morska.Release.sh - EOF + EOF \ No newline at end of file