From 9ab24fbe53401accb53353466d56dff21e54058d Mon Sep 17 00:00:00 2001 From: Haitao Pan Date: Sun, 12 Apr 2026 18:33:04 +0800 Subject: [PATCH] ci: deploy every push from build output --- .github/workflows/pipeline.yml | 32 +++++++++++- .../github-actions/report-production-state.sh | 50 +++++++++++++++++++ 2 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 scripts/github-actions/report-production-state.sh diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 3655284..d1c5c0f 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -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 diff --git a/scripts/github-actions/report-production-state.sh b/scripts/github-actions/report-production-state.sh new file mode 100644 index 0000000..b602704 --- /dev/null +++ b/scripts/github-actions/report-production-state.sh @@ -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 +