1
- name : Build and Push Docker Image
1
+ name : Build, Push to GHCR, and Create Release
2
2
3
3
on :
4
4
push :
@@ -11,19 +11,23 @@ jobs:
11
11
runs-on : ubuntu-latest
12
12
13
13
steps :
14
+ # Step 1: Checkout the code
14
15
- name : Checkout Code
15
16
uses : actions/checkout@v3
16
17
18
+ # Step 2: Set up Docker Buildx
17
19
- name : Set up Docker Buildx
18
20
uses : docker/setup-buildx-action@v2
19
21
20
- - name : Log in to GitHub Container Registry
22
+ # Step 3: Log in to GitHub Container Registry (GHCR)
23
+ - name : Log in to GHCR
21
24
uses : docker/login-action@v2
22
25
with :
23
26
registry : ghcr.io
24
27
username : ${{ github.actor }}
25
28
password : ${{ secrets.GHCR_PAT }}
26
29
30
+ # Step 4: Build and push Docker image
27
31
- name : Build and Push Docker Image
28
32
uses : docker/build-push-action@v4
29
33
with :
33
37
ghcr.io/${{ github.repository_owner }}/gomarks:${{ github.ref_name }}
34
38
ghcr.io/${{ github.repository_owner }}/gomarks:latest
35
39
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