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
srcdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$srcdir"
# shellcheck disable=SC1090,SC1091
. "$srcdir/lib/utils.sh"
if [ $# -eq 0 ];then
echo "usage: <file1> <file2> ..."
exit 1
fi
# shellcheck disable=SC2034,SC2154
usage_description="
Syncs GitHub Actions CI/CD workflows in this repo to all adjacent repo checkouts listed in ../setup/repos.txt
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(){
local filename="$1"
@ -32,26 +47,43 @@ sync_file(){
dir="$repo"
fi
dir="$(tr '[:upper:]' '[:lower:]' <<< "$dir")"
if ! [ -d "../../$dir" ]; then
echo "WARNING: repo dir $dir not found, skipping..."
if ! [ -d "$srcdir/../../$dir" ]; then
timestamp "WARNING: repo dir $srcdir/../../$dir not found, skipping..."
return 0
fi
target="../../$dir/.github/$filename"
target="$srcdir/../../$dir/.github/workflows/$filename"
targetdir="${target%/*}"
mkdir -p -v "$targetdir"
if [ -f "$filename" ]; then
echo "syncing $filename -> $target"
perl -p -e "s/(DevOps-)?Bash-tools/$repo/i" "$filename" > "$target"
if [ -f "$target" ]; then
perl -p -e "s/(DevOps-)?Bash-tools/$repo/i" "$filename" > "$tmpfile"
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
echo "file not found: $filename. Skipping..."
log "File not found: $target. Skipping..."
fi
}
sed 's/#.*//; s/:/ /' ../setup/repos.txt |
sed 's/#.*//; s/:/ /' "$srcdir/../setup/repos.txt" |
grep -v -e bash-tools \
-e '^[[:space:]]*$' |
while read -r repo dir; do
for filename in "$@"; do
sync_file "$filename" "$repo" "$dir"
done
if [ $# -gt 1 ]; then
for filename in "$@"; do
sync_file "$filename" "$repo" "$dir"
done
else
for filename in *.yaml; do
sync_file "$filename" "$repo" "$dir"
done
fi
done

Loading…
Cancel
Save