Files
sorsfonalak/ci/changed-services.sh
T

24 lines
1.2 KiB
Bash
Raw Normal View History

#!/bin/sh
# Prints the services whose image has to be built for HEAD: those whose files
# changed since the last deployment (the newest v* release tag among HEAD's
# ancestors; the release step tags every deployment). Prints all of them when
# there is no such tag or the comparison fails, so a doubt builds everything.
# Needs the full history and the tags (git fetch --unshallow --tags).
#
# frontend services/frontend/
# backend, worker, forum their folder, the shared crates/, Cargo.toml, Cargo.lock
# horoscope-api the same, and scripts/fetch-deps.sh
set -u
ALL="horoscope-api backend worker forum frontend"
prev=$(git describe --tags --abbrev=0 --match 'v*' HEAD 2>/dev/null) || { echo "$ALL"; exit 0; }
files=$(git diff --name-only "$prev" HEAD) || { echo "$ALL"; exit 0; }
changed() { printf '%s\n' "$files" | grep -Eq "$1"; }
rust='^(crates/|Cargo\.toml$|Cargo\.lock$)'
out=""
changed "^services/horoscope-api/|^scripts/fetch-deps\.sh$|$rust" && out="$out horoscope-api"
for svc in backend worker forum; do
changed "^services/$svc/|$rust" && out="$out $svc"
done
changed '^services/frontend/' && out="$out frontend"
echo $out