morska rlease
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
name: Release Morska (latest successful build)
|
name: Release Morska (latest successful build)
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch: { } # ręczny trigger
|
workflow_dispatch: {} # ręczny trigger
|
||||||
|
|
||||||
env:
|
env:
|
||||||
DEPLOY_HOST: "bim-it.pl"
|
DEPLOY_HOST: "bim-it.pl"
|
||||||
@@ -24,107 +24,108 @@ jobs:
|
|||||||
apt-get update -y
|
apt-get update -y
|
||||||
apt-get install -y jq unzip zip openssh-client
|
apt-get install -y jq unzip zip openssh-client
|
||||||
|
|
||||||
- name: Resolve repo/env
|
- name: Resolve repo/env
|
||||||
id: repo
|
id: repo
|
||||||
env:
|
env:
|
||||||
GITHUB_REPOSITORY: ${{ github.repository }} # owner/repo
|
GITEA_SERVER_URL: ${{ github.server_url }} # np. https://code.bim-it.pl
|
||||||
API_BASE: ${{ env.API_BASE }}
|
GITHUB_REPOSITORY: ${{ github.repository }} # owner/repo
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
OWNER="${GITHUB_REPOSITORY%%/*}"
|
OWNER="${GITHUB_REPOSITORY%%/*}"
|
||||||
REPO="${GITHUB_REPOSITORY##*/}"
|
REPO="${GITHUB_REPOSITORY##*/}"
|
||||||
echo "owner=$OWNER" >> $GITHUB_OUTPUT
|
echo "owner=$OWNER" >> $GITHUB_OUTPUT
|
||||||
echo "repo=$REPO" >> $GITHUB_OUTPUT
|
echo "repo=$REPO" >> $GITHUB_OUTPUT
|
||||||
echo "api=$API_BASE" >> $GITHUB_OUTPUT
|
echo "api=${GITEA_SERVER_URL%/}/api/v1" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Probe API & auth
|
- name: Probe API & auth
|
||||||
env:
|
env:
|
||||||
API: ${{ steps.repo.outputs.api }}
|
API: ${{ steps.repo.outputs.api }}
|
||||||
OWNER: ${{ steps.repo.outputs.owner }}
|
OWNER: ${{ steps.repo.outputs.owner }}
|
||||||
REPO: ${{ steps.repo.outputs.repo }}
|
REPO: ${{ steps.repo.outputs.repo }}
|
||||||
TOKEN: ${{ secrets.GITEATOKEN }}
|
TOKEN: ${{ secrets.GITEATOKEN }}
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
echo "Probing: $API/repos/$OWNER/$REPO"
|
echo "Probing: $API/repos/$OWNER/$REPO"
|
||||||
curl -sfSL -H "Authorization: token $TOKEN" "$API/repos/$OWNER/$REPO" >/dev/null
|
curl -sfSL -H "Authorization: token $TOKEN" "$API/repos/$OWNER/$REPO" >/dev/null
|
||||||
echo "OK"
|
echo "OK"
|
||||||
|
|
||||||
- name: Pick latest successful build (main)
|
- name: Pick latest successful build (main)
|
||||||
id: pick
|
id: pick
|
||||||
env:
|
env:
|
||||||
API: ${{ steps.repo.outputs.api }}
|
API: ${{ steps.repo.outputs.api }}
|
||||||
OWNER: ${{ steps.repo.outputs.owner }}
|
OWNER: ${{ steps.repo.outputs.owner }}
|
||||||
REPO: ${{ steps.repo.outputs.repo }}
|
REPO: ${{ steps.repo.outputs.repo }}
|
||||||
TOKEN: ${{ secrets.GITEATOKEN }}
|
TOKEN: ${{ secrets.GITEATOKEN }}
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
URL="$API/repos/$OWNER/$REPO/actions/runs?status=success&branch=main&per_page=20"
|
URL="$API/repos/$OWNER/$REPO/actions/runs?status=success&branch=main&per_page=20"
|
||||||
echo "GET $URL"
|
echo "GET $URL"
|
||||||
RESP="$(curl -sfSL -H "Authorization: token $TOKEN" "$URL")"
|
RESP="$(curl -sfSL -H "Authorization: token $TOKEN" "$URL")"
|
||||||
echo "$RESP" | jq -e '.workflow_runs' >/dev/null
|
echo "$RESP" | jq -e '.workflow_runs' >/dev/null
|
||||||
|
|
||||||
RUN_ID="$(echo "$RESP" | jq -r '
|
RUN_ID="$(echo "$RESP" | jq -r '
|
||||||
.workflow_runs
|
.workflow_runs
|
||||||
| map(select(
|
| map(select(
|
||||||
(.head_branch=="main")
|
(.head_branch=="main")
|
||||||
and (.status=="completed")
|
and (.status=="completed")
|
||||||
and (.conclusion=="success")
|
and (.conclusion=="success")
|
||||||
and (
|
and (
|
||||||
(.path? // .workflow_path? // .workflow?.path? // "")
|
(.path? // .workflow_path? // .workflow?.path? // "")
|
||||||
| test("(\\.gitea|\\.github)/workflows/build\\.yml$")
|
| test("(\\.gitea|\\.github)/workflows/build\\.yml$")
|
||||||
)
|
)
|
||||||
))
|
))
|
||||||
| sort_by(.run_number) | reverse | .[0].id // empty
|
| 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; }
|
test -n "$RUN_ID" && echo "run_id=$RUN_ID" >> $GITHUB_OUTPUT || { echo "No successful build found"; exit 1; }
|
||||||
- name: Download artifacts (frontend, webapi)
|
|
||||||
env:
|
- name: Download artifacts (frontend, webapi)
|
||||||
API: ${{ steps.repo.outputs.api }}
|
env:
|
||||||
OWNER: ${{ steps.repo.outputs.owner }}
|
API: ${{ steps.repo.outputs.api }}
|
||||||
REPO: ${{ steps.repo.outputs.repo }}
|
OWNER: ${{ steps.repo.outputs.owner }}
|
||||||
TOKEN: ${{ secrets.GITEA_TOKEN }}
|
REPO: ${{ steps.repo.outputs.repo }}
|
||||||
RUN_ID: ${{ steps.pick.outputs.run_id }}
|
TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||||
run: |
|
RUN_ID: ${{ steps.pick.outputs.run_id }}
|
||||||
set -euo pipefail
|
run: |
|
||||||
mkdir -p release
|
set -euo pipefail
|
||||||
LIST="$(curl -sfSL -H "Authorization: token $TOKEN" \
|
mkdir -p release
|
||||||
"$API/repos/$OWNER/$REPO/actions/runs/$RUN_ID/artifacts")"
|
LIST="$(curl -sfSL -H "Authorization: token $TOKEN" \
|
||||||
echo "Artifacts:"; echo "$LIST" | jq -r '.artifacts[]?.name'
|
"$API/repos/$OWNER/$REPO/actions/runs/$RUN_ID/artifacts")"
|
||||||
|
echo "Artifacts:"; echo "$LIST" | jq -r '.artifacts[]?.name'
|
||||||
download_artifact () {
|
|
||||||
local NAME="$1"
|
download_artifact () {
|
||||||
local URL
|
local NAME="$1"
|
||||||
URL="$(echo "$LIST" | jq -r --arg n "$NAME" '
|
local URL
|
||||||
(.artifacts // []) | map(select(.name==$n)) | .[0].archive_download_url // .[0].url // empty
|
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"
|
[ -n "$URL" ] && [ "$URL" != "null" ] || { echo "Artifact $NAME not found"; exit 1; }
|
||||||
unzip -o "$NAME.zip" -d "./$NAME"
|
curl -sfSL -H "Authorization: token $TOKEN" -o "$NAME.zip" "$URL"
|
||||||
}
|
unzip -o "$NAME.zip" -d "./$NAME"
|
||||||
|
}
|
||||||
download_artifact frontend
|
|
||||||
download_artifact webapi
|
download_artifact frontend
|
||||||
(cd frontend && zip -r ../DiunaBI-Morska-Frontend.zip .)
|
download_artifact webapi
|
||||||
(cd webapi && zip -r ../DiunaBI-Morska-WebApi.zip .)
|
(cd frontend && zip -r ../DiunaBI-Morska-Frontend.zip .)
|
||||||
ls -la release
|
(cd webapi && zip -r ../DiunaBI-Morska-WebApi.zip .)
|
||||||
|
ls -la release
|
||||||
- name: Prepare known_hosts
|
|
||||||
run: |
|
- name: Prepare known_hosts
|
||||||
mkdir -p ~/.ssh
|
run: |
|
||||||
ssh-keyscan -H "${{ env.DEPLOY_HOST }}" >> ~/.ssh/known_hosts 2>/dev/null || true
|
mkdir -p ~/.ssh
|
||||||
|
ssh-keyscan -H "${{ env.DEPLOY_HOST }}" >> ~/.ssh/known_hosts 2>/dev/null || true
|
||||||
- name: Send artifacts to PROD
|
|
||||||
run: |
|
- name: Send artifacts to PROD
|
||||||
scp -i "${{ env.SSH_KEYFILE }}" -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes \
|
run: |
|
||||||
./release/DiunaBI-Morska-Frontend.zip \
|
scp -i "${{ env.SSH_KEYFILE }}" -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes \
|
||||||
"${{ env.DEPLOY_USER }}@${{ env.DEPLOY_HOST }}:${{ env.DEPLOY_PATH }}"
|
./release/DiunaBI-Morska-Frontend.zip \
|
||||||
scp -i "${{ env.SSH_KEYFILE }}" -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes \
|
"${{ env.DEPLOY_USER }}@${{ env.DEPLOY_HOST }}:${{ env.DEPLOY_PATH }}"
|
||||||
./release/DiunaBI-Morska-WebApi.zip \
|
scp -i "${{ env.SSH_KEYFILE }}" -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes \
|
||||||
"${{ env.DEPLOY_USER }}@${{ env.DEPLOY_HOST }}:${{ env.DEPLOY_PATH }}"
|
./release/DiunaBI-Morska-WebApi.zip \
|
||||||
|
"${{ env.DEPLOY_USER }}@${{ env.DEPLOY_HOST }}:${{ env.DEPLOY_PATH }}"
|
||||||
- name: Run remote deploy script
|
|
||||||
run: |
|
- name: Run remote deploy script
|
||||||
ssh -i "${{ env.SSH_KEYFILE }}" -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes \
|
run: |
|
||||||
"${{ env.DEPLOY_USER }}@${{ env.DEPLOY_HOST }}" << 'EOF'
|
ssh -i "${{ env.SSH_KEYFILE }}" -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes \
|
||||||
./deployment/DiunaBI-Morska.Release.sh
|
"${{ env.DEPLOY_USER }}@${{ env.DEPLOY_HOST }}" << 'EOF'
|
||||||
EOF
|
./deployment/DiunaBI-Morska.Release.sh
|
||||||
|
EOF
|
||||||
|
|||||||
Reference in New Issue
Block a user