103 lines
3.2 KiB
YAML
103 lines
3.2 KiB
YAML
name: 'Configure Build Environment'
|
|
description: '验证已有环境并配置 Git 与 kubectl(不执行软件安装)'
|
|
author: 'Your Organization'
|
|
|
|
branding:
|
|
icon: 'settings'
|
|
color: 'green'
|
|
|
|
inputs:
|
|
git-user-name:
|
|
description: 'Git 用户名'
|
|
required: false
|
|
default: 'GiteaActions'
|
|
git-user-email:
|
|
description: 'Git 用户邮箱'
|
|
required: false
|
|
default: 'xgj-actions@xmail.bjxgj.com'
|
|
kube-config:
|
|
description: 'Base64 编码的 kubectl 配置文件'
|
|
required: false
|
|
default: ''
|
|
enable-validation:
|
|
description: '是否执行环境校验 (true/false)'
|
|
required: false
|
|
default: 'true'
|
|
docker-registry:
|
|
description: 'Docker 私有仓库地址'
|
|
required: false
|
|
default: 'docker-registry.bjxgj.com'
|
|
docker-username:
|
|
description: 'Docker 仓库用户名'
|
|
required: false
|
|
default: 'GiteaDocker'
|
|
docker-password:
|
|
description: 'Docker 仓库密码(开启登录时必填)'
|
|
required: false
|
|
default: ''
|
|
skip-docker-login:
|
|
description: '是否跳过 Docker 登录 (true/false)'
|
|
required: false
|
|
default: 'false'
|
|
|
|
outputs:
|
|
docker-version:
|
|
description: '检测到的 Docker 版本'
|
|
value: ${{ steps.validate-tools.outputs.docker-version }}
|
|
kubectl-version:
|
|
description: '检测到的 kubectl 版本'
|
|
value: ${{ steps.validate-tools.outputs.kubectl-version }}
|
|
kubectl-context:
|
|
description: '验证通过时的当前 kubectl 上下文'
|
|
value: ${{ steps.verify-kubectl.outputs.current-context }}
|
|
|
|
runs:
|
|
using: 'composite'
|
|
steps:
|
|
- name: 配置 Git
|
|
shell: bash
|
|
run: bash ${{ github.action_path }}/scripts/configure-git.sh
|
|
env:
|
|
GIT_USER_NAME: ${{ inputs.git-user-name }}
|
|
GIT_USER_EMAIL: ${{ inputs.git-user-email }}
|
|
|
|
- name: 校验工具可用性
|
|
id: validate-tools
|
|
shell: bash
|
|
run: bash ${{ github.action_path }}/scripts/validate-tools.sh
|
|
env:
|
|
ENABLE_VALIDATION: ${{ inputs.enable-validation }}
|
|
|
|
- name: 配置 kubectl
|
|
if: ${{ inputs.kube-config != '' }}
|
|
shell: bash
|
|
run: bash ${{ github.action_path }}/scripts/configure-kubectl.sh
|
|
env:
|
|
KUBE_CONFIG_BASE64: ${{ inputs.kube-config }}
|
|
|
|
- name: 验证 kubectl 连通性
|
|
id: verify-kubectl
|
|
if: ${{ inputs.kube-config != '' && inputs.enable-validation != 'false' }}
|
|
shell: bash
|
|
run: bash ${{ github.action_path }}/scripts/verify-kubectl.sh
|
|
|
|
- name: 登录私有 Docker 仓库
|
|
if: ${{ inputs.skip-docker-login != 'true' }}
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ inputs.docker-registry }}
|
|
username: ${{ inputs.docker-username }}
|
|
password: ${{ inputs.docker-password }}
|
|
|
|
- name: 环境校验完成
|
|
shell: bash
|
|
run: |
|
|
echo '🎉 环境校验与配置步骤完成'
|
|
if [[ "${{ inputs.enable-validation }}" != 'false' ]]; then
|
|
echo " - Docker: ${{ steps.validate-tools.outputs.docker-version }}"
|
|
echo " - kubectl: ${{ steps.validate-tools.outputs.kubectl-version }}"
|
|
fi
|
|
if [[ "${{ inputs.kube-config }}" != '' && "${{ inputs.enable-validation }}" != 'false' ]]; then
|
|
echo " - 当前上下文: ${{ steps.verify-kubectl.outputs.current-context }}"
|
|
fi
|