From 0745dfaba4baed690f42293328c8a5744e122c98 Mon Sep 17 00:00:00 2001 From: Steven Oderayi Date: Mon, 26 Feb 2024 16:06:37 +0100 Subject: [PATCH 1/2] feat: update scripts, package spec and code comments --- .github/workflows/manifests/package.yaml | 14 ++++++ .github/workflows/scripts/patch-manifests.sh | 45 ++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 .github/workflows/manifests/package.yaml create mode 100755 .github/workflows/scripts/patch-manifests.sh diff --git a/.github/workflows/manifests/package.yaml b/.github/workflows/manifests/package.yaml new file mode 100644 index 000000000..56d212b8f --- /dev/null +++ b/.github/workflows/manifests/package.yaml @@ -0,0 +1,14 @@ +# Package specification file for the Mojaloop project +# +# Format: +# : +# : +# +# +# Example: +# acccount-lookup-service: <= 15.0.0 +# central-ledger: ~ 15.2.0 +# +# Package versiions specified here will be applied to the entire update manifest. +# To apply, run the `patch-manifest.sh` script in the `.github/workflow/scripts` directory like so: +# $ patch-manifests.sh package.yaml .github/workflow/manifests/first-pass \ No newline at end of file diff --git a/.github/workflows/scripts/patch-manifests.sh b/.github/workflows/scripts/patch-manifests.sh new file mode 100755 index 000000000..fa8bdc876 --- /dev/null +++ b/.github/workflows/scripts/patch-manifests.sh @@ -0,0 +1,45 @@ +# Applies package versions override to manifests using versions from the package.yaml file +# Usage: patch-manifests.sh +# Example: patch-manifests.sh ../manifests/package.yaml ../manifests + +set -e + +# Read and parse package.yaml file and store as assiciative array +declare -A package +while IFS=': ' read -r key value; do + if [ -n "$key" ] && [ -n "$value" ]; then + package[$key]=$value + fi +done < $1 + +# Exit if there are no items in package array +if [ ${#package[@]} -eq 0 ]; then + echo "No package specifications in package.yaml file" + exit 0 +fi + +# Iterate over all the files in the directory +for file in $2/*; do + # Check if the file is a yaml file and filename is not package.yaml + if [ ${file: -5} == ".yaml" ] && [ ${file: -13} != "/package.yaml" ]; then + # Iterate over all the keys in the package.yaml file + for key in "${!package[@]}"; do + version=$(echo ${package[$key]} | tr -d '[:space:]') + yq eval -i '(.sources[] | select(.spec.repository == "'$key'" or .spec.name == "'$key'") | .spec) += { "versionfilter": { "kind": "semver", "pattern": "'$version'" } }' $file + done + fi +done + +# TODO: +# # Iterate over all the files in the directory and remove the .versionfilter node for any source that is not in the package.yaml file +# for file in $2/*; do +# # Check if the file is a yaml file and filename is not package.yaml +# if [ ${file: -5} == ".yaml" ] && [ ${file: -13} != "/package.yaml" ]; then +# # Iterate over all the keys in the package.yaml file +# for key in "${!package[@]}"; do +# yq eval -i 'del(.sources[] | select(.spec.repository != "'$key'" and .spec.name != "'$key'") | .versionfilter)' $file +# done +# fi +# done + + From f3881b551fd444f5e091884c516631ed6ee815fd Mon Sep 17 00:00:00 2001 From: Steven Oderayi Date: Mon, 26 Feb 2024 16:11:18 +0100 Subject: [PATCH 2/2] doc: update comments --- .github/workflows/manifests/package.yaml | 4 ++-- .github/workflows/scripts/patch-manifests.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/manifests/package.yaml b/.github/workflows/manifests/package.yaml index 56d212b8f..92f0f063c 100644 --- a/.github/workflows/manifests/package.yaml +++ b/.github/workflows/manifests/package.yaml @@ -10,5 +10,5 @@ # central-ledger: ~ 15.2.0 # # Package versiions specified here will be applied to the entire update manifest. -# To apply, run the `patch-manifest.sh` script in the `.github/workflow/scripts` directory like so: -# $ patch-manifests.sh package.yaml .github/workflow/manifests/first-pass \ No newline at end of file +# To apply, run the `patch-manifest.sh` script in the `.github/workflows/scripts` directory like so: +# $ patch-manifests.sh .github/workflows/manifests/package.yaml .github/workflows/manifests/first-pass \ No newline at end of file diff --git a/.github/workflows/scripts/patch-manifests.sh b/.github/workflows/scripts/patch-manifests.sh index fa8bdc876..3ffd0eb34 100755 --- a/.github/workflows/scripts/patch-manifests.sh +++ b/.github/workflows/scripts/patch-manifests.sh @@ -1,6 +1,6 @@ # Applies package versions override to manifests using versions from the package.yaml file # Usage: patch-manifests.sh -# Example: patch-manifests.sh ../manifests/package.yaml ../manifests +# Example: patch-manifests.sh patch-manifests.sh .github/workflows/manifests/package.yaml .github/workflows/manifests/first-pass set -e