Files
yunhai.netcore.tool/.gitea/workflows/build.yml
T
wanghu 8c840aa933
build / build-push (push) Failing after 40s
git
2026-09-02 10:44:33 +08:00

59 lines
2.7 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
name: build
# .NET Core 应用 CI:clone 源码 -> docker build(dotnet restore/build 在 Dockerfile 内)-> push Nexus -> 通知 projman 建档
# 触发:push 到 main / 手动 Run workflow(可勾选缓存重建)
# 注意:dotnet 构建发生在 docker build 内部,宿主卷挂不进去;其缓存 = docker 层缓存
# (Dockerfile 应按「COPY *.csproj -> dotnet restore -> COPY 其余」分层以命中层缓存)。
# cache_bust 勾选时清空 docker builder 层缓存,强制下次全量重建。
# 依赖仓库 Secrets:NEXUS_USER / NEXUS_PASSWORD(docker-hosted 推送)/ DEPLOY_TOKEN(webhook 鉴权)
# 依赖 docker/Dockerfile(由 projman 注入,开发者也可自备——已写则尊重不覆盖)
on:
push:
branches: [ main ]
workflow_dispatch:
inputs:
cache_bust:
description: '构建前清空 NuGet 缓存'
required: false
default: 'false'
jobs:
build-push:
runs-on: ubuntu-latest
container:
image: docker:24
options: --network infra-infra-net
steps:
- name: 安装 git / curl(alpine)
run: apk add --no-cache git curl
- name: 拉取源码(内网无 GitHub,手动 clone 本仓库)
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git clone --depth 1 --branch main "http://x-access-token:${GITHUB_TOKEN}@gitea.yunhaixingtong.com/${{ github.repository }}.git" /tmp/src
cp -a /tmp/src/. .
rm -rf /tmp/src
COMMIT_MSG=$(git log -1 --pretty=%s | tr '\n' ' ' | sed 's/["\\]/ /g' | cut -c1-200)
echo "COMMIT_MSG=${COMMIT_MSG}" >> "$GITHUB_ENV"
# 可选:清空 docker 构建层缓存(仅手动勾选 cache_bust 时;.NET 构建缓存即 docker 层缓存)
- name: 可选清空构建缓存
if: ${{ inputs.cache_bust == 'true' }}
run: |
docker builder prune -f
echo "docker build cache busted"
- name: 构建并推送镜像
run: |
set -e
TAG=$(echo "$GITHUB_SHA" | cut -c1-8)
echo "${{ secrets.NEXUS_PASSWORD }}" | docker login nexus:8083 -u "${{ secrets.NEXUS_USER }}" --password-stdin
docker build -t "nexus:8083/docker-hosted/docprint-service:${TAG}" -f docker/Dockerfile .
docker push "nexus:8083/docker-hosted/docprint-service:${TAG}"
echo "TAG=${TAG}" >> "$GITHUB_ENV"
- name: 通知 projman 部署
run: |
curl -sS -X POST "http://192.168.10.160:8090/projman/api/deploy/webhook" \
-H "Content-Type: application/json" \
-H "X-Deploy-Token: ${{ secrets.DEPLOY_TOKEN }}" \
-d "{\"app\":\"docprint\",\"tag\":\"${TAG}\",\"sha\":\"${GITHUB_SHA}\",\"message\":\"${COMMIT_MSG}\"}"