Skip to content

Commit 53148a0

Browse files
committed
auto tag
1 parent 3d56caf commit 53148a0

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

.github/workflows/docker-build.yml

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build and Push Docker Image
1+
name: Build, Push to GHCR, and Create Release
22

33
on:
44
push:
@@ -11,19 +11,23 @@ jobs:
1111
runs-on: ubuntu-latest
1212

1313
steps:
14+
# Step 1: Checkout the code
1415
- name: Checkout Code
1516
uses: actions/checkout@v3
1617

18+
# Step 2: Set up Docker Buildx
1719
- name: Set up Docker Buildx
1820
uses: docker/setup-buildx-action@v2
1921

20-
- name: Log in to GitHub Container Registry
22+
# Step 3: Log in to GitHub Container Registry (GHCR)
23+
- name: Log in to GHCR
2124
uses: docker/login-action@v2
2225
with:
2326
registry: ghcr.io
2427
username: ${{ github.actor }}
2528
password: ${{ secrets.GHCR_PAT }}
2629

30+
# Step 4: Build and push Docker image
2731
- name: Build and Push Docker Image
2832
uses: docker/build-push-action@v4
2933
with:
@@ -33,3 +37,39 @@ jobs:
3337
ghcr.io/${{ github.repository_owner }}/gomarks:${{ github.ref_name }}
3438
ghcr.io/${{ github.repository_owner }}/gomarks:latest
3539
40+
# Step 5: Generate the next tag (e.g., v0.1.3 -> v0.1.4)
41+
- name: Generate New Tag
42+
id: tag
43+
run: |
44+
# Get the latest tag
45+
latest_tag=$(git describe --tags $(git rev-list --tags --max-count=1))
46+
echo "Latest Tag: $latest_tag"
47+
48+
# Parse and increment the version (e.g., v0.1.3 -> v0.1.4)
49+
IFS='.' read -r major minor patch <<< "${latest_tag//v/}"
50+
new_tag="v$major.$minor.$((patch+1))"
51+
echo "New Tag: $new_tag"
52+
echo "tag=$new_tag" >> $GITHUB_ENV
53+
54+
# Step 6: Push the new tag to the repository
55+
- name: Push New Tag
56+
run: |
57+
git config user.name "GitHub Actions"
58+
git config user.email "[email protected]"
59+
git tag ${{ env.tag }}
60+
git push origin ${{ env.tag }}
61+
62+
# Step 7: Create a new GitHub release
63+
- name: Create GitHub Release
64+
uses: actions/create-release@v1
65+
with:
66+
tag_name: ${{ env.tag }}
67+
release_name: Release ${{ env.tag }}
68+
body: |
69+
This release includes the latest Docker image:
70+
- **Image:** ghcr.io/${{ github.repository_owner }}/gomarks:${{ env.tag }}
71+
- **Latest Tag:** ghcr.io/${{ github.repository_owner }}/gomarks:latest
72+
draft: false
73+
prerelease: false
74+
env:
75+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)