67 lines
1.6 KiB
YAML
67 lines
1.6 KiB
YAML
name: Manual Run Build
|
||
on:
|
||
workflow_dispatch:
|
||
inputs:
|
||
# 1. 字符串(默认类型,不写 type 就是 string)
|
||
image_tag:
|
||
description: "镜像 tag"
|
||
required: false
|
||
default: "latest"
|
||
|
||
# 2. 布尔
|
||
build_image:
|
||
description: "是否打镜像"
|
||
type: boolean
|
||
required: false
|
||
default: false
|
||
|
||
# 3. 数字
|
||
timeout_min:
|
||
description: "超时分钟数"
|
||
type: number
|
||
required: false
|
||
default: 10
|
||
|
||
# 4. 下拉选择(单选)
|
||
env_name:
|
||
description: "部署环境"
|
||
type: choice
|
||
options:
|
||
- dev
|
||
- test
|
||
- prod
|
||
required: true
|
||
default: dev
|
||
|
||
# 5. 环境(关联 Gitea 的 Environments 功能)
|
||
deploy_env:
|
||
description: "目标环境"
|
||
type: environment
|
||
required: false
|
||
|
||
jobs:
|
||
build:
|
||
runs-on: ubuntu-latest
|
||
container:
|
||
image: git.vipjhzf.cn/github/ci-base:latest
|
||
steps:
|
||
- name: 克隆
|
||
run: |
|
||
git clone ${{ gitea.server_url }}/${{ gitea.repository }}.git .
|
||
git checkout ${{ gitea.sha }}
|
||
|
||
- name: 编译
|
||
run: |
|
||
go mod tidy
|
||
CGO_ENABLED=0 go build -o myapp .
|
||
|
||
- name: 打镜像(仅手动触发时)
|
||
if: ${{ inputs.build_image == 'true' }}
|
||
run: |
|
||
cat > Dockerfile <<EOF
|
||
FROM git.vipjhzf.cn/github/alpine:3.16.2
|
||
WORKDIR /app
|
||
COPY ./myapp /app/server
|
||
CMD ["/app/server"]
|
||
EOF
|
||
docker build -t myapp:${{ inputs.image_tag }} . |