From 7a9fcaae81023bffeba4185bc98c00942f58be88 Mon Sep 17 00:00:00 2001 From: Jiang Date: Tue, 9 Jun 2026 18:22:16 +0800 Subject: [PATCH] ci: add deployment trigger script --- Dockerfile | 6 ++- scripts/trigger-gitea-pipeline.sh | 67 +++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100755 scripts/trigger-gitea-pipeline.sh diff --git a/Dockerfile b/Dockerfile index 757f518..6690198 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,12 +2,16 @@ FROM condaforge/miniforge3:latest WORKDIR /app +ENV PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple \ + PIP_TRUSTED_HOST=pypi.tuna.tsinghua.edu.cn \ + UV_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple + # 安装 Python 3.12 和 pymetis (通过 conda-forge 避免编译问题) RUN mamba install -y python=3.12 pymetis && \ mamba clean -afy COPY requirements.txt . -RUN pip install uv +RUN pip install --no-cache-dir uv RUN uv pip install --system --no-cache-dir -r requirements.txt # 将代码放入子目录 'app',临时数据目录运行时创建。 diff --git a/scripts/trigger-gitea-pipeline.sh b/scripts/trigger-gitea-pipeline.sh new file mode 100755 index 0000000..53efaa6 --- /dev/null +++ b/scripts/trigger-gitea-pipeline.sh @@ -0,0 +1,67 @@ +#!/usr/bin/env bash + +set -euo pipefail + +if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then + echo "Usage: bash scripts/trigger-gitea-pipeline.sh [remote] [tag]" + echo "" + echo "Examples:" + echo " bash scripts/trigger-gitea-pipeline.sh" + echo " bash scripts/trigger-gitea-pipeline.sh origin latest" + echo " bash scripts/trigger-gitea-pipeline.sh gitea latest" + echo " bash scripts/trigger-gitea-pipeline.sh origin v2026.06.09.1" + exit 0 +fi + +resolve_default_remote() { + if git remote get-url gitea >/dev/null 2>&1; then + echo "gitea" + return 0 + fi + + if git remote get-url origin >/dev/null 2>&1; then + echo "origin" + return 0 + fi + + return 1 +} + +REMOTE="${1:-}" +TAG="${2:-latest}" + +if ! git rev-parse --git-dir >/dev/null 2>&1; then + echo "[ERROR] Current directory is not a git repository." + exit 1 +fi + +if [[ -z "$REMOTE" ]]; then + if ! REMOTE="$(resolve_default_remote)"; then + echo "[ERROR] No default remote found. Expected 'gitea' or 'origin'." + echo "Available remotes:" + git remote -v || true + exit 1 + fi +fi + +if ! git remote get-url "$REMOTE" >/dev/null 2>&1; then + echo "[ERROR] Remote '$REMOTE' does not exist." + echo "Available remotes:" + git remote -v + exit 1 +fi + +HEAD_SHA="$(git rev-parse --short HEAD)" +MESSAGE="manual trigger: ${TAG} $(date '+%F %T')" + +echo "[INFO] HEAD: ${HEAD_SHA}" +echo "[INFO] Recreate annotated tag '${TAG}'" +git tag -fa "$TAG" -m "$MESSAGE" + +echo "[INFO] Push '${TAG}' to remote '${REMOTE}' (force update)" +git push "$REMOTE" "refs/tags/${TAG}" --force + +echo "[INFO] Verify remote tag reference" +git ls-remote --tags "$REMOTE" "refs/tags/${TAG}" + +echo "[DONE] Pipeline trigger request sent by updating tag '${TAG}'."