Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/scripts/bump_patch_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
set -euo pipefail

# Bump the patch version of a given version.txt
# Usage: bump_patch_version.sh <version.txt filepath>

version_file="${1:-}"

if [[ -z "$version_file" ]]; then
echo "Usage: $0 <path/to/version.txt>" >&2
exit 1
fi

if [[ ! -f "$version_file" ]]; then
echo "Error: file does not exist: $version_file" >&2
exit 1
fi

version=$(<"$version_file")


if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: $version_file must contain exactly one version in MAJOR.MINOR.PATCH format" >&2
exit 1
fi

IFS='.' read -r major minor patch <<< "$version"

printf '%s.%s.%s\n' "$major" "$minor" "$((patch + 1))" > "$version_file"
27 changes: 27 additions & 0 deletions .github/scripts/detect_changed_images.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash
set -euo pipefail

base="$1"
head="$2"

changed=$(git diff --name-only "$base...$head")

find . -name Dockerfile -not -path './.git/*' -printf '%h\n' |
while read -r dir; do
dir=${dir#./}

# Only consider directories containing both Dockerfile and version.txt
# as these directories will be the name of the image that has changed
[[ -f "$dir/Dockerfile" && -f "$dir/version.txt" ]] || continue

# Check whether anything in the image directory changed
if grep -q "^$dir/" <<< "$changed"; then
# version.txt must also have changed
if ! grep -q "^$dir/version.txt$" <<< "$changed"; then
echo "ERROR: $dir has changed, but version.txt was not changed - bump the version!" >&2
exit 1
fi
echo "$dir"
fi
done |
sort -u
50 changes: 50 additions & 0 deletions .github/scripts/utils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env bash
set -euo pipefail

# Shared helpers. Sourced by the other scripts, not run directly.

# allows these scripts to be used by github runners
# if run locally will go back to stdout and summaries discarded
: "${GITHUB_OUTPUT:=/dev/stdout}"
: "${GITHUB_STEP_SUMMARY:=/dev/null}"

# Emit a step output (key=value).
output() { printf '%s=%s\n' "$1" "$2" >> "$GITHUB_OUTPUT"; }

# Append a line to the job summary.
summary() { printf '%s\n' "$*" >> "$GITHUB_STEP_SUMMARY"; }

# Logging. All to stderr.
info() { printf '%s\n' "$*" >&2; }
warn() { printf '::warning::%s\n' "$*" >&2; }
fail() { printf '::error::%s\n' "$*" >&2; exit 1; }

# The image name for a image_path is just its directory name.
get_image_name() { basename "$1"; }

# Assert that the named variables are set and non-empty.
require() {
local var
for var in "$@"; do
[ -n "${!var:-}" ] || fail "$var is not set"
done
}

# Read and validate a image_path's version.txt. Prints the version.
read_version() {
local image_path=$1 file version
file="$image_path/version.txt"
[ -f "$file" ] || fail "$file not found"
version=$(tr -d '[:space:]' < "$file")
[[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] \
|| fail "$file is '$version', expected MAJOR.MINOR.PATCH"
printf '%s' "$version"
}

# Locate a image_path's Dockerfile, at any depth. Prints the path.
find_dockerfile() {
local image_path=$1 dockerfile
dockerfile=$(find "$image_path" -name Dockerfile | head -n1)
[ -n "$dockerfile" ] || fail "no Dockerfile found under $image_path"
printf '%s' "$dockerfile"
}
20 changes: 0 additions & 20 deletions .github/workflows/bin/version_increment.sh

This file was deleted.

111 changes: 0 additions & 111 deletions .github/workflows/build_images.yaml

This file was deleted.

Loading
Loading