ci: deploy every push from build output
This commit is contained in:
parent
b8b1d83802
commit
9ab24fbe53
32
.github/workflows/pipeline.yml
vendored
32
.github/workflows/pipeline.yml
vendored
@ -4,7 +4,7 @@ on:
|
||||
pull_request:
|
||||
branches: [main]
|
||||
push:
|
||||
branches: [main]
|
||||
branches: ['**']
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
target_host:
|
||||
@ -39,6 +39,32 @@ env:
|
||||
DEFAULT_TARGET_HOST: jp-xhttp-contabo.svc.plus
|
||||
|
||||
jobs:
|
||||
production_state:
|
||||
name: Production State
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
production_image: ${{ steps.production_state.outputs.production_image }}
|
||||
production_tag: ${{ steps.production_state.outputs.production_tag }}
|
||||
production_commit: ${{ steps.production_state.outputs.production_commit }}
|
||||
production_version: ${{ steps.production_state.outputs.production_version }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
|
||||
- name: Probe current production bridge
|
||||
id: production_state
|
||||
env:
|
||||
BRIDGE_SERVER_URL: https://xworkmate-bridge.svc.plus
|
||||
run: |
|
||||
while IFS='=' read -r key value; do
|
||||
echo "${key}=${value}" >> "$GITHUB_OUTPUT"
|
||||
done < <(bash ./scripts/github-actions/report-production-state.sh "${BRIDGE_SERVER_URL}")
|
||||
|
||||
- name: Explain branch push vs production
|
||||
if: ${{ github.event_name == 'push' }}
|
||||
run: |
|
||||
echo "::notice title=Production state::Current production bridge before this run is ${{ steps.production_state.outputs.production_commit }}."
|
||||
|
||||
prep:
|
||||
name: Prep
|
||||
runs-on: ubuntu-latest
|
||||
@ -63,7 +89,9 @@ jobs:
|
||||
|
||||
build:
|
||||
name: Build
|
||||
needs: prep
|
||||
needs:
|
||||
- production_state
|
||||
- prep
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
SERVICE_REGISTRY: ghcr.io
|
||||
|
||||
50
scripts/github-actions/report-production-state.sh
Normal file
50
scripts/github-actions/report-production-state.sh
Normal file
@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
BASE_URL="${1:?base url is required}"
|
||||
|
||||
normalize_url() {
|
||||
local value="$1"
|
||||
if [[ "${value}" =~ ^https:([^/].*)$ ]]; then
|
||||
printf 'https://%s\n' "${BASH_REMATCH[1]}"
|
||||
return
|
||||
fi
|
||||
if [[ "${value}" =~ ^http:([^/].*)$ ]]; then
|
||||
printf 'http://%s\n' "${BASH_REMATCH[1]}"
|
||||
return
|
||||
fi
|
||||
printf '%s\n' "${value}"
|
||||
}
|
||||
|
||||
base_url="$(normalize_url "${BASE_URL}")"
|
||||
|
||||
ping_json="$(
|
||||
curl \
|
||||
--silent \
|
||||
--show-error \
|
||||
--fail \
|
||||
--location \
|
||||
--max-time 20 \
|
||||
"${base_url}/api/ping"
|
||||
)"
|
||||
|
||||
PING_JSON="${ping_json}" python3 - <<'PY'
|
||||
import json
|
||||
import os
|
||||
|
||||
payload = json.loads(os.environ["PING_JSON"])
|
||||
|
||||
if payload.get("status") != "ok":
|
||||
raise SystemExit("production ping status not ok")
|
||||
|
||||
deployed_image = str(payload.get("image", "")).strip()
|
||||
deployed_tag = str(payload.get("tag", "")).strip()
|
||||
deployed_commit = str(payload.get("commit", "")).strip()
|
||||
deployed_version = str(payload.get("version", "")).strip()
|
||||
|
||||
print(f"production_image={deployed_image}")
|
||||
print(f"production_tag={deployed_tag}")
|
||||
print(f"production_commit={deployed_commit}")
|
||||
print(f"production_version={deployed_version}")
|
||||
PY
|
||||
|
||||
Loading…
Reference in New Issue
Block a user