This commit is contained in:
Michał Zieliński
2025-09-13 15:20:45 +02:00
parent 148bf73406
commit 2942ab8740

View File

@@ -1,4 +1,4 @@
name: Release Morska (latest successful build) name: Release Morska (from latest build cache)
on: on:
workflow_dispatch: {} workflow_dispatch: {}
@@ -8,8 +8,6 @@ env:
DEPLOY_USER: "mz" DEPLOY_USER: "mz"
DEPLOY_PATH: "./deployment/" DEPLOY_PATH: "./deployment/"
SSH_KEYFILE: "/ci-keys/morska" SSH_KEYFILE: "/ci-keys/morska"
BUILD_WORKFLOW_PATH: ".gitea/workflows/build.yml"
API_BASE: "https://code.bim-it.pl/api/v1"
jobs: jobs:
release: release:
@@ -18,95 +16,30 @@ jobs:
- name: Checkout (for completeness) - name: Checkout (for completeness)
uses: https://github.com/actions/checkout@v4 uses: https://github.com/actions/checkout@v4
- name: Install tools - name: Tools
run: | run: |
set -euo pipefail set -euo pipefail
apt-get update -y apt-get update -y
apt-get install -y jq unzip zip openssh-client apt-get install -y zip openssh-client
- name: Resolve repo/env - name: Verify runner cache
id: repo
env: env:
GITHUB_REPOSITORY: ${{ github.repository }} # owner/repo SRC: /runner-cache/builds/latest
API_BASE: ${{ env.API_BASE }}
run: | run: |
set -euo pipefail set -euo pipefail
OWNER="${GITHUB_REPOSITORY%%/*}" echo "Expecting artifacts in: $SRC"
REPO="${GITHUB_REPOSITORY##*/}" test -d "$SRC/frontend" || { echo "Missing $SRC/frontend"; exit 1; }
echo "owner=$OWNER" >> $GITHUB_OUTPUT test -d "$SRC/webapi" || { echo "Missing $SRC/webapi"; exit 1; }
echo "repo=$REPO" >> $GITHUB_OUTPUT ls -la "$SRC"
echo "api=$API_BASE" >> $GITHUB_OUTPUT
- name: Probe API & auth - name: Create archives
env: env:
API: ${{ steps.repo.outputs.api }} SRC: /runner-cache/builds/latest
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 }}
run: | run: |
set -euo pipefail set -euo pipefail
mkdir -p release mkdir -p release
LIST="$(curl -sfSL -H "Authorization: token $TOKEN" \ (cd "$SRC/frontend" && zip -r "$GITHUB_WORKSPACE/release/DiunaBI-Morska-Frontend.zip" .)
"$API/repos/$OWNER/$REPO/actions/runs/$RUN_ID/artifacts")" (cd "$SRC/webapi" && zip -r "$GITHUB_WORKSPACE/release/DiunaBI-Morska-WebApi.zip" .)
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 .)
ls -la release ls -la release
- name: Prepare known_hosts - name: Prepare known_hosts
@@ -115,7 +48,7 @@ jobs:
mkdir -p ~/.ssh mkdir -p ~/.ssh
ssh-keyscan -H "${{ env.DEPLOY_HOST }}" >> ~/.ssh/known_hosts 2>/dev/null || true ssh-keyscan -H "${{ env.DEPLOY_HOST }}" >> ~/.ssh/known_hosts 2>/dev/null || true
- name: Send artifacts to PROD - name: Upload via SCP
run: | run: |
set -euo pipefail set -euo pipefail
scp -i "${{ env.SSH_KEYFILE }}" -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes \ scp -i "${{ env.SSH_KEYFILE }}" -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes \
@@ -125,7 +58,7 @@ jobs:
./release/DiunaBI-Morska-WebApi.zip \ ./release/DiunaBI-Morska-WebApi.zip \
"${{ env.DEPLOY_USER }}@${{ env.DEPLOY_HOST }}:${{ env.DEPLOY_PATH }}" "${{ env.DEPLOY_USER }}@${{ env.DEPLOY_HOST }}:${{ env.DEPLOY_PATH }}"
- name: Run remote deploy script - name: Remote deploy
run: | run: |
set -euo pipefail set -euo pipefail
ssh -i "${{ env.SSH_KEYFILE }}" -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes \ ssh -i "${{ env.SSH_KEYFILE }}" -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes \