mirror of
https://git.bjxgj.com/xgj/xgj-actions.git
synced 2025-10-14 17:13:38 +08:00
chore: 更新 Web 项目发布构建的 GitHub Action,简化 Docker 相关配置,移除不必要的输入参数和步骤,优化描述信息以提高可读性。
This commit is contained in:
@@ -40,4 +40,3 @@ jobs:
|
||||
run: |
|
||||
echo "✅ 发布完成!"
|
||||
echo "📦 版本: ${{ steps.release.outputs.version }}"
|
||||
echo "🐳 Docker镜像已推送到仓库"
|
||||
|
@@ -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' }}(环境标签)"
|
@@ -58,9 +58,6 @@ jobs:
|
||||
uses: actions/xgj/release-web@main
|
||||
with:
|
||||
gitea-token: ${{ secrets.GITEA_TOKEN }}
|
||||
docker-tags: |
|
||||
env-example
|
||||
${{ github.ref_name }}
|
||||
env:
|
||||
# 🎯 根据分支设置不同的环境变量
|
||||
APP_ENV: ${{ github.ref == 'refs/heads/main' && 'production' || 'staging' }}
|
||||
|
@@ -75,37 +75,9 @@ jobs:
|
||||
with:
|
||||
gitea-token: ${{ secrets.GITEA_TOKEN }}
|
||||
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: 通知发布结果
|
||||
run: |
|
||||
echo "🎉 发布完成!"
|
||||
echo "📦 版本: ${{ steps.release.outputs.version }}"
|
||||
echo "🌍 环境: ${{ github.ref == 'refs/heads/main' && '生产环境' || '开发环境' }}"
|
||||
echo "🐳 Docker镜像: ${{ env.REGISTRY }}/${{ github.event.repository.name }}:${{ steps.release.outputs.version }}"
|
||||
|
@@ -22,7 +22,7 @@ on:
|
||||
- minor
|
||||
- major
|
||||
custom_tags:
|
||||
description: "自定义Docker标签(每行一个)"
|
||||
description: "自定义标签(每行一个)"
|
||||
required: false
|
||||
default: ""
|
||||
|
||||
@@ -35,19 +35,13 @@ jobs:
|
||||
matrix:
|
||||
include:
|
||||
- environment: staging
|
||||
dockerfile: "./container/dev/Dockerfile"
|
||||
app_env: "staging"
|
||||
registry: "docker-registry.bjxgj.com"
|
||||
namespace: "staging"
|
||||
- environment: production
|
||||
dockerfile: "./container/prod/Dockerfile"
|
||||
app_env: "production"
|
||||
registry: "docker-registry.bjxgj.com"
|
||||
namespace: "production"
|
||||
- environment: testing
|
||||
dockerfile: "./container/test/Dockerfile"
|
||||
app_env: "testing"
|
||||
registry: "docker-registry.bjxgj.com"
|
||||
namespace: "testing"
|
||||
|
||||
steps:
|
||||
@@ -60,8 +54,6 @@ jobs:
|
||||
- name: 设置构建环境
|
||||
uses: actions/xgj/setup-env@main
|
||||
with:
|
||||
docker-registry: ${{ matrix.registry }}
|
||||
docker-password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
kube-config: ${{ secrets.KUBE_CONFIG }}
|
||||
|
||||
- name: 安装依赖
|
||||
@@ -69,67 +61,26 @@ jobs:
|
||||
with:
|
||||
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: 发布构建
|
||||
id: release
|
||||
uses: actions/xgj/release-web@main
|
||||
with:
|
||||
gitea-token: ${{ secrets.GITEA_TOKEN }}
|
||||
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 }}"
|
||||
docker-tags: ${{ steps.env_tags.outputs.tags }}
|
||||
|
||||
- name: 部署到Kubernetes
|
||||
- name: 部署应用
|
||||
run: |
|
||||
ENVIRONMENT="${{ github.event.inputs.environment }}"
|
||||
VERSION="${{ steps.release.outputs.version }}"
|
||||
NAMESPACE="${{ matrix.namespace }}"
|
||||
IMAGE="${{ matrix.registry }}/${{ github.event.repository.name }}:${VERSION}"
|
||||
|
||||
echo "🚀 部署到 ${ENVIRONMENT} 环境..."
|
||||
echo "📦 版本: ${VERSION}"
|
||||
echo "🐳 镜像: ${IMAGE}"
|
||||
echo "📍 命名空间: ${NAMESPACE}"
|
||||
|
||||
kubectl set image deployment/web-app \
|
||||
web-app=${IMAGE} \
|
||||
-n ${NAMESPACE}
|
||||
|
||||
kubectl rollout status deployment/web-app -n ${NAMESPACE}
|
||||
# 这里可以根据实际情况部署应用
|
||||
# 例如通过配置文件更新、API调用等方式
|
||||
|
||||
echo "✅ 部署完成!"
|
||||
|
||||
@@ -141,11 +92,4 @@ jobs:
|
||||
echo " - 环境: ${{ github.event.inputs.environment }}"
|
||||
echo " - 版本: ${{ steps.release.outputs.version }}"
|
||||
echo " - 版本类型: ${{ github.event.inputs.version_type }}"
|
||||
echo " - Docker仓库: ${{ matrix.registry }}"
|
||||
echo " - Kubernetes命名空间: ${{ matrix.namespace }}"
|
||||
echo ""
|
||||
echo "🏷️ 主要标签:"
|
||||
echo " - latest(默认)"
|
||||
echo " - prod(默认)"
|
||||
echo " - ${{ steps.release.outputs.version }}(版本标签)"
|
||||
echo " - ${{ github.event.inputs.environment }}(环境标签)"
|
||||
echo " - 命名空间: ${{ matrix.namespace }}"
|
||||
|
Reference in New Issue
Block a user