Files
action_test/.gitea/workflows/test.yml
KaGaMi ffc441f6c2
All checks were successful
简单测试 / test (push) Successful in 16s
t1
2025-07-12 20:07:29 +08:00

78 lines
2.6 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: 简单测试
on:
push:
pull_request:
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: 检出代码
uses: actions/checkout@v4
- name: 登录到Gitea Container Registry
run: |
echo "🔐 登录到Gitea Registry..."
# 获取registry地址
REGISTRY_HOST=$(echo "${{ gitea.server_url }}" | sed 's|https\?://||')
cat /etc/docker/daemon.json || echo 'cat /etc/docker/daemon.json 失败'
echo "📡 Registry地址: $REGISTRY_HOST"
echo "👤 用户名: ${{ gitea.actor }}"
# 使用HTTP协议登录
echo "${{ secrets.GITEAS_PAT }}" | docker login $REGISTRY_HOST -u "${{ gitea.actor }}" --password-stdin
echo "✅ 登录成功!"
- name: 构造Docker镜像
run: |
echo "🐳 构造Node.js Hello World应用镜像..."
# 设置镜像标签
REGISTRY_HOST=$(echo "${{ gitea.server_url }}" | sed 's|https\?://||')
OWNER=${{ gitea.repository_owner }}
LOWER_OWNER=$(echo "$OWNER" | tr '[:upper:]' '[:lower:]')
# 获取仓库名称并转换为小写
REPO_NAME=${{ gitea.repository }}
LOWER_REPO_NAME=$(echo "$REPO_NAME" | tr '[:upper:]' '[:lower:]')
# 构造完整的镜像名称 (registry/owner/repo)
IMAGE_NAME="$REGISTRY_HOST/$LOWER_OWNER/$LOWER_REPO_NAME"
IMAGE_TAG="latest"
COMMIT_SHA="${{ gitea.sha }}"
echo "📦 镜像名称: $IMAGE_NAME"
echo "🏷️ 镜像标签: $IMAGE_TAG"
echo "📋 提交SHA: $COMMIT_SHA"
# 构造镜像
docker build -t "$IMAGE_NAME:$IMAGE_TAG" -t "$IMAGE_NAME:$COMMIT_SHA" .
echo "✅ Docker镜像构造完成" # 可以将此信息改为更通用
# - name: 推送Docker镜像
# run: |
# echo "🚀 推送Docker镜像到Gitea registry..."
# # 设置镜像标签
# REGISTRY_HOST=$(echo "${{ gitea.server_url }}" | sed 's|https\?://||')
# REPO_OWNER="${{ gitea.repository_owner }}"
# REPO_OWNER_LOWER="${REPO_OWNER,,}"
# IMAGE_NAME="$REGISTRY_HOST/$REPO_OWNER_LOWER/hello-world-app"
# IMAGE_TAG="latest"
# COMMIT_SHA="${{ gitea.sha }}"
# # 推送镜像
# docker push "$IMAGE_NAME:$IMAGE_TAG"
# docker push "$IMAGE_NAME:$COMMIT_SHA"
# echo "✅ Docker镜像推送完成"
# echo "🎉 镜像已推送到: $IMAGE_NAME:$IMAGE_TAG"
# echo "🎉 镜像已推送到: $IMAGE_NAME:$COMMIT_SHA"