22
22
steps :
23
23
- name : Checkout code
24
24
uses : actions/checkout@v4
25
+ with :
26
+ fetch-depth : 0
25
27
26
28
- name : Set up QEMU
27
29
uses : docker/setup-qemu-action@v3
@@ -41,13 +43,60 @@ jobs:
41
43
VERSION=$(node -p "require('./package.json').version")
42
44
echo "version=$VERSION" >> $GITHUB_OUTPUT
43
45
46
+ - name : Determine versioning strategy
47
+ id : versioning
48
+ run : |
49
+ BASE_VERSION="v${{ steps.package-version.outputs.version }}"
50
+
51
+ # Check if tag already exists
52
+ if git rev-parse "$BASE_VERSION" >/dev/null 2>&1; then
53
+ # Find the highest build number for this version
54
+ BUILD_PATTERN="${BASE_VERSION}-"
55
+ HIGHEST_BUILD=0
56
+
57
+ for tag in $(git tag -l "${BUILD_PATTERN}*"); do
58
+ # Extract build number from tag
59
+ BUILD_NUM=$(echo $tag | sed "s|${BUILD_PATTERN}||")
60
+ if [[ "$BUILD_NUM" =~ ^[0-9]+$ ]] && [ $BUILD_NUM -gt $HIGHEST_BUILD ]; then
61
+ HIGHEST_BUILD=$BUILD_NUM
62
+ fi
63
+ done
64
+
65
+ # Increment for the new build
66
+ NEW_BUILD=$((HIGHEST_BUILD + 1))
67
+ VERSION="${BASE_VERSION}-${NEW_BUILD}"
68
+ echo "New build for existing version: $VERSION"
69
+ else
70
+ VERSION="$BASE_VERSION"
71
+ echo "New version: $VERSION"
72
+ fi
73
+
74
+ echo "full_version=$VERSION" >> $GITHUB_OUTPUT
75
+ echo "is_new_base_version=$([[ "$VERSION" == "$BASE_VERSION" ]] && echo "true" || echo "false")" >> $GITHUB_OUTPUT
76
+
44
77
- name : Login to GitHub Container Registry
45
78
uses : docker/login-action@v3
46
79
with :
47
80
registry : ghcr.io
48
81
username : ${{ github.repository_owner }}
49
82
password : ${{ secrets.GITHUB_TOKEN }}
50
83
84
+ - name : Get previous tag
85
+ id : previoustag
86
+ uses : actions/github-script@v6
87
+ with :
88
+ script : |
89
+ const { data: tags } = await github.rest.repos.listTags({
90
+ owner: context.repo.owner,
91
+ repo: context.repo.repo,
92
+ per_page: 2
93
+ });
94
+ if (tags.length > 1) {
95
+ return tags[1].name;
96
+ }
97
+ return '';
98
+ result-encoding : string
99
+
51
100
- name : Build and push
52
101
uses : docker/build-push-action@v5
53
102
with :
@@ -56,29 +105,37 @@ jobs:
56
105
push : true
57
106
tags : |
58
107
joanroig/admincraft-websocket:latest
59
- joanroig/admincraft-websocket:${{ steps.package-version .outputs.version }}
108
+ joanroig/admincraft-websocket:${{ steps.versioning .outputs.full_version }}
60
109
ghcr.io/${{ github.repository_owner }}/admincraft-websocket:latest
61
- ghcr.io/${{ github.repository_owner }}/admincraft-websocket:${{ steps.package-version .outputs.version }}
110
+ ghcr.io/${{ github.repository_owner }}/admincraft-websocket:${{ steps.versioning .outputs.full_version }}
62
111
labels : |
63
112
org.opencontainers.image.source=https://github.com/${{ github.repository_owner }}/admincraft-websocket
64
113
org.opencontainers.image.description=Admincraft WebSocket server
65
- org.opencontainers.image.version=${{ steps.package-version.outputs.version }}
114
+ org.opencontainers.image.version=${{ steps.versioning.outputs.full_version }}
115
+
116
+ - name : Create Git Tag
117
+ run : |
118
+ git config user.name github-actions
119
+ git config user.email [email protected]
120
+ git tag ${{ steps.versioning.outputs.full_version }}
121
+ git push origin ${{ steps.versioning.outputs.full_version }}
122
+ echo "Created and pushed tag ${{ steps.versioning.outputs.full_version }}"
66
123
67
124
- name : Create GitHub Release
68
125
id : create_release
69
126
uses : actions/create-release@v1
70
127
env :
71
128
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
72
129
with :
73
- tag_name : v ${{ steps.package-version .outputs.version }}
74
- release_name : Release v ${{ steps.package-version .outputs.version }}
130
+ tag_name : ${{ steps.versioning .outputs.full_version }}
131
+ release_name : Release ${{ steps.versioning .outputs.full_version }}
75
132
draft : false
76
- prerelease : false
133
+ prerelease : ${{ steps.versioning.outputs.is_new_base_version == ' false' }}
77
134
body : |
78
- Release v ${{ steps.package-version .outputs.version }}
135
+ Release ${{ steps.versioning .outputs.full_version }}
79
136
80
137
Docker images available at:
81
- - Docker Hub: [joanroig/admincraft-websocket:${{ steps.package-version .outputs.version }}](https://hub.docker.com/r/joanroig/admincraft-websocket/tags?name=${{ steps.package-version .outputs.version }})
82
- - GitHub Packages: [ghcr.io/${{ github.repository_owner }}/admincraft-websocket:${{ steps.package-version .outputs.version }}](https://github.com/${{ github.repository_owner }}/admincraft-websocket/pkgs/container/admincraft-websocket)
138
+ - Docker Hub: [joanroig/admincraft-websocket:${{ steps.versioning .outputs.full_version }}](https://hub.docker.com/r/joanroig/admincraft-websocket/tags?name=${{ steps.versioning .outputs.full_version }})
139
+ - GitHub Packages: [ghcr.io/${{ github.repository_owner }}/admincraft-websocket:${{ steps.versioning .outputs.full_version }}](https://github.com/${{ github.repository_owner }}/admincraft-websocket/pkgs/container/admincraft-websocket)
83
140
84
- Full Changelog: https://github.com/${{ github.repository_owner }}/admincraft-websocket/commits/v ${{ steps.package-version .outputs.version }}
141
+ Full Changelog: https://github.com/${{ github.repository_owner }}/admincraft-websocket/compare/ ${{ steps.previoustag .outputs.result }}...${{ steps.versioning.outputs.full_version }}
0 commit comments