Merge branch 'v1'

This commit is contained in:
Lyda
2025-08-20 17:26:23 +08:00
6 changed files with 7 additions and 265 deletions

View File

@@ -1,9 +1,9 @@
name: 'Web项目发布构建' name: 'Web项目发布构建'
description: '自动化Web项目发布流程包括版本发布、Docker镜像构建和推送' description: '自动化Web项目发布流程支持版本管理和发布'
author: 'Your Organization' author: 'Your Organization'
branding: branding:
icon: 'upload-cloud' icon: 'tag'
color: 'green' color: 'green'
inputs: inputs:
@@ -22,31 +22,6 @@ inputs:
required: false required: false
default: 'npm run release -- --release -V' default: 'npm run release -- --release -V'
docker-registry:
description: 'Docker仓库地址'
required: false
default: 'docker-registry.bjxgj.com'
docker-context:
description: 'Docker构建上下文路径'
required: false
default: '.'
dockerfile-path:
description: 'Dockerfile路径'
required: false
default: './container/dev/Dockerfile'
docker-tags:
description: '额外的Docker标签 (每行一个标签)'
required: false
default: ''
enable-docker-build:
description: '是否执行Docker构建 (true/false)'
required: false
default: 'true'
node-debug: node-debug:
description: '是否启用Node.js调试模式 (true/false)' description: '是否启用Node.js调试模式 (true/false)'
required: false required: false
@@ -60,14 +35,6 @@ outputs:
version-with-dash: version-with-dash:
description: '版本号(点号替换为横线)' description: '版本号(点号替换为横线)'
value: ${{ steps.get_var.outputs.version_with_dash }} value: ${{ steps.get_var.outputs.version_with_dash }}
docker-image-digest:
description: 'Docker镜像摘要'
value: ${{ steps.build.outputs.digest }}
docker-image-tags:
description: 'Docker镜像标签列表'
value: ${{ steps.build.outputs.tags }}
runs: runs:
using: 'composite' using: 'composite'
@@ -82,13 +49,6 @@ runs:
exit 1 exit 1
fi fi
if [[ "${{ inputs.enable-docker-build }}" == "true" ]]; then
if [[ ! -f "${{ inputs.dockerfile-path }}" ]]; then
echo "❌ 错误: Dockerfile 不存在: ${{ inputs.dockerfile-path }}"
exit 1
fi
fi
echo "✅ 参数验证通过" echo "✅ 参数验证通过"
- name: 发布构建 - name: 发布构建
@@ -124,57 +84,6 @@ runs:
echo "📦 发布版本: $VERSION" echo "📦 发布版本: $VERSION"
echo "📦 带横线版本: $VERSION_WITH_DASH" echo "📦 带横线版本: $VERSION_WITH_DASH"
- name: 准备Docker标签
if: ${{ inputs.enable-docker-build == 'true' }}
id: docker_tags
shell: bash
run: |
echo "🏷️ 准备Docker标签..."
REPO_NAME="${{ github.event.repository.name }}"
REGISTRY="${{ inputs.docker-registry }}"
VERSION="${{ steps.get_var.outputs.version }}"
# 基础标签(保留版本标签)
TAGS="${TAGS}\n${REGISTRY}/${REPO_NAME}:${VERSION}"
# 添加用户自定义标签
if [[ -n "${{ inputs.docker-tags }}" ]]; then
while IFS= read -r tag; do
if [[ -n "$tag" ]]; then
# 如果标签不包含仓库地址,则添加默认仓库前缀
if [[ "$tag" != *"/"* ]]; then
TAGS="${TAGS}\n${REGISTRY}/${REPO_NAME}:${tag}"
else
TAGS="${TAGS}\n${tag}"
fi
fi
done <<< "${{ inputs.docker-tags }}"
fi
echo "Docker标签列表:"
echo -e "$TAGS" | sed 's/^/ - /'
# 将标签转换为多行格式供后续步骤使用
echo -e "$TAGS" > /tmp/docker-tags.txt
# 输出标签给后续步骤使用
{
echo "tags<<EOF"
echo -e "$TAGS"
echo "EOF"
} >> $GITHUB_OUTPUT
- name: 构建并推送Docker镜像
if: ${{ inputs.enable-docker-build == 'true' }}
id: build
uses: docker/build-push-action@v6
with:
context: ${{ inputs.docker-context }}
file: ${{ inputs.dockerfile-path }}
push: true
tags: ${{ steps.docker_tags.outputs.tags }}
- name: 发布总结 - name: 发布总结
shell: bash shell: bash
run: | run: |
@@ -183,18 +92,3 @@ runs:
echo "📋 发布信息:" echo "📋 发布信息:"
echo " - 版本号: ${{ steps.get_var.outputs.version }}" echo " - 版本号: ${{ steps.get_var.outputs.version }}"
echo " - 应用环境: ${{ inputs.app-env }}" echo " - 应用环境: ${{ inputs.app-env }}"
echo " - Sentry启用: ${{ inputs.enable-sentry }}"
echo ""
if [[ "${{ inputs.enable-docker-build }}" == "true" ]]; then
echo "🐳 Docker信息:"
echo " - 仓库: ${{ inputs.docker-registry }}"
echo " - 项目名: ${{ github.event.repository.name }}"
echo " - 主要标签:"
echo " - ${{ steps.get_var.outputs.version }}"
if [[ -n "${{ steps.build.outputs.digest }}" ]]; then
echo " - 镜像摘要: ${{ steps.build.outputs.digest }}"
fi
else
echo "🐳 Docker构建已跳过"
fi

