更新 Gitea CI/CD 触发方式,支持分支触发

This commit is contained in:
2026-05-19 11:27:52 +08:00
parent 50c44ddc2d
commit ebb0743fcb
3 changed files with 36 additions and 24 deletions
+19 -2
View File
@@ -88,7 +88,7 @@ jobs:
docker-image: docker-image:
runs-on: ubuntu-22.04 runs-on: ubuntu-22.04
needs: validate needs: validate
if: startsWith(github.ref, 'refs/tags/') if: startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
permissions: permissions:
contents: read contents: read
defaults: defaults:
@@ -134,7 +134,8 @@ jobs:
env: env:
RAW_REGISTRY_HOST: ${{ vars.REGISTRY_HOST }} RAW_REGISTRY_HOST: ${{ vars.REGISTRY_HOST }}
RAW_REPOSITORY: ${{ github.repository }} RAW_REPOSITORY: ${{ github.repository }}
IMAGE_TAG: ${{ github.ref_name }} RAW_REF: ${{ github.ref }}
RAW_REF_NAME: ${{ github.ref_name }}
run: | run: |
REGISTRY_HOST="${RAW_REGISTRY_HOST#http://}" REGISTRY_HOST="${RAW_REGISTRY_HOST#http://}"
REGISTRY_HOST="${REGISTRY_HOST#https://}" REGISTRY_HOST="${REGISTRY_HOST#https://}"
@@ -142,6 +143,14 @@ jobs:
REPOSITORY_PATH="${RAW_REPOSITORY#/}" REPOSITORY_PATH="${RAW_REPOSITORY#/}"
IMAGE_REPOSITORY_PATH="$(printf '%s' "$REPOSITORY_PATH" | tr '[:upper:]' '[:lower:]')" IMAGE_REPOSITORY_PATH="$(printf '%s' "$REPOSITORY_PATH" | tr '[:upper:]' '[:lower:]')"
IMAGE_NAME="${REGISTRY_HOST}/${IMAGE_REPOSITORY_PATH}" IMAGE_NAME="${REGISTRY_HOST}/${IMAGE_REPOSITORY_PATH}"
case "$RAW_REF" in
refs/heads/main|refs/heads/master)
IMAGE_TAG="latest"
;;
*)
IMAGE_TAG="${RAW_REF_NAME}"
;;
esac
{ {
echo "REGISTRY_HOST=${REGISTRY_HOST}" echo "REGISTRY_HOST=${REGISTRY_HOST}"
echo "REPOSITORY_PATH=${REPOSITORY_PATH}" echo "REPOSITORY_PATH=${REPOSITORY_PATH}"
@@ -179,6 +188,13 @@ jobs:
done done
} }
if [ "${IMAGE_TAG}" = "latest" ]; then
docker build \
-f ./Dockerfile \
-t "${IMAGE_NAME}:latest" \
.
push_with_retry "${IMAGE_NAME}:latest"
else
docker build \ docker build \
-f ./Dockerfile \ -f ./Dockerfile \
-t "${IMAGE_NAME}:${IMAGE_TAG}" \ -t "${IMAGE_NAME}:${IMAGE_TAG}" \
@@ -186,6 +202,7 @@ jobs:
. .
push_with_retry "${IMAGE_NAME}:${IMAGE_TAG}" push_with_retry "${IMAGE_NAME}:${IMAGE_TAG}"
push_with_retry "${IMAGE_NAME}:latest" push_with_retry "${IMAGE_NAME}:latest"
fi
- name: Notify Deploy Server - name: Notify Deploy Server
run: | run: |
+1 -1
View File
@@ -248,7 +248,7 @@ docker compose down
| `bun run start` | 直接运行 `src/server.ts` | | `bun run start` | 直接运行 `src/server.ts` |
| `bun run start:prod` | 先类型检查再启动 | | `bun run start:prod` | 先类型检查再启动 |
| `bun run install:opencode` | 手动安装 `.opencode` 依赖 | | `bun run install:opencode` | 手动安装 `.opencode` 依赖 |
| `bun run pipeline:trigger` | 通过更新远端 tag 触发 Gitea CI/CD(默认优先 `gitea`,否则回退到 `origin`tag=`latest` | | `bun run pipeline:trigger` | 通过强制更新远端 `main` 分支触发 Gitea CI/CD;分支触发时只发布/覆盖 `latest` 镜像 |
### 模型与 API 配置 ### 模型与 API 配置
+9 -14
View File
@@ -3,13 +3,12 @@
set -euo pipefail set -euo pipefail
if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then
echo "Usage: bash scripts/trigger-gitea-pipeline.sh [remote] [tag]" echo "Usage: bash scripts/trigger-gitea-pipeline.sh [remote] [branch]"
echo "" echo ""
echo "Examples:" echo "Examples:"
echo " bash scripts/trigger-gitea-pipeline.sh" echo " bash scripts/trigger-gitea-pipeline.sh"
echo " bash scripts/trigger-gitea-pipeline.sh gitea latest" echo " bash scripts/trigger-gitea-pipeline.sh gitea main"
echo " bash scripts/trigger-gitea-pipeline.sh origin latest" echo " bash scripts/trigger-gitea-pipeline.sh origin main"
echo " bash scripts/trigger-gitea-pipeline.sh gitea v2026.05.15.1"
exit 0 exit 0
fi fi
@@ -28,7 +27,7 @@ resolve_default_remote() {
} }
REMOTE="${1:-}" REMOTE="${1:-}"
TAG="${2:-latest}" BRANCH="${2:-main}"
if ! git rev-parse --git-dir >/dev/null 2>&1; then if ! git rev-parse --git-dir >/dev/null 2>&1; then
echo "[ERROR] Current directory is not a git repository." echo "[ERROR] Current directory is not a git repository."
@@ -52,16 +51,12 @@ if ! git remote get-url "$REMOTE" >/dev/null 2>&1; then
fi fi
HEAD_SHA="$(git rev-parse --short HEAD)" HEAD_SHA="$(git rev-parse --short HEAD)"
MESSAGE="manual trigger: ${TAG} $(date '+%F %T')"
echo "[INFO] HEAD: ${HEAD_SHA}" echo "[INFO] HEAD: ${HEAD_SHA}"
echo "[INFO] Recreate annotated tag '${TAG}'" echo "[INFO] Force-push HEAD to remote branch '${BRANCH}'"
git tag -fa "$TAG" -m "$MESSAGE" git push "$REMOTE" "HEAD:refs/heads/${BRANCH}" --force
echo "[INFO] Push '${TAG}' to remote '${REMOTE}' (force update)" echo "[INFO] Verify remote branch reference"
git push "$REMOTE" "refs/tags/${TAG}" --force git ls-remote "$REMOTE" "refs/heads/${BRANCH}"
echo "[INFO] Verify remote tag reference" echo "[DONE] Pipeline trigger request sent by updating branch '${BRANCH}'."
git ls-remote --tags "$REMOTE" "refs/tags/${TAG}"
echo "[DONE] Pipeline trigger request sent by updating tag '${TAG}'."