Skip to content

Commit f39aa1c

Browse files
CharmCharm
authored andcommitted
update ci
1 parent 3776fa6 commit f39aa1c

File tree

5 files changed

+70
-56
lines changed

5 files changed

+70
-56
lines changed

.github/workflows/build-and-push.yml

Lines changed: 38 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ name: Build and Push Docker Images
22

33
on:
44
push:
5-
branches:
6-
- main
5+
# branches:
6+
# - main
77
tags:
88
- "v*"
9-
pull_request:
10-
branches:
11-
- main
9+
# pull_request:
10+
# branches:
11+
# - main
1212

1313
env:
1414
DOCKERHUB_USERNAME: charmy1220
@@ -43,35 +43,27 @@ jobs:
4343
uses: docker/setup-buildx-action@v3
4444

4545
- name: Log in to Docker Hub
46-
if: github.event_name != 'pull_request'
4746
uses: docker/login-action@v3
4847
with:
4948
registry: ${{ env.REGISTRY }}
5049
username: ${{ env.DOCKERHUB_USERNAME }}
5150
password: ${{ env.DOCKERHUB_TOKEN }}
5251

53-
- name: Extract metadata
54-
id: meta
55-
uses: docker/metadata-action@v5
56-
with:
57-
images: ${{ env.REGISTRY }}/${{ env.DOCKERHUB_USERNAME }}/${{ matrix.service.image }}
58-
tags: |
59-
type=ref,event=branch
60-
type=ref,event=pr
61-
type=semver,pattern={{version}}
62-
type=semver,pattern={{major}}.{{minor}}
63-
type=semver,pattern={{major}}
64-
type=raw,value=latest,enable={{is_default_branch}}
52+
- name: Extract tag name
53+
id: extract_tag
54+
run: |
55+
TAG_NAME=${GITHUB_REF#refs/tags/}
56+
echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT
57+
echo "Extracted tag: $TAG_NAME"
6558
6659
- name: Build and push Docker image
6760
uses: docker/build-push-action@v5
6861
timeout-minutes: 30
6962
with:
7063
context: ${{ matrix.service.context }}
7164
file: ${{ matrix.service.dockerfile }}
72-
push: ${{ github.event_name != 'pull_request' }}
73-
tags: ${{ steps.meta.outputs.tags }}
74-
labels: ${{ steps.meta.outputs.labels }}
65+
push: true
66+
tags: ${{ env.REGISTRY }}/${{ env.DOCKERHUB_USERNAME }}/${{ matrix.service.image }}:${{ steps.extract_tag.outputs.tag_name }}
7567
cache-from: type=gha
7668
cache-to: type=gha,mode=max
7769
platforms: linux/amd64
@@ -82,49 +74,50 @@ jobs:
8274
needs: build-and-push
8375
runs-on: ubuntu-latest
8476
if: startsWith(github.ref, 'refs/tags/v')
77+
permissions:
78+
contents: write
79+
discussions: write
8580

8681
steps:
8782
- name: Checkout code
8883
uses: actions/checkout@v4
8984
with:
9085
fetch-depth: 0
9186

87+
- name: Extract tag name
88+
id: extract_tag
89+
run: |
90+
TAG_NAME=${GITHUB_REF#refs/tags/}
91+
echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT
92+
echo "Current tag: $TAG_NAME"
93+
9294
- name: Generate changelog
9395
id: changelog
9496
run: |
95-
# get current tag and previous tag
96-
CURRENT_TAG=${GITHUB_REF#refs/tags/}
97+
CURRENT_TAG=${{ steps.extract_tag.outputs.tag_name }}
9798
PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD~1 2>/dev/null || echo "")
9899
99-
echo "current_tag=$CURRENT_TAG" >> $GITHUB_OUTPUT
100+
echo "## 🚀 Release $CURRENT_TAG" > CHANGELOG.md
101+
echo "" >> CHANGELOG.md
102+
echo "### 📦 Docker Images" >> CHANGELOG.md
103+
echo "- \`${{ env.DOCKERHUB_USERNAME }}/lmeterx-be:$CURRENT_TAG\`" >> CHANGELOG.md
104+
echo "- \`${{ env.DOCKERHUB_USERNAME }}/lmeterx-eng:$CURRENT_TAG\`" >> CHANGELOG.md
105+
echo "- \`${{ env.DOCKERHUB_USERNAME }}/lmeterx-fe:$CURRENT_TAG\`" >> CHANGELOG.md
106+
echo "" >> CHANGELOG.md
100107
101-
# generate changelog
102108
if [ -n "$PREVIOUS_TAG" ]; then
103-
echo "## 🚀 Changes in $CURRENT_TAG" > CHANGELOG.md
104-
echo "" >> CHANGELOG.md
105-
echo "### 📦 Docker Images" >> CHANGELOG.md
106-
echo "- \`${{ env.DOCKERHUB_USERNAME }}/lmeterx-be:$CURRENT_TAG\`" >> CHANGELOG.md
107-
echo "- \`${{ env.DOCKERHUB_USERNAME }}/lmeterx-eng:$CURRENT_TAG\`" >> CHANGELOG.md
108-
echo "- \`${{ env.DOCKERHUB_USERNAME }}/lmeterx-fe:$CURRENT_TAG\`" >> CHANGELOG.md
109-
echo "" >> CHANGELOG.md
110-
echo "### 📝 Commits" >> CHANGELOG.md
109+
echo "### 📝 Changes since $PREVIOUS_TAG" >> CHANGELOG.md
111110
git log --pretty=format:"- %s (%h)" $PREVIOUS_TAG..$CURRENT_TAG >> CHANGELOG.md
112111
else
113-
echo "## 🚀 Release $CURRENT_TAG" > CHANGELOG.md
114-
echo "" >> CHANGELOG.md
115-
echo "### 📦 Docker Images" >> CHANGELOG.md
116-
echo "- \`${{ env.DOCKERHUB_USERNAME }}/lmeterx-be:$CURRENT_TAG\`" >> CHANGELOG.md
117-
echo "- \`${{ env.DOCKERHUB_USERNAME }}/lmeterx-eng:$CURRENT_TAG\`" >> CHANGELOG.md
118-
echo "- \`${{ env.DOCKERHUB_USERNAME }}/lmeterx-fe:$CURRENT_TAG\`" >> CHANGELOG.md
119-
echo "" >> CHANGELOG.md
120-
echo "Initial release" >> CHANGELOG.md
112+
echo "### 📝 Initial Release" >> CHANGELOG.md
113+
echo "This is the initial release of LMeterX." >> CHANGELOG.md
121114
fi
122115
123116
- name: Create GitHub Release
124117
uses: softprops/action-gh-release@v1
125118
with:
126-
tag_name: ${{ steps.changelog.outputs.current_tag }}
127-
name: Release ${{ steps.changelog.outputs.current_tag }}
119+
tag_name: ${{ steps.extract_tag.outputs.tag_name }}
120+
name: Release ${{ steps.extract_tag.outputs.tag_name }}
128121
body_path: CHANGELOG.md
129122
draft: false
130123
prerelease: false
@@ -134,7 +127,7 @@ jobs:
134127

135128
- name: Update docker-compose.yml
136129
run: |
137-
CURRENT_TAG=${GITHUB_REF#refs/tags/}
130+
CURRENT_TAG=${{ steps.extract_tag.outputs.tag_name }}
138131
139132
# update docker-compose.yml with new image tags
140133
sed -i "s|${{ env.DOCKERHUB_USERNAME }}/lmeterx-be:.*|${{ env.DOCKERHUB_USERNAME }}/lmeterx-be:$CURRENT_TAG|g" docker-compose.yml
@@ -146,7 +139,7 @@ jobs:
146139
git config --local user.email "[email protected]"
147140
git config --local user.name "GitHub Action"
148141
git add docker-compose.yml
149-
git diff --staged --quiet || git commit -m "Update docker-compose.yml to use ${{ steps.changelog.outputs.current_tag }} images"
142+
git diff --staged --quiet || git commit -m "Update docker-compose.yml to use ${{ steps.extract_tag.outputs.tag_name }} images"
150143
git push origin HEAD:main
151144
env:
152145
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/manual-build.yml

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,9 @@ jobs:
6363
VERSION=${{ inputs.version }}
6464
IMAGE_NAME="${{ env.REGISTRY }}/${{ env.DOCKERHUB_USERNAME }}/${{ matrix.service.image }}"
6565
66-
# 生成标签
66+
# 只生成用户指定的版本标签
6767
TAGS="${IMAGE_NAME}:${VERSION}"
6868
69-
# 如果是语义化版本,添加额外标签
70-
if [[ $VERSION =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
71-
MAJOR_MINOR=$(echo $VERSION | sed 's/v\([0-9]*\.[0-9]*\)\.[0-9]*/v\1/')
72-
MAJOR=$(echo $VERSION | sed 's/v\([0-9]*\)\.[0-9]*\.[0-9]*/v\1/')
73-
TAGS="${TAGS},${IMAGE_NAME}:${MAJOR_MINOR},${IMAGE_NAME}:${MAJOR}"
74-
fi
75-
76-
# 添加latest标签(如果需要)
77-
TAGS="${TAGS},${IMAGE_NAME}:latest"
78-
7969
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
8070
echo "Generated tags: ${TAGS}"
8171
@@ -94,12 +84,31 @@ jobs:
9484
needs: build-and-push
9585
runs-on: ubuntu-latest
9686
if: inputs.create_release
87+
permissions:
88+
contents: write
89+
discussions: write
9790

9891
steps:
9992
- name: Checkout code
10093
uses: actions/checkout@v4
10194
with:
10295
fetch-depth: 0
96+
token: ${{ secrets.GITHUB_TOKEN }}
97+
98+
- name: Check if tag exists
99+
id: check_tag
100+
run: |
101+
VERSION=${{ inputs.version }}
102+
if git rev-parse "refs/tags/$VERSION" >/dev/null 2>&1; then
103+
echo "Tag $VERSION already exists locally"
104+
git tag -d $VERSION || true
105+
fi
106+
107+
# Check if tag exists on remote
108+
if git ls-remote --tags origin | grep -q "refs/tags/$VERSION"; then
109+
echo "Tag $VERSION exists on remote, deleting it"
110+
git push origin --delete $VERSION || true
111+
fi
103112
104113
- name: Create tag
105114
run: |
@@ -133,6 +142,17 @@ jobs:
133142
echo "This is the initial release of LMeterX." >> CHANGELOG.md
134143
fi
135144
145+
- name: Delete existing release if exists
146+
run: |
147+
VERSION=${{ inputs.version }}
148+
# Check if release exists and delete it
149+
if gh release view $VERSION >/dev/null 2>&1; then
150+
echo "Release $VERSION exists, deleting it"
151+
gh release delete $VERSION --yes
152+
fi
153+
env:
154+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
155+
136156
- name: Create GitHub Release
137157
uses: softprops/action-gh-release@v1
138158
with:
@@ -142,6 +162,7 @@ jobs:
142162
draft: false
143163
prerelease: false
144164
generate_release_notes: true
165+
fail_on_unmatched_files: false
145166
env:
146167
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
147168

docs/images/tech-arch-cn.png

97.1 KB
Loading

docs/images/tech-arch.png

-2.19 MB
Loading
2.29 MB
Loading

0 commit comments

Comments
 (0)