Skip to content

Commit 3220ae0

Browse files
author
Andras Mitzki
committed
ci: update merge-and-push job in axosyslog-docker workflow
- after this change next docker tag will automatically calculated in a following way: - if actual git tag version is greater than previous docker tag example: current git tag: 4.10.0 last docker tag: 4.9.0-2 next docker tag: 4.10.0-1 - if actual git tag version is equals with previous docker tag example: current git tag: 4.9.0 last docker tag: 4.9.0-2 next docker tag: 4.9.0-3 - if actual git tag version is less than previous docker tag, than compare script will display a warning and will exit Signed-off-by: Andras Mitzki <andras.mitzki@axoflow.com>
1 parent b4aca29 commit 3220ae0

File tree

1 file changed

+47
-5
lines changed

1 file changed

+47
-5
lines changed

.github/workflows/axosyslog-docker.yml

+47-5
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ jobs:
138138
merge-and-push:
139139
runs-on: ubuntu-latest
140140
needs: [prepare, image-build]
141+
outputs:
142+
tags: ${{ steps.docker-metadata-tags.outputs.tags }}
141143
steps:
142144
- name: Download digests
143145
uses: actions/download-artifact@v4
@@ -149,13 +151,53 @@ jobs:
149151
- name: Set up Docker Buildx
150152
uses: docker/setup-buildx-action@v3
151153

154+
- name: "Query previous container image version"
155+
uses: actions/github-script@v7
156+
with:
157+
script: |
158+
const versionPattern = /^[0-9]+\.[0-9]+\.[0-9]+-[0-9]+$/;
159+
const package_name = "axosyslog", org = "axoflow";
160+
const allPackageVersions = await github.paginate(
161+
github.rest.packages.getAllPackageVersionsForPackageOwnedByOrg,
162+
{ package_type: "container", package_name, org }
163+
);
164+
165+
const latest = allPackageVersions.find(p =>
166+
p.metadata.container?.tags.includes("latest")
167+
);
168+
const { data: { metadata: { container: { tags } } } } =
169+
await github.rest.packages.getPackageVersionForOrganization({
170+
package_type: "container", package_name, org, package_version_id: latest.id
171+
});
172+
173+
previousDockerTag = tags.find(t => versionPattern.test(t));
174+
core.exportVariable('previous_docker_tag', previousDockerTag);
175+
152176
- name: Extract metadata (AxoSyslog version) for Docker
153177
id: docker-metadata-tags
154-
uses: docker/metadata-action@v5
155-
with:
156-
images: ${{ needs.prepare.outputs.image-name }}
157-
tags: type=match,pattern=axosyslog-([0-9].*),group=1
158-
sep-tags: ','
178+
run: |
179+
previous_docker_tag_short=$(echo $previous_docker_tag | cut -d"-" -f1)
180+
previous_docker_tag_rebuild_num=$(echo $previous_docker_tag | cut -d"-" -f2)
181+
current_git_tag=$(echo ${{ github.ref }} | cut -d"-" -f2)
182+
if [[ $current_git_tag =~ ^[0-9]+.[0-9]+.[0-9]+$ ]]; then
183+
function version { echo "$@" | awk -F. '{ printf("%d%03d%03d\n", $1,$2,$3); }'; }
184+
if [ $(version $current_git_tag) -gt $(version $previous_docker_tag_short) ]; then
185+
next_docker_tag_with_patch=$current_git_tag-1
186+
next_docker_tag=$current_git_tag
187+
echo "New AxoSyslog release detected (new version: $next_docker_tag_with_patch, previous docker version: $previous_docker_tag)"
188+
elif [ $(version $current_git_tag) -eq $(version $previous_docker_tag_short) ]; then
189+
next_docker_tag_patch=$((previous_docker_tag_rebuild_num+1))
190+
next_docker_tag_with_patch=$previous_docker_tag_short-$next_docker_tag_patch
191+
next_docker_tag=$previous_docker_tag_short
192+
echo "AxoSyslog image rebuild detected (new version: $next_docker_tag_with_patch, previous docker version: $previous_docker_tag)"
193+
else
194+
echo "Given git tag version is less than previous docker tag version: $current_git_tag < $previous_docker_tag_short"
195+
echo "Rebuilding an older AxoSyslog version is not allowed. Please provide a valid git tag version."
196+
exit 1
197+
fi
198+
TAGS="ghcr.io/axoflow/axosyslog:$next_docker_tag,ghcr.io/axoflow/axosyslog:$next_docker_tag_with_patch,ghcr.io/axoflow/axosyslog:latest"
199+
echo "tags=$TAGS" >> $GITHUB_OUTPUT
200+
fi
159201
160202
- name: Compose Docker image tags
161203
id: tags

0 commit comments

Comments
 (0)