View File

@@ -40,4 +40,3 @@ jobs:
run: | run: |
echo "✅ 发布完成!" echo "✅ 发布完成!"
echo "📦 版本: ${{ steps.release.outputs.version }}" echo "📦 版本: ${{ steps.release.outputs.version }}"
echo "🐳 Docker镜像已推送到仓库"

View File

@@ -1,64 +0,0 @@
name: "自定义Docker标签发布"
on:
push:
branches:
- main
- develop
workflow_dispatch:
inputs:
custom_tag:
description: "自定义Docker标签"
required: false
default: "manual"
jobs:
release:
runs-on: ubuntu-latest
name: "发布项目(自定义标签)"
steps:
- name: 检出代码
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITEA_TOKEN }}
- name: 设置构建环境
uses: actions/xgj/setup-env@main
with:
docker-password: ${{ secrets.DOCKER_PASSWORD }}
skip-kubectl: "true"
- name: 安装依赖
uses: actions/xgj/npm-install@main
with:
package-manager: "pnpm"
- name: 发布构建(带自定义标签)
id: release
uses: actions/xgj/release-web@main
with:
gitea-token: ${{ secrets.GITEA_TOKEN }}
app-env: ${{ github.ref == 'refs/heads/main' && 'production' || 'staging' }}
sentry-auth-token: ${{ secrets.SENTRY_AUTH_TOKEN }}
sentry-dsn: ${{ vars.SENTRY_DSN }}
enable-sentry: "true"
docker-tags: |
${{ github.sha }}
${{ github.ref_name }}
${{ github.event.inputs.custom_tag || 'auto' }}
stable
${{ github.ref == 'refs/heads/main' && 'production' || 'staging' }}
- name: 显示所有Docker标签
run: |
echo "🏷️ 生成的Docker标签包括"
echo " - latest默认"
echo " - prod默认"
echo " - ${{ steps.release.outputs.version }}(版本标签,保留)"
echo " - ${{ github.sha }}(提交哈希)"
echo " - ${{ github.ref_name }}(分支名)"
echo " - ${{ github.event.inputs.custom_tag || 'auto' }}(自定义标签)"
echo " - stable稳定版本"
echo " - ${{ github.ref == 'refs/heads/main' && 'production' || 'staging' }}(环境标签)"

View File

@@ -58,9 +58,6 @@ jobs:
uses: actions/xgj/release-web@main uses: actions/xgj/release-web@main
with: with:
gitea-token: ${{ secrets.GITEA_TOKEN }} gitea-token: ${{ secrets.GITEA_TOKEN }}
docker-tags: |
env-example
${{ github.ref_name }}
env: env:
# 🎯 根据分支设置不同的环境变量 # 🎯 根据分支设置不同的环境变量
APP_ENV: ${{ github.ref == 'refs/heads/main' && 'production' || 'staging' }} APP_ENV: ${{ github.ref == 'refs/heads/main' && 'production' || 'staging' }}

