updated sync_github_actions_workflows_to_adjacent_repos.sh

master
Hari Sekhon 3 days ago
parent 19b90aaed3
commit 76489562f8

@ -17,12 +17,27 @@ set -euo pipefail
[ -n "${DEBUG:-}" ] && set -x [ -n "${DEBUG:-}" ] && set -x
srcdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" srcdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$srcdir" # shellcheck disable=SC1090,SC1091
. "$srcdir/lib/utils.sh"
if [ $# -eq 0 ];then # shellcheck disable=SC2034,SC2154
echo "usage: <file1> <file2> ..." usage_description="
exit 1 Syncs GitHub Actions CI/CD workflows in this repo to all adjacent repo checkouts listed in ../setup/repos.txt
fi
Quick way of updating GitHub Actions CI/CD workflows between repos
and then using ../git/github_foreach_repo.sh to commit them
"
# used by usage() in lib/utils.sh
# shellcheck disable=SC2034
usage_args="[<workflow_yaml_1> <workflow_yaml_2> ...]"
help_usage "$@"
cd "$srcdir/../.github/workflows"
tmpfile="$(mktemp)"
sync_file(){ sync_file(){
local filename="$1" local filename="$1"
@ -32,26 +47,43 @@ sync_file(){
dir="$repo" dir="$repo"
fi fi
dir="$(tr '[:upper:]' '[:lower:]' <<< "$dir")" dir="$(tr '[:upper:]' '[:lower:]' <<< "$dir")"
if ! [ -d "../../$dir" ]; then if ! [ -d "$srcdir/../../$dir" ]; then
echo "WARNING: repo dir $dir not found, skipping..." timestamp "WARNING: repo dir $srcdir/../../$dir not found, skipping..."
return 0 return 0
fi fi
target="../../$dir/.github/$filename" target="$srcdir/../../$dir/.github/workflows/$filename"
targetdir="${target%/*}" targetdir="${target%/*}"
mkdir -p -v "$targetdir" mkdir -p -v "$targetdir"
if [ -f "$filename" ]; then if [ -f "$target" ]; then
echo "syncing $filename -> $target" perl -p -e "s/(DevOps-)?Bash-tools/$repo/i" "$filename" > "$tmpfile"
perl -p -e "s/(DevOps-)?Bash-tools/$repo/i" "$filename" > "$target" tmpfile_checksum="$(cksum "$tmpfile" | awk '{print $1}')"
target_checksum="$(cksum "$target" | awk '{print $1}')"
if [ "$tmpfile_checksum" = "$target_checksum" ]; then
log "Skipping GitHub Actions CI/CD Config Sync for file due to same checksum: $filename"
return 0
fi
if ! QUIET=1 "$srcdir/../bin/diff_line_threshold.sh" "$filename" "$target"; then
timestamp "Skipping GitHub Actions CI/CD Config Sync for file due to large diff: $filename"
return 0
fi
timestamp "Syncing $filename -> $target"
mv "$tmpfile" "$target"
else else
echo "file not found: $filename. Skipping..." log "File not found: $target. Skipping..."
fi fi
} }
sed 's/#.*//; s/:/ /' ../setup/repos.txt | sed 's/#.*//; s/:/ /' "$srcdir/../setup/repos.txt" |
grep -v -e bash-tools \ grep -v -e bash-tools \
-e '^[[:space:]]*$' | -e '^[[:space:]]*$' |
while read -r repo dir; do while read -r repo dir; do
for filename in "$@"; do if [ $# -gt 1 ]; then
sync_file "$filename" "$repo" "$dir" for filename in "$@"; do
done sync_file "$filename" "$repo" "$dir"
done
else
for filename in *.yaml; do
sync_file "$filename" "$repo" "$dir"
done
fi
done done

Loading…
Cancel
Save