ci(polaris)!: 改为仅在版本标签触发工作流
将运行提示改为中文,移除旧的 runner 冒烟测试工作流。 BREAKING CHANGE: main 分支提交不再触发 Polaris CI。
This commit is contained in:
@@ -2,11 +2,8 @@ name: Polaris CI
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
tags:
|
||||||
- main
|
- 'polaris-v*'
|
||||||
paths:
|
|
||||||
- ts/web/nextjs/polaris/**
|
|
||||||
- .gitea/workflows/polaris-ci.yml
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
verify:
|
verify:
|
||||||
@@ -17,31 +14,31 @@ jobs:
|
|||||||
run:
|
run:
|
||||||
working-directory: ts/web/nextjs/polaris
|
working-directory: ts/web/nextjs/polaris
|
||||||
steps:
|
steps:
|
||||||
- name: Check out repository
|
- name: 检出仓库
|
||||||
uses: https://gitea.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262
|
uses: https://gitea.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: 安装依赖
|
||||||
run: corepack pnpm install --frozen-lockfile
|
run: corepack pnpm install --frozen-lockfile
|
||||||
|
|
||||||
- name: Lint
|
- name: 代码检查
|
||||||
run: corepack pnpm lint
|
run: corepack pnpm lint
|
||||||
|
|
||||||
- name: Typecheck
|
- name: 类型检查
|
||||||
run: corepack pnpm typecheck
|
run: corepack pnpm typecheck
|
||||||
|
|
||||||
- name: Test
|
- name: 运行测试
|
||||||
run: corepack pnpm test
|
run: corepack pnpm test
|
||||||
|
|
||||||
- name: Build standalone server
|
- name: 构建独立服务器
|
||||||
run: corepack pnpm build
|
run: corepack pnpm build
|
||||||
|
|
||||||
- name: Prepare standalone output
|
- name: 准备独立部署文件
|
||||||
run: |
|
run: |
|
||||||
test -f .next/standalone/server.js
|
test -f .next/standalone/server.js
|
||||||
cp -r public .next/standalone/
|
cp -r public .next/standalone/
|
||||||
cp -r .next/static .next/standalone/.next/
|
cp -r .next/static .next/standalone/.next/
|
||||||
|
|
||||||
- name: Smoke test standalone server
|
- name: 独立服务器冒烟测试
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
@@ -56,32 +53,32 @@ jobs:
|
|||||||
ready=1
|
ready=1
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
kill -0 "$server_pid" 2>/dev/null || { echo "server process exited early" >&2; exit 1; }
|
kill -0 "$server_pid" 2>/dev/null || { echo "服务器进程提前退出" >&2; exit 1; }
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
test "$ready" -eq 1 || { echo "server not ready within 30s" >&2; exit 1; }
|
test "$ready" -eq 1 || { echo "服务器在 30 秒内未就绪" >&2; exit 1; }
|
||||||
|
|
||||||
curl -fsS -o /dev/null "$base_url/categories/dev/"
|
curl -fsS -o /dev/null "$base_url/categories/dev/"
|
||||||
curl -fsS -o /dev/null "$base_url/brand/logo.svg"
|
curl -fsS -o /dev/null "$base_url/brand/logo.svg"
|
||||||
|
|
||||||
static_asset=$(curl -fsS "$base_url/" | grep -o '/_next/static/[^"]*' | sed -n '1p')
|
static_asset=$(curl -fsS "$base_url/" | grep -o '/_next/static/[^"]*' | sed -n '1p')
|
||||||
test -n "$static_asset" || { echo "homepage references no /_next/static asset" >&2; exit 1; }
|
test -n "$static_asset" || { echo "首页未引用 /_next/static 静态资源" >&2; exit 1; }
|
||||||
curl -fsS -o /dev/null "$base_url$static_asset"
|
curl -fsS -o /dev/null "$base_url$static_asset"
|
||||||
|
|
||||||
publish:
|
publish:
|
||||||
needs: verify
|
needs: verify
|
||||||
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/polaris-v')
|
||||||
runs-on: polaris-ci
|
runs-on: polaris-ci
|
||||||
container: node:22.23.2-bookworm
|
container: node:22.23.2-bookworm
|
||||||
timeout-minutes: 30
|
timeout-minutes: 30
|
||||||
steps:
|
steps:
|
||||||
- name: Check out repository
|
- name: 检出仓库
|
||||||
uses: https://gitea.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262
|
uses: https://gitea.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262
|
||||||
|
|
||||||
# Daemon comes from the runner (gitea/runner:3-dind-rootless) via the
|
# Daemon comes from the runner (gitea/runner:3-dind-rootless) via the
|
||||||
# job container's /var/run/docker.sock. Only the CLI is installed here;
|
# job container's /var/run/docker.sock. Only the CLI is installed here;
|
||||||
# DOCKER_HOST stays unset and no host socket is mounted.
|
# DOCKER_HOST stays unset and no host socket is mounted.
|
||||||
- name: Install Docker CLI
|
- name: 安装 Docker 命令行工具
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
export DEBIAN_FRONTEND=noninteractive
|
export DEBIAN_FRONTEND=noninteractive
|
||||||
@@ -89,25 +86,25 @@ jobs:
|
|||||||
apt-get install -y --no-install-recommends docker.io
|
apt-get install -y --no-install-recommends docker.io
|
||||||
docker version
|
docker version
|
||||||
|
|
||||||
- name: Resolve image reference
|
- name: 确定镜像引用
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
repository="${GITHUB_REPOSITORY:?GITHUB_REPOSITORY is not set}"
|
repository="${GITHUB_REPOSITORY:?未设置 GITHUB_REPOSITORY}"
|
||||||
owner="${repository%%/*}"
|
owner="${repository%%/*}"
|
||||||
owner="${owner,,}"
|
owner="${owner,,}"
|
||||||
if ! [[ "$owner" =~ ^[a-z0-9]([a-z0-9._-]*[a-z0-9])?$ ]]; then
|
if ! [[ "$owner" =~ ^[a-z0-9]([a-z0-9._-]*[a-z0-9])?$ ]]; then
|
||||||
echo "::error::owner segment '$owner' is not a valid registry path component" >&2
|
echo "::error::所有者名称 '$owner' 不是有效的镜像仓库路径组成部分" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
image="git.labmem.icu/${owner}/polaris:${GITHUB_SHA}"
|
image="git.labmem.icu/${owner}/polaris:${GITHUB_SHA}"
|
||||||
echo "image reference: $image"
|
echo "镜像引用:$image"
|
||||||
echo "IMAGE=$image" >> "$GITHUB_ENV"
|
echo "IMAGE=$image" >> "$GITHUB_ENV"
|
||||||
|
|
||||||
- name: Build image
|
- name: 构建镜像
|
||||||
run: docker build -t "$IMAGE" ts/web/nextjs/polaris
|
run: docker build -t "$IMAGE" ts/web/nextjs/polaris
|
||||||
|
|
||||||
- name: Smoke test image
|
- name: 镜像冒烟测试
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
@@ -128,19 +125,19 @@ jobs:
|
|||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
if [[ "$(docker inspect -f '{{.State.Running}}' "$container")" != "true" ]]; then
|
if [[ "$(docker inspect -f '{{.State.Running}}' "$container")" != "true" ]]; then
|
||||||
echo "container exited early, logs:" >&2
|
echo "容器提前退出,日志:" >&2
|
||||||
docker logs "$container" >&2 || true
|
docker logs "$container" >&2 || true
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
test "$ready" -eq 1 || { echo "server not ready within 30s" >&2; docker logs "$container" >&2 || true; exit 1; }
|
test "$ready" -eq 1 || { echo "服务器在 30 秒内未就绪" >&2; docker logs "$container" >&2 || true; exit 1; }
|
||||||
|
|
||||||
probe /categories/dev/ || { echo "smoke test failed: /categories/dev/" >&2; exit 1; }
|
probe /categories/dev/ || { echo "冒烟测试失败:/categories/dev/" >&2; exit 1; }
|
||||||
probe /brand/logo.svg || { echo "smoke test failed: /brand/logo.svg" >&2; exit 1; }
|
probe /brand/logo.svg || { echo "冒烟测试失败:/brand/logo.svg" >&2; exit 1; }
|
||||||
echo "smoke test passed for $IMAGE"
|
echo "镜像 $IMAGE 冒烟测试通过"
|
||||||
|
|
||||||
- name: Log in and push image
|
- name: 登录并推送镜像
|
||||||
shell: bash
|
shell: bash
|
||||||
env:
|
env:
|
||||||
POLARIS_REGISTRY_USER: ${{ secrets.POLARIS_REGISTRY_USER }}
|
POLARIS_REGISTRY_USER: ${{ secrets.POLARIS_REGISTRY_USER }}
|
||||||
@@ -160,7 +157,7 @@ jobs:
|
|||||||
|
|
||||||
printf '%s' "$POLARIS_REGISTRY_TOKEN" | docker --config "$docker_config_dir" login git.labmem.icu --username "$POLARIS_REGISTRY_USER" --password-stdin >/dev/null
|
printf '%s' "$POLARIS_REGISTRY_TOKEN" | docker --config "$docker_config_dir" login git.labmem.icu --username "$POLARIS_REGISTRY_USER" --password-stdin >/dev/null
|
||||||
|
|
||||||
echo "pushing $IMAGE"
|
echo "正在推送 $IMAGE"
|
||||||
# tee keeps push output visible in the log; pipefail (already set
|
# tee keeps push output visible in the log; pipefail (already set
|
||||||
# via `set -euo pipefail`) fails the step when push itself fails.
|
# via `set -euo pipefail`) fails the step when push itself fails.
|
||||||
docker --config "$docker_config_dir" push "$IMAGE" 2>&1 | tee "$push_log_file"
|
docker --config "$docker_config_dir" push "$IMAGE" 2>&1 | tee "$push_log_file"
|
||||||
@@ -171,6 +168,6 @@ jobs:
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "published image: $IMAGE"
|
echo "已发布镜像:$IMAGE"
|
||||||
echo "digest: $digest"
|
echo "镜像摘要:$digest"
|
||||||
echo "manual deploy reference: docker pull ${IMAGE%%:*}@$digest"
|
echo "手动部署引用:docker pull ${IMAGE%%:*}@$digest"
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
name: Polaris runner smoke test
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
paths:
|
|
||||||
- .gitea/workflows/polaris-runner-smoke.yml
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
smoke:
|
|
||||||
runs-on: polaris-ci
|
|
||||||
steps:
|
|
||||||
- name: Confirm runner can execute a job
|
|
||||||
run: |
|
|
||||||
echo "Polaris runner is working"
|
|
||||||
uname -m
|
|
||||||
Reference in New Issue
Block a user