Files
ogame-vue-ts/.github/workflows/ogame-vue-ts.yml
coolxitech e4c4cdd63c chore(workflow): 更新 GitHub Actions 工作流配置
- 升级 actions/checkout 从 v4 到 v6
- 升级 pnpm/action-setup 从 v3 到 v4 并更新版本到 latest
- 升级 actions/setup-node 从 v4 到 v6
- 升级 actions/setup-java 从 v4 到 v5
- 升级 actions/cache 从 v4 到 v5
- 升级 softprops/action-gh-release 从 v1 到 v2
- 升级 actions/configure-pages 从 v3 到 v5
- 升级 actions/deploy-pages 从 v2 到 v4
- 添加构建产物验证步骤
- 添加缓存 pnpm 依赖的配置
- 优化 Docker 镜像标签和元数据配置
- 改进条件判断逻辑以优化 Docker 推送流程
2026-01-08 17:40:29 +08:00

126 lines
3.9 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
name: 构建并发布 Docker 镜像
on:
push:
branches: [main]
tags: ['v*.*.*'] # 打 tag 时也触发
workflow_dispatch:
permissions:
contents: read
packages: write
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: 检出代码
uses: actions/checkout@v6
with:
fetch-depth: 0
# 设置 Node.js 环境
- name: 设置 Node.js
uses: actions/setup-node@v6
with:
node-version: '20'
# 设置 pnpm
- name: 设置 pnpm
uses: pnpm/action-setup@v4
with:
version: latest
# 缓存 pnpm 依赖
- name: 缓存 pnpm 依赖
uses: actions/cache@v5
with:
path: |
~/.pnpm-store
node_modules
key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-
# 安装依赖
- name: 安装依赖
run: pnpm install --frozen-lockfile
# 构建项目
- name: 构建项目
run: pnpm run build
# 验证构建产物
- name: 验证构建产物
run: |
if [ ! -d "docs" ]; then
echo "❌ 构建失败docs 目录不存在"
exit 1
fi
if [ ! -f "docs/index.html" ]; then
echo "❌ 构建失败docs/index.html 不存在"
exit 1
fi
echo "✅ 构建产物验证通过"
ls -la docs/
# 获取当前日期
- name: 获取当前日期
id: date
run: echo "date=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
# 准备 CI 构建环境
- name: 准备 CI 构建环境
run: |
# 使用 CI 专用的 dockerignore
cp .dockerignore.ci .dockerignore
echo "✅ 已切换到 CI 构建模式"
echo "📁 当前构建上下文文件:"
ls -la | grep -E "(docs|nginx.conf|Dockerfile.ci|\.dockerignore)$"
# QEMU 用于支持多架构构建(必须)
- name: 设置 QEMU
uses: docker/setup-qemu-action@v3
# Buildx 是目前官方唯一推荐的多架构构建方式
- name: 设置 Docker Buildx
uses: docker/setup-buildx-action@v3
# 登录 GHCR始终执行
- name: 登录 GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# 登录 Docker Hub只在用户名存在时执行
- name: 登录 Docker Hub
if: vars.DOCKERHUB_USERNAME != '' # 只检查 vars忽略 secrets
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# 构建并推送多架构镜像(使用构建产物)
- name: 构建并推送多架构镜像
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile.ci
platforms: linux/amd64,linux/arm64
push: true
tags: |
ghcr.io/${{ github.repository_owner }}/ogame-vue-ts:latest
ghcr.io/${{ github.repository_owner }}/ogame-vue-ts:${{ github.sha }}
${{ vars.DOCKERHUB_USERNAME && format('{0}/ogame-vue-ts:latest', vars.DOCKERHUB_USERNAME) || '' }}
${{ vars.DOCKERHUB_USERNAME && format('{0}/ogame-vue-ts:{1}', vars.DOCKERHUB_USERNAME, github.sha) || '' }}
cache-from: type=gha
cache-to: type=gha,mode=max
labels: |
org.opencontainers.image.title=OGame Vue Ts
org.opencontainers.image.description=OGame Vue TypeScript Implementation
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.created=${{ steps.date.outputs.date }}