-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rebuild axosyslog image with auto patch version increment #411
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -138,6 +138,8 @@ jobs: | |
merge-and-push: | ||
runs-on: ubuntu-latest | ||
needs: [prepare, image-build] | ||
outputs: | ||
tags: ${{ steps.docker-metadata-tags.outputs.tags }} | ||
steps: | ||
- name: Download digests | ||
uses: actions/download-artifact@v4 | ||
|
@@ -151,11 +153,30 @@ jobs: | |
|
||
- name: Extract metadata (AxoSyslog version) for Docker | ||
id: docker-metadata-tags | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ${{ needs.prepare.outputs.image-name }} | ||
tags: type=match,pattern=axosyslog-([0-9].*),group=1 | ||
sep-tags: ',' | ||
run: | | ||
previous_docker_tag=$(skopeo inspect docker://ghcr.io/axoflow/axosyslog:latest | jq '.RepoTags' | sed 's/ \|"\|,//g' | grep "^[0-9]*.[0-9]*.[0-9]*$\|^[0-9]*.[0-9]*.[0-9]*-[0-9]*$" | tail -n 1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a problem with the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very verbose, but it works. Let me know what you think: - name: "Query previous container image version"
uses: actions/github-script@v7
with:
script: |
const versionPattern = /^[0-9]+\.[0-9]+\.[0-9]+-[0-9]+$/;
const package_name = "axosyslog", org = "axoflow";
const allPackageVersions = await github.paginate(
github.rest.packages.getAllPackageVersionsForPackageOwnedByOrg,
{ package_type: "container", package_name, org }
);
const latest = allPackageVersions.find(p =>
p.metadata.container?.tags.includes("latest")
);
const { data: { metadata: { container: { tags } } } } =
await github.rest.packages.getPackageVersionForOrganization({
package_type: "container", package_name, org, package_version_id: latest.id
});
previousDockerTag = tags.find(t => versionPattern.test(t));
core.exportVariable('previous_docker_tag', previousDockerTag); After this step, you will get |
||
previous_docker_tag_short=$(echo $previous_docker_tag | cut -d"-" -f1) | ||
previous_docker_tag_patch=$(echo $previous_docker_tag | cut -d"-" -f2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: this is the rebuild number, not the patch part. |
||
current_git_tag=$(echo ${{ github.ref }} | cut -d"-" -f2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to make sure everything below this line is skipped when github.ref is not a version tag. |
||
function version { echo "$@" | awk -F. '{ printf("%d%03d%03d\n", $1,$2,$3); }'; } | ||
if [ $(version $current_git_tag) -gt $(version $previous_docker_tag_short) ]; then | ||
echo "Given git tag version is greater than previous docker tag version: $current_git_tag > $previous_docker_tag_short" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that we have debugged everything, we could replace this echo with something like this:
|
||
next_docker_tag_with_patch=$current_git_tag-1 | ||
next_docker_tag=$current_git_tag | ||
echo "Next docker version tag: $next_docker_tag_with_patch" | ||
elif [ $(version $current_git_tag) -eq $(version $previous_docker_tag_short) ]; then | ||
echo "Given git tag version is equals with previous docker tag version: $current_git_tag == $previous_docker_tag_short" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
next_docker_tag_patch=$((previous_docker_tag_patch+1)) | ||
next_docker_tag_with_patch=$previous_docker_tag_short-$next_docker_tag_patch | ||
next_docker_tag=$previous_docker_tag_short | ||
echo "Next docker version tag: $next_docker_tag_with_patch" | ||
else | ||
echo "Given git tag version is less than previous docker tag version: $current_git_tag < $previous_docker_tag_short" | ||
echo "This is not allowed. Please provide a valid git tag version." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
exit 1 | ||
fi | ||
TAGS="ghcr.io/axoflow/axosyslog:$next_docker_tag,ghcr.io/axoflow/axosyslog:$next_docker_tag_with_patch,ghcr.io/axoflow/axosyslog:latest" | ||
echo "tags=$TAGS" >> $GITHUB_OUTPUT | ||
|
||
- name: Compose Docker image tags | ||
id: tags | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jq --raw-output '.RepoTags.[]'
produces the desired output, so the sed can be removed.