fix(ci): source Docker tags from semantic-release version

Avoid stale image tags from placeholder package.json and prevent prereleases from overwriting latest.
This commit is contained in:
jeffusion
2026-03-24 15:06:48 +08:00
parent 7792a78c00
commit f84c0ab777
2 changed files with 41 additions and 10 deletions

View File

@@ -40,35 +40,66 @@ jobs:
run: bun test run: bun test
- name: Run semantic-release - name: Run semantic-release
run: bunx semantic-release id: semantic
uses: codfish/semantic-release-action@v5
env: env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
HUSKY: 0
HUSKY_SKIP_HOOKS: 1
# Docker build and push # Docker build and push
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3 uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry - name: Log in to GitHub Container Registry
if: steps.semantic.outputs.new-release-published == 'true'
uses: docker/login-action@v3 uses: docker/login-action@v3
with: with:
registry: ghcr.io registry: ghcr.io
username: ${{ github.repository_owner }} username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }} password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract version from package.json - name: Derive Docker tags from semantic-release
id: package-version if: steps.semantic.outputs.new-release-published == 'true'
id: docker-tags
run: | run: |
VERSION=$(node -p "require('./package.json').version") VERSION="${{ steps.semantic.outputs.release-version }}"
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Detected version: $VERSION" if [ -z "$VERSION" ]; then
echo "semantic-release did not provide release-version" >&2
exit 1
fi
if [[ "$VERSION" == *"-"* ]]; then
TAGS="ghcr.io/${{ github.repository_owner }}/gitea-ai-assistant:${VERSION}"
else
MAJOR="${VERSION%%.*}"
REST="${VERSION#*.}"
MINOR="${REST%%.*}"
TAGS=$(printf '%s\n' \
"ghcr.io/${{ github.repository_owner }}/gitea-ai-assistant:latest" \
"ghcr.io/${{ github.repository_owner }}/gitea-ai-assistant:${MAJOR}" \
"ghcr.io/${{ github.repository_owner }}/gitea-ai-assistant:${MAJOR}.${MINOR}" \
"ghcr.io/${{ github.repository_owner }}/gitea-ai-assistant:${VERSION}")
fi
{
echo "tags<<EOF"
echo "$TAGS"
echo "EOF"
} >> "$GITHUB_OUTPUT"
echo "Release version: ${VERSION}"
echo "Docker tags to push:"
echo "$TAGS"
- name: Build and push Docker image - name: Build and push Docker image
if: steps.semantic.outputs.new-release-published == 'true'
uses: docker/build-push-action@v5 uses: docker/build-push-action@v5
with: with:
context: . context: .
push: true push: true
tags: | tags: ${{ steps.docker-tags.outputs.tags }}
ghcr.io/${{ github.repository_owner }}/gitea-ai-assistant:latest
ghcr.io/${{ github.repository_owner }}/gitea-ai-assistant:${{ steps.package-version.outputs.version }}
cache-from: type=gha cache-from: type=gha
cache-to: type=gha,mode=max cache-to: type=gha,mode=max

View File

@@ -1,6 +1,6 @@
{ {
"name": "gitea-assistant", "name": "gitea-assistant",
"version": "1.0.0", "version": "0.0.0-develop",
"description": "Gitea功能增强助手包含AI代码审核功能", "description": "Gitea功能增强助手包含AI代码审核功能",
"engines": { "engines": {
"bun": ">=1.2.5" "bun": ">=1.2.5"