@@ -125,6 +125,8 @@ jobs:
125
125
merge-and-push :
126
126
runs-on : ubuntu-latest
127
127
needs : [prepare, image-build]
128
+ outputs :
129
+ tags : ${{ steps.docker-metadata-tags.outputs.tags }}
128
130
steps :
129
131
- name : Download digests
130
132
uses : actions/download-artifact@v4
@@ -136,13 +138,53 @@ jobs:
136
138
- name : Set up Docker Buildx
137
139
uses : docker/setup-buildx-action@v3
138
140
141
+ - name : " Query previous container image version"
142
+ uses : actions/github-script@v7
143
+ with :
144
+ script : |
145
+ const versionPattern = /^[0-9]+\.[0-9]+\.[0-9]+-[0-9]+$/;
146
+ const package_name = "axosyslog", org = "axoflow";
147
+ const allPackageVersions = await github.paginate(
148
+ github.rest.packages.getAllPackageVersionsForPackageOwnedByOrg,
149
+ { package_type: "container", package_name, org }
150
+ );
151
+
152
+ const latest = allPackageVersions.find(p =>
153
+ p.metadata.container?.tags.includes("latest")
154
+ );
155
+ const { data: { metadata: { container: { tags } } } } =
156
+ await github.rest.packages.getPackageVersionForOrganization({
157
+ package_type: "container", package_name, org, package_version_id: latest.id
158
+ });
159
+
160
+ previousDockerTag = tags.find(t => versionPattern.test(t));
161
+ core.exportVariable('previous_docker_tag', previousDockerTag);
162
+
139
163
- name : Extract metadata (AxoSyslog version) for Docker
140
164
id : docker-metadata-tags
141
- uses : docker/metadata-action@v5
142
- with :
143
- images : ${{ needs.prepare.outputs.image-name }}
144
- tags : type=match,pattern=axosyslog-([0-9].*),group=1
145
- sep-tags : ' ,'
165
+ run : |
166
+ previous_docker_tag_short=$(echo $previous_docker_tag | cut -d"-" -f1)
167
+ previous_docker_tag_rebuild_num=$(echo $previous_docker_tag | cut -d"-" -f2)
168
+ current_git_tag=$(echo ${{ github.ref }} | cut -d"-" -f2)
169
+ if [[ $current_git_tag =~ ^[0-9]+.[0-9]+.[0-9]+$ ]]; then
170
+ function version { echo "$@" | awk -F. '{ printf("%d%03d%03d\n", $1,$2,$3); }'; }
171
+ if [ $(version $current_git_tag) -gt $(version $previous_docker_tag_short) ]; then
172
+ next_docker_tag_with_patch=$current_git_tag-1
173
+ next_docker_tag=$current_git_tag
174
+ echo "New AxoSyslog release detected (new version: $next_docker_tag_with_patch, previous docker version: $previous_docker_tag)"
175
+ elif [ $(version $current_git_tag) -eq $(version $previous_docker_tag_short) ]; then
176
+ next_docker_tag_patch=$((previous_docker_tag_rebuild_num+1))
177
+ next_docker_tag_with_patch=$previous_docker_tag_short-$next_docker_tag_patch
178
+ next_docker_tag=$previous_docker_tag_short
179
+ echo "AxoSyslog image rebuild detected (new version: $next_docker_tag_with_patch, previous docker version: $previous_docker_tag)"
180
+ else
181
+ echo "Given git tag version is less than previous docker tag version: $current_git_tag < $previous_docker_tag_short"
182
+ echo "Rebuilding an older AxoSyslog version is not allowed. Please provide a valid git tag version."
183
+ exit 1
184
+ fi
185
+ TAGS="ghcr.io/axoflow/axosyslog:$next_docker_tag,ghcr.io/axoflow/axosyslog:$next_docker_tag_with_patch,ghcr.io/axoflow/axosyslog:latest"
186
+ echo "tags=$TAGS" >> $GITHUB_OUTPUT
187
+ fi
146
188
147
189
- name : Compose Docker image tags
148
190
id : tags
0 commit comments