Skip to content

chore: add deps

chore: add deps #37

# push main/master 或 tag 时:构建并推送 Runner 容器镜像到 GHCR(tag 带 -runner 后缀)
name: Publish image (Runner)
on:
push:
branches:
- main
- master
tags:
- 'v*'
workflow_dispatch:
concurrency:
group: publish-runner-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
packages: write
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build:
name: Build and push Runner image
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Verify build context (Dockerfile.runner 所需源码齐全)
id: verify
run: |
set -e
MISSING=""
[ ! -f go.mod ] && MISSING="${MISSING} go.mod"
[ ! -f go.sum ] && MISSING="${MISSING} go.sum"
[ ! -f cmd/runner-agent/main.go ] && MISSING="${MISSING} cmd/runner-agent/main.go"
MISSING="${MISSING# }"
if [ -z "$MISSING" ]; then
echo "has_go_source=true" >> $GITHUB_OUTPUT
else
echo "has_go_source=false" >> $GITHUB_OUTPUT
echo "::warning::Runner 构建所需文件缺失(${MISSING}),跳过构建。请确认已提交并推送 go.mod、go.sum、cmd/ 等完整源码到本仓库后再构建。"
fi
- name: Set up QEMU
if: steps.verify.outputs.has_go_source == 'true'
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
if: steps.verify.outputs.has_go_source == 'true'
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
if: steps.verify.outputs.has_go_source == 'true'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Compute canonical image name (lowercase)
if: steps.verify.outputs.has_go_source == 'true'
id: vars
shell: bash
run: |
set -eu
IMAGE_REF="${IMAGE_NAME:-$GITHUB_REPOSITORY}"
CANONICAL_IMAGE="${REGISTRY}/${IMAGE_REF,,}"
echo "canonical=${CANONICAL_IMAGE}" >> "$GITHUB_OUTPUT"
- name: Get version for build
if: steps.verify.outputs.has_go_source == 'true'
id: version
run: |
VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo "dev-$(git rev-parse --short HEAD)")
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Extract Docker metadata (tags, labels)
if: steps.verify.outputs.has_go_source == 'true'
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ steps.vars.outputs.canonical }}
tags: |
type=ref,event=branch
type=ref,event=tag
type=sha,format=short,prefix=sha-
type=semver,pattern={{version}},enable=${{ startsWith(github.ref, 'refs/tags/v') }}
type=semver,pattern={{major}}.{{minor}},enable=${{ startsWith(github.ref, 'refs/tags/v') }}
type=semver,pattern={{major}},enable=${{ startsWith(github.ref, 'refs/tags/v') }}
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v') }}
- name: Prepare Runner tags (same image, tag suffix -runner)
if: steps.verify.outputs.has_go_source == 'true'
id: runner-tags
run: |
echo "tags<<EOF" >> "$GITHUB_OUTPUT"
# metadata-action 可能输出逗号/换行分隔;每行 image:tag 转为 image:tag-runner
echo "${{ steps.meta.outputs.tags }}" | tr ',' '\n' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//' | while IFS= read -r line; do
[ -z "$line" ] && continue
if [[ "$line" == *:* ]]; then
echo "$line" | sed 's/\(:.*\)$/\1-runner/'
else
echo "${line}:latest-runner"
fi
done >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
- name: Build and push Runner image (container mode)
if: steps.verify.outputs.has_go_source == 'true'
uses: docker/build-push-action@v6
with:
context: ${{ github.workspace }}
file: ${{ github.workspace }}/Dockerfile.runner
push: true
tags: ${{ steps.runner-tags.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max