Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci(mojaloop/#3738): implement package version override for release workflow #602

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
14 changes: 14 additions & 0 deletions .github/workflows/manifests/package.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Package specification file for the Mojaloop project
#
# Format:
# <package-name-1>: <version-range>
# <package-name-2>: <version-range>
#
#
# 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/workflows/scripts` directory like so:
# $ patch-manifests.sh .github/workflows/manifests/package.yaml .github/workflows/manifests/first-pass
45 changes: 45 additions & 0 deletions .github/workflows/scripts/patch-manifests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Applies package versions override to manifests using versions from the package.yaml file
# Usage: patch-manifests.sh <package.yaml> <manifests-dir>
# Example: patch-manifests.sh patch-manifests.sh .github/workflows/manifests/package.yaml .github/workflows/manifests/first-pass

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