Skip to content

Commit

Permalink
Tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
stagnation authored and moroten committed Nov 19, 2023
1 parent 9eb0304 commit 5ffcc77
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions tools/update-container-image-versions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ set -eu -o pipefail

get_image_version() {
repo="$1"; shift
grep -E "github\.com/buildbarn/${repo}" go.mod \
grep -E "github\.com/buildbarn/$repo" go.mod \
| sed 's#.* v0.0.0-\([0-9]\{8\}\)\([0-9]\{6\}\)-\([0-9a-f]\{7\}\)[0-9a-f]\+#\1T\2Z-\3#'
}

get_full_git_commit_hash() {
repo="$1"; shift
# Reuse the same sed expression as in get_image_version.
short_commit_hash=$(grep -E "github\.com/buildbarn/${repo}" go.mod \
short_commit_hash=$(grep -E "github\.com/buildbarn/$repo" go.mod \
| sed 's#.* v0.0.0-\([0-9]\{8\}\)\([0-9]\{6\}\)-\([0-9a-f]\+\)#\3#')
# Let GitHub resolve the full commit hash.
curl "https://github.com/buildbarn/$repo/commit/$short_commit_hash" \
curl -s "https://github.com/buildbarn/$repo/commit/$short_commit_hash" \
| grep '<meta property="og:url" content="' \
| sed 's#.*<meta property="og:url" content="/buildbarn/'"$repo"'/commit/\([0-9a-f]*\)" />.*#\1#'
}
Expand All @@ -41,15 +41,16 @@ update_image_version() {
image_version=$(get_image_version "$repo")
timestamp=$(echo "$image_version" | sed 's#\([0-9]\{4\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)T\([0-9]\{2\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)Z.*#\1-\2-\3 \4:\5:\6#')
commit_hash=$(get_full_git_commit_hash "$repo")
checks_url="https://github.com/buildbarn/$repo/commit/$commit_hash/checks"

# Replace image version.
sed -i "s#\(ghcr\.io/buildbarn/${image_name}:\)[0-9tzTZ]*-[0-9a-f]*#\1${image_version}#g" \
sed -i "s#\(ghcr\.io/buildbarn/$image_name:\)[0-9tzTZ]*-[0-9a-f]*#\1$image_version#g" \
README.md docker-compose/docker-compose.yml kubernetes/*.yaml

# Replace timestamp and CI Build link.
sed -i \
-e "s#^\(| ${image_name} .*| \)\([^|]* UTC |\)#\1${timestamp} UTC |#" \
-e "s#| [^|]*/buildbarn/${repo}/commit/[0-9a-f]*/checks#| [\`${commit_hash}\`](https://github.com/buildbarn/${repo}/commit/${commit_hash}/checks#" \
-e "s#^\(| $image_name .*| \)\([^|]* UTC |\)#\1$timestamp UTC |#" \
-e "s#| [^|]*/buildbarn/$repo/commit/[0-9a-f]*/checks#| [\`$commit_hash\`]($checks_url#" \
README.md
}

Expand Down

0 comments on commit 5ffcc77

Please sign in to comment.