release1
This commit is contained in:
@@ -1,67 +1,126 @@
|
|||||||
name: Release Morska (from latest build cache)
|
name: ReleaseApp (auto from latest successful BuildApp)
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch: {}
|
workflow_dispatch: {} # Manual trigger with ZERO inputs
|
||||||
|
|
||||||
env:
|
|
||||||
DEPLOY_HOST: "bim-it.pl"
|
|
||||||
DEPLOY_USER: "mz"
|
|
||||||
DEPLOY_PATH: "./deployment/"
|
|
||||||
SSH_KEYFILE: "/ci-keys/morska"
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
release:
|
release:
|
||||||
runs-on: ubuntu-latest
|
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:
|
steps:
|
||||||
- name: Checkout (for completeness)
|
- name: Checkout (for tagging context only)
|
||||||
uses: https://github.com/actions/checkout@v4
|
uses: https://github.com/actions/checkout@v4
|
||||||
|
|
||||||
- name: Tools
|
- name: Install tools
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
sudo apt-get update
|
||||||
apt-get update -y
|
sudo apt-get install -y jq zip
|
||||||
apt-get install -y zip openssh-client
|
|
||||||
|
|
||||||
- name: Verify runner cache
|
# 1) Find latest successful run of "BuildApp"
|
||||||
env:
|
- name: Find latest successful BuildApp run
|
||||||
SRC: /runner-cache/builds/latest
|
id: find_run
|
||||||
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
# Fetch recent runs and filter client-side
|
||||||
echo "Expecting artifacts in: $SRC"
|
RESP="$(curl -fsSL \
|
||||||
test -d "$SRC/frontend" || { echo "Missing $SRC/frontend"; exit 1; }
|
-H "Authorization: token ${{ secrets.GITEA_PAT }}" \
|
||||||
test -d "$SRC/webapi" || { echo "Missing $SRC/webapi"; exit 1; }
|
"$GITEA_BASE_URL/api/v1/repos/$OWNER/$REPO/actions/runs?limit=50")"
|
||||||
ls -la "$SRC"
|
|
||||||
|
|
||||||
- name: Create archives
|
echo "$RESP" | jq . >/dev/null || { echo "Invalid JSON from API"; exit 1; }
|
||||||
env:
|
|
||||||
SRC: /runner-cache/builds/latest
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
mkdir -p release
|
|
||||||
(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
|
RUN_JSON="$(echo "$RESP" | jq -r \
|
||||||
run: |
|
--arg W "$WORKFLOW_NAME" '
|
||||||
set -euo pipefail
|
.workflow_runs
|
||||||
mkdir -p ~/.ssh
|
| map(select(.status=="completed" and .conclusion=="success" and .workflow.name==$W))
|
||||||
ssh-keyscan -H "${{ env.DEPLOY_HOST }}" >> ~/.ssh/known_hosts 2>/dev/null || true
|
| sort_by(.id) | reverse | .[0]
|
||||||
|
')"
|
||||||
|
|
||||||
- name: Upload via SCP
|
RUN_ID="$(echo "$RUN_JSON" | jq -r '.id')"
|
||||||
run: |
|
RUN_HEAD_SHA="$(echo "$RUN_JSON" | jq -r '.head_sha')"
|
||||||
set -euo pipefail
|
|
||||||
scp -i "${{ env.SSH_KEYFILE }}" -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes \
|
|
||||||
./release/DiunaBI-Morska-Frontend.zip \
|
|
||||||
"${{ env.DEPLOY_USER }}@${{ env.DEPLOY_HOST }}:${{ env.DEPLOY_PATH }}"
|
|
||||||
scp -i "${{ env.SSH_KEYFILE }}" -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes \
|
|
||||||
./release/DiunaBI-Morska-WebApi.zip \
|
|
||||||
"${{ env.DEPLOY_USER }}@${{ env.DEPLOY_HOST }}:${{ env.DEPLOY_PATH }}"
|
|
||||||
|
|
||||||
- name: Remote deploy
|
if [[ -z "$RUN_ID" || "$RUN_ID" == "null" ]]; then
|
||||||
|
echo "No successful '$WORKFLOW_NAME' run found." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
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)"
|
||||||
|
|
||||||
|
# 2) List and download artifacts "frontend" and "webapi" via Gitea API
|
||||||
|
- name: List artifacts for that run
|
||||||
|
id: list_artifacts
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
curl -fsSL \
|
||||||
ssh -i "${{ env.SSH_KEYFILE }}" -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes \
|
-H "Authorization: token ${{ secrets.GITEA_PAT }}" \
|
||||||
"${{ env.DEPLOY_USER }}@${{ env.DEPLOY_HOST }}" << 'EOF'
|
"$GITEA_BASE_URL/api/v1/repos/$OWNER/$REPO/actions/runs/${{ steps.find_run.outputs.run_id }}/artifacts" \
|
||||||
./deployment/DiunaBI-Morska.Release.sh
|
| tee artifacts.json
|
||||||
EOF
|
|
||||||
|
# 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)
|
||||||
|
run: |
|
||||||
|
mkdir -p artifacts/frontend
|
||||||
|
ART_ID=$(jq -r '.artifacts[] | select(.name=="frontend") | .id' artifacts.json)
|
||||||
|
curl -fsSL \
|
||||||
|
-H "Authorization: token ${{ secrets.GITEA_PAT }}" \
|
||||||
|
"$GITEA_BASE_URL/api/v1/repos/$OWNER/$REPO/actions/artifacts/$ART_ID/zip" \
|
||||||
|
-o frontend.zip
|
||||||
|
unzip -q frontend.zip -d artifacts/frontend
|
||||||
|
rm -f frontend.zip
|
||||||
|
|
||||||
|
- name: Download 'webapi' artifact (zip -> dir)
|
||||||
|
run: |
|
||||||
|
mkdir -p artifacts/webapi
|
||||||
|
ART_ID=$(jq -r '.artifacts[] | select(.name=="webapi") | .id' artifacts.json)
|
||||||
|
curl -fsSL \
|
||||||
|
-H "Authorization: token ${{ secrets.GITEA_PAT }}" \
|
||||||
|
"$GITEA_BASE_URL/api/v1/repos/$OWNER/$REPO/actions/artifacts/$ART_ID/zip" \
|
||||||
|
-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 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) Autogenerate tag and title, then create release + upload assets
|
||||||
|
- 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"
|
||||||
|
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 generated 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
|
||||||
Reference in New Issue
Block a user