ops:离线发版工作流切换为同机 Runner 模式

This commit is contained in:
LoveLosita
2026-05-09 15:03:16 +08:00
parent 9025096bc6
commit 6ff1b3a2f2

View File

@@ -4,10 +4,10 @@ on:
workflow_dispatch: workflow_dispatch:
inputs: inputs:
base_ref: base_ref:
description: "可选:用于 impact diff 的起始 ref留空则默认 HEAD^" description: "Optional base ref for impact diff, defaults to HEAD^"
required: false required: false
include_infra: include_infra:
description: "是否同时打 infra bundle" description: "Whether to pack infra bundle too"
required: false required: false
default: "false" default: "false"
@@ -15,29 +15,48 @@ jobs:
package-and-deploy: package-and-deploy:
runs-on: build-host runs-on: build-host
steps: steps:
- name: Checkout - name: Prepare local worktree
uses: actions/checkout@v4 env:
with: SMARTFLOW_REPO_SLUG: ${{ gitea.repository }}
fetch-depth: 0 SMARTFLOW_REPO_SHA: ${{ gitea.sha }}
- name: Resolve release refs
shell: bash shell: bash
run: | run: |
set -euo pipefail set -euo pipefail
APP_TAG="$(git rev-parse --short=12 HEAD)" repo_slug="${SMARTFLOW_REPO_SLUG,,}"
bare_repo="/srv/gitea/data/gitea/data/gitea-repositories/${repo_slug}.git"
worktree_root="/tmp/smartflow-actions"
worktree="${worktree_root}/${SMARTFLOW_REPO_SHA}"
if [[ ! -d "${bare_repo}" ]]; then
echo "gitea bare repo not found: ${bare_repo}" >&2
exit 65
fi
rm -rf "${worktree}"
mkdir -p "${worktree_root}"
git clone --no-checkout "${bare_repo}" "${worktree}"
git -C "${worktree}" checkout --force "${SMARTFLOW_REPO_SHA}"
git -C "${worktree}" clean -dffx
app_tag="$(git -C "${worktree}" rev-parse --short=12 HEAD)"
{
echo "APP_TAG=${app_tag}"
echo "SMARTFLOW_WORKTREE=${worktree}"
} >> "${GITHUB_ENV}"
- name: Resolve release base
shell: bash
run: |
set -euo pipefail
cd "${SMARTFLOW_WORKTREE}"
BASE_REF="${{ inputs.base_ref }}" BASE_REF="${{ inputs.base_ref }}"
if [[ -z "${BASE_REF}" ]] && git rev-parse --verify --quiet HEAD^ >/dev/null; then if [[ -z "${BASE_REF}" ]] && git rev-parse --verify --quiet HEAD^ >/dev/null; then
BASE_REF="$(git rev-parse HEAD^)" BASE_REF="$(git rev-parse HEAD^)"
fi fi
{ echo "BASE_REF=${BASE_REF}" >> "${GITHUB_ENV}"
echo "APP_TAG=${APP_TAG}"
echo "BASE_REF=${BASE_REF}"
} >> "${GITHUB_ENV}"
- name: Build release plan - name: Build release plan
shell: bash shell: bash
run: | run: |
set -euo pipefail set -euo pipefail
cd "${SMARTFLOW_WORKTREE}"
./deploy/impact-rules.sh "${BASE_REF:-}" HEAD deploy/release-plan.env ./deploy/impact-rules.sh "${BASE_REF:-}" HEAD deploy/release-plan.env
cat deploy/release-plan.env cat deploy/release-plan.env
@@ -45,6 +64,7 @@ jobs:
shell: bash shell: bash
run: | run: |
set -euo pipefail set -euo pipefail
cd "${SMARTFLOW_WORKTREE}"
source deploy/release-plan.env source deploy/release-plan.env
args=(--app-tag "${APP_TAG}") args=(--app-tag "${APP_TAG}")
if [[ "${SMARTFLOW_BUILD_BACKEND}" != "1" ]]; then if [[ "${SMARTFLOW_BUILD_BACKEND}" != "1" ]]; then
@@ -62,40 +82,38 @@ jobs:
shell: bash shell: bash
run: | run: |
set -euo pipefail set -euo pipefail
cd "${SMARTFLOW_WORKTREE}"
./deploy/stage-release.sh \ ./deploy/stage-release.sh \
--release-dir ".release/${APP_TAG}" \ --release-dir ".release/${APP_TAG}" \
--plan-file "deploy/release-plan.env" \ --plan-file "deploy/release-plan.env" \
--bundle-dir ".docker-bundles" --bundle-dir ".docker-bundles"
- name: Upload release bundle - name: Materialize release directory
shell: bash shell: bash
env:
SMARTFLOW_DEPLOY_HOST: ${{ secrets.SMARTFLOW_DEPLOY_HOST }}
SMARTFLOW_DEPLOY_PORT: ${{ secrets.SMARTFLOW_DEPLOY_PORT }}
SMARTFLOW_DEPLOY_USER: ${{ secrets.SMARTFLOW_DEPLOY_USER }}
SMARTFLOW_DEPLOY_SSH_KEY: ${{ secrets.SMARTFLOW_DEPLOY_SSH_KEY }}
run: | run: |
set -euo pipefail set -euo pipefail
mkdir -p ~/.ssh cd "${SMARTFLOW_WORKTREE}"
printf '%s\n' "${SMARTFLOW_DEPLOY_SSH_KEY}" > ~/.ssh/id_ed25519 release_root="/srv/smartflow/releases/${APP_TAG}"
chmod 600 ~/.ssh/id_ed25519 release_archive="/srv/smartflow/releases/${APP_TAG}.tgz"
ssh-keyscan -p "${SMARTFLOW_DEPLOY_PORT:-22}" "${SMARTFLOW_DEPLOY_HOST}" >> ~/.ssh/known_hosts mkdir -p /srv/smartflow/releases
tar -C ".release/${APP_TAG}" -czf ".release/${APP_TAG}.tgz" . rm -f "${release_archive}"
ssh -p "${SMARTFLOW_DEPLOY_PORT:-22}" "${SMARTFLOW_DEPLOY_USER}@${SMARTFLOW_DEPLOY_HOST}" "mkdir -p /srv/smartflow/releases/${APP_TAG}" tar -C ".release/${APP_TAG}" -czf "${release_archive}" .
scp -P "${SMARTFLOW_DEPLOY_PORT:-22}" ".release/${APP_TAG}.tgz" "${SMARTFLOW_DEPLOY_USER}@${SMARTFLOW_DEPLOY_HOST}:/srv/smartflow/releases/${APP_TAG}.tgz" rm -rf "${release_root}"
ssh -p "${SMARTFLOW_DEPLOY_PORT:-22}" "${SMARTFLOW_DEPLOY_USER}@${SMARTFLOW_DEPLOY_HOST}" "rm -rf /srv/smartflow/releases/${APP_TAG}/* && tar -xzf /srv/smartflow/releases/${APP_TAG}.tgz -C /srv/smartflow/releases/${APP_TAG} && rm -f /srv/smartflow/releases/${APP_TAG}.tgz" mkdir -p "${release_root}"
tar -xzf "${release_archive}" -C "${release_root}"
rm -f "${release_archive}"
- name: Trigger deploy - name: Trigger deploy
shell: bash shell: bash
env:
SMARTFLOW_DEPLOY_HOST: ${{ secrets.SMARTFLOW_DEPLOY_HOST }}
SMARTFLOW_DEPLOY_PORT: ${{ secrets.SMARTFLOW_DEPLOY_PORT }}
SMARTFLOW_DEPLOY_USER: ${{ secrets.SMARTFLOW_DEPLOY_USER }}
SMARTFLOW_DEPLOY_SSH_KEY: ${{ secrets.SMARTFLOW_DEPLOY_SSH_KEY }}
run: | run: |
set -euo pipefail set -euo pipefail
mkdir -p ~/.ssh smartflow-release deploy "${APP_TAG}"
printf '%s\n' "${SMARTFLOW_DEPLOY_SSH_KEY}" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519 - name: Cleanup worktree
ssh-keyscan -p "${SMARTFLOW_DEPLOY_PORT:-22}" "${SMARTFLOW_DEPLOY_HOST}" >> ~/.ssh/known_hosts if: ${{ always() }}
ssh -p "${SMARTFLOW_DEPLOY_PORT:-22}" "${SMARTFLOW_DEPLOY_USER}@${SMARTFLOW_DEPLOY_HOST}" "smartflow-release deploy ${APP_TAG}" shell: bash
run: |
set -euo pipefail
if [[ -n "${SMARTFLOW_WORKTREE:-}" && "${SMARTFLOW_WORKTREE}" == /tmp/smartflow-actions/* ]]; then
rm -rf "${SMARTFLOW_WORKTREE}"
fi