View File

@@ -75,37 +75,9 @@ jobs:
with: with:
gitea-token: ${{ secrets.GITEA_TOKEN }} gitea-token: ${{ secrets.GITEA_TOKEN }}
app-env: ${{ github.ref == 'refs/heads/main' && 'production' || 'develop' }} app-env: ${{ github.ref == 'refs/heads/main' && 'production' || 'develop' }}
sentry-auth-token: ${{ secrets.SENTRY_AUTH_TOKEN }}
sentry-dsn: ${{ vars.SENTRY_DSN }}
enable-sentry: ${{ github.ref == 'refs/heads/main' && 'true' || 'false' }}
docker-registry: ${{ env.REGISTRY }}
dockerfile-path: "./Dockerfile"
docker-tags: |
${{ github.sha }}
${{ github.ref_name }}
${{ github.ref == 'refs/heads/main' && 'stable' || 'unstable' }}
- name: 部署到Kubernetes (生产环境)
if: github.ref == 'refs/heads/main'
run: |
echo "🚀 部署到生产环境..."
kubectl set image deployment/web-app \
web-app=${{ env.REGISTRY }}/${{ github.event.repository.name }}:${{ steps.release.outputs.version }} \
-n production
kubectl rollout status deployment/web-app -n production
- name: 部署到Kubernetes (开发环境)
if: github.ref == 'refs/heads/develop'
run: |
echo "🧪 部署到开发环境..."
kubectl set image deployment/web-app-dev \
web-app=${{ env.REGISTRY }}/${{ github.event.repository.name }}:${{ steps.release.outputs.version }} \
-n development
kubectl rollout status deployment/web-app-dev -n development
- name: 通知发布结果 - name: 通知发布结果
run: | run: |
echo "🎉 发布完成!" echo "🎉 发布完成!"
echo "📦 版本: ${{ steps.release.outputs.version }}" echo "📦 版本: ${{ steps.release.outputs.version }}"
echo "🌍 环境: ${{ github.ref == 'refs/heads/main' && '生产环境' || '开发环境' }}" echo "🌍 环境: ${{ github.ref == 'refs/heads/main' && '生产环境' || '开发环境' }}"
echo "🐳 Docker镜像: ${{ env.REGISTRY }}/${{ github.event.repository.name }}:${{ steps.release.outputs.version }}"

View File

@@ -22,7 +22,7 @@ on:
- minor - minor
- major - major
custom_tags: custom_tags:
description: "自定义Docker标签(每行一个)" description: "自定义标签(每行一个)"
required: false required: false
default: "" default: ""
@@ -35,19 +35,13 @@ jobs:
matrix: matrix:
include: include:
- environment: staging - environment: staging
dockerfile: "./container/dev/Dockerfile"
app_env: "staging" app_env: "staging"
registry: "docker-registry.bjxgj.com"
namespace: "staging" namespace: "staging"
- environment: production - environment: production
dockerfile: "./container/prod/Dockerfile"
app_env: "production" app_env: "production"
registry: "docker-registry.bjxgj.com"
namespace: "production" namespace: "production"
- environment: testing - environment: testing
dockerfile: "./container/test/Dockerfile"
app_env: "testing" app_env: "testing"
registry: "docker-registry.bjxgj.com"
namespace: "testing" namespace: "testing"
steps: steps:
@@ -60,8 +54,6 @@ jobs:
- name: 设置构建环境 - name: 设置构建环境
uses: actions/xgj/setup-env@main uses: actions/xgj/setup-env@main
with: with:
docker-registry: ${{ matrix.registry }}
docker-password: ${{ secrets.DOCKER_PASSWORD }}
kube-config: ${{ secrets.KUBE_CONFIG }} kube-config: ${{ secrets.KUBE_CONFIG }}
- name: 安装依赖 - name: 安装依赖
@@ -69,67 +61,26 @@ jobs:
with: with:
package-manager: "pnpm" package-manager: "pnpm"
- name: 准备环境特定的标签
id: env_tags
run: |
ENVIRONMENT="${{ github.event.inputs.environment }}"
VERSION_TYPE="${{ github.event.inputs.version_type }}"
CUSTOM_TAGS="${{ github.event.inputs.custom_tags }}"
# 基础标签
TAGS="${ENVIRONMENT}"
TAGS="${TAGS}\n${ENVIRONMENT}-${VERSION_TYPE}"
TAGS="${TAGS}\n$(date +%Y%m%d)-${ENVIRONMENT}"
# 添加自定义标签
if [[ -n "$CUSTOM_TAGS" ]]; then
while IFS= read -r tag; do
if [[ -n "$tag" ]]; then
TAGS="${TAGS}\n${tag}-${ENVIRONMENT}"
fi
done <<< "$CUSTOM_TAGS"
fi
{
echo "tags<<EOF"
echo -e "$TAGS"
echo "EOF"
} >> $GITHUB_OUTPUT
echo "🏷️ 环境特定标签:"
echo -e "$TAGS" | sed 's/^/ - /'
- name: 发布构建 - name: 发布构建
id: release id: release
uses: actions/xgj/release-web@main uses: actions/xgj/release-web@main
with: with:
gitea-token: ${{ secrets.GITEA_TOKEN }} gitea-token: ${{ secrets.GITEA_TOKEN }}
app-env: ${{ matrix.app_env }} app-env: ${{ matrix.app_env }}
sentry-auth-token: ${{ secrets.SENTRY_AUTH_TOKEN }}
sentry-dsn: ${{ vars.SENTRY_DSN }}
enable-sentry: ${{ matrix.environment == 'production' && 'true' || 'false' }}
docker-registry: ${{ matrix.registry }}
dockerfile-path: ${{ matrix.dockerfile }}
release-command: "npm run release -- --release -V --increment ${{ github.event.inputs.version_type }}" release-command: "npm run release -- --release -V --increment ${{ github.event.inputs.version_type }}"
docker-tags: ${{ steps.env_tags.outputs.tags }}
- name: 部署到Kubernetes - name: 部署应用
run: | run: |
ENVIRONMENT="${{ github.event.inputs.environment }}" ENVIRONMENT="${{ github.event.inputs.environment }}"
VERSION="${{ steps.release.outputs.version }}" VERSION="${{ steps.release.outputs.version }}"
NAMESPACE="${{ matrix.namespace }}" NAMESPACE="${{ matrix.namespace }}"
IMAGE="${{ matrix.registry }}/${{ github.event.repository.name }}:${VERSION}"
echo "🚀 部署到 ${ENVIRONMENT} 环境..." echo "🚀 部署到 ${ENVIRONMENT} 环境..."
echo "📦 版本: ${VERSION}" echo "📦 版本: ${VERSION}"
echo "🐳 镜像: ${IMAGE}"
echo "📍 命名空间: ${NAMESPACE}" echo "📍 命名空间: ${NAMESPACE}"
kubectl set image deployment/web-app \ # 这里可以根据实际情况部署应用
web-app=${IMAGE} \ # 例如通过配置文件更新、API调用等方式
-n ${NAMESPACE}
kubectl rollout status deployment/web-app -n ${NAMESPACE}
echo "✅ 部署完成!" echo "✅ 部署完成!"
@@ -141,11 +92,4 @@ jobs:
echo " - 环境: ${{ github.event.inputs.environment }}" echo " - 环境: ${{ github.event.inputs.environment }}"
echo " - 版本: ${{ steps.release.outputs.version }}" echo " - 版本: ${{ steps.release.outputs.version }}"
echo " - 版本类型: ${{ github.event.inputs.version_type }}" echo " - 版本类型: ${{ github.event.inputs.version_type }}"
echo " - Docker仓库: ${{ matrix.registry }}" echo " - 命名空间: ${{ matrix.namespace }}"
echo " - Kubernetes命名空间: ${{ matrix.namespace }}"
echo ""
echo "🏷️ 主要标签:"
echo " - latest默认"
echo " - prod默认"
echo " - ${{ steps.release.outputs.version }}(版本标签)"
echo " - ${{ github.event.inputs.environment }}(环境标签)"