Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2d691c9538 |
+36
-5
@@ -3,8 +3,10 @@ name: CI Pipeline
|
||||
on:
|
||||
push:
|
||||
branches: [main, develop]
|
||||
tags:
|
||||
- 'v*'
|
||||
pull_request:
|
||||
branches: [main]
|
||||
branches: [main, develop]
|
||||
|
||||
env:
|
||||
REGISTRY: git.xiaoxiajianji.com
|
||||
@@ -50,7 +52,12 @@ jobs:
|
||||
name: Build & Push Docker Image
|
||||
runs-on: ubuntu-latest
|
||||
needs: lint-and-build
|
||||
if: github.ref == 'refs/heads/main'
|
||||
# 仅在 main/develop 分支和 release tag 上构建推送镜像
|
||||
# PR 和其他分支不推送镜像,避免产生多余 tag
|
||||
if: |
|
||||
github.ref == 'refs/heads/main' ||
|
||||
github.ref == 'refs/heads/develop' ||
|
||||
startsWith(github.ref, 'refs/tags/v')
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
@@ -71,13 +78,37 @@ jobs:
|
||||
username: ${{ gitea.actor }}
|
||||
password: ${{ secrets.GITEA_TOKEN }}
|
||||
|
||||
- name: Set image tags based on ref
|
||||
id: tags
|
||||
run: |
|
||||
IMAGE="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}"
|
||||
case "${{ github.ref }}" in
|
||||
refs/heads/main)
|
||||
# main 分支:latest + commit sha(版本号用 sha)
|
||||
TAGS="${IMAGE}:latest,${IMAGE}:${{ gitea.sha }}"
|
||||
;;
|
||||
refs/heads/develop)
|
||||
# develop 分支:固定 dev tag(覆盖推送,不堆积)
|
||||
TAGS="${IMAGE}:dev"
|
||||
;;
|
||||
refs/tags/v*)
|
||||
# release tag:用版本号作为 tag
|
||||
VERSION="${GITHUB_REF_NAME}"
|
||||
TAGS="${IMAGE}:${VERSION}"
|
||||
;;
|
||||
*)
|
||||
echo "::warning::No push for ref ${{ github.ref }}"
|
||||
TAGS=""
|
||||
;;
|
||||
esac
|
||||
echo "tags=${TAGS}"
|
||||
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Build and push
|
||||
uses: actions/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
tags: |
|
||||
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
|
||||
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ gitea.sha }}
|
||||
tags: ${{ steps.tags.outputs.tags }}
|
||||
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache
|
||||
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache,mode=max
|
||||
|
||||
Reference in New Issue
Block a user