From fe16df8a6c0a188b3621061932801587e2999383 Mon Sep 17 00:00:00 2001
From: Thomas Woerner <twoerner@redhat.com>
Date: Wed, 20 Mar 2024 11:07:56 +0100
Subject: [PATCH] utils/build-galaxy-release.sh: Enable offline generation for
rpm
Two new options have been added to enable the offline build within rpm:
-o <A.B.C> Build offline without using git, using version A.B.C
Also enables -a
-p <path> Installation the generated collection in the path, the
ansible_collections sub directory will be created and will
contain the collection: ansible_collections/<namespace>/<name>
Also enables -i
The usage text has been fixed also for specifying namespace and name.
The collection variable has been renamed to name.
Example usage:
utils/build-galaxy-release.sh -o 1.12.1 \
-p %{buildroot}%{_datadir}/ansible/collections \
freeipa ansible_freeipa
---
utils/build-galaxy-release.sh | 57 ++++++++++++++++++++++++-----------
1 file changed, 40 insertions(+), 17 deletions(-)
diff --git a/utils/build-galaxy-release.sh b/utils/build-galaxy-release.sh
index e427013e..3c9c609a 100755
--- a/utils/build-galaxy-release.sh
+++ b/utils/build-galaxy-release.sh
@@ -8,18 +8,24 @@ pwd=$(pwd)
usage() {
cat <<EOF
-Usage: $prog [options] [namespace] [collection]
+Usage: $prog [options] [<namespace> <name>]
Build Anible Collection for ansible-freeipa.
-The namespace defaults to freeipa an collection defaults to ansible_freeipa
-if namespace and collection are not given. Namespace and collection can not
-be givedn without the other one.
+The namespace defaults to freeipa an name defaults to ansible_freeipa,
+if namespace and name are not given. Namespace and name need to be set
+together.
Options:
-a Add all files, no only files known to git repo
-k Keep build directory
-i Install the generated collection
+ -o <A.B.C> Build offline without using git, using version A.B.C
+ Also enables -a
+ -p <path> Installation the generated collection in the path, the
+ ansible_collections sub directory will be created and will
+ contain the collection: ansible_collections/<namespace>/<name>
+ Also enables -i
-h Print this help
EOF
@@ -28,7 +34,10 @@ EOF
all=0
keep=0
install=0
-while getopts "ahki" arg; do
+path=
+offline=0
+galaxy_version=
+while getopts "ahkio:p:" arg; do
case $arg in
a)
all=1
@@ -43,6 +52,15 @@ while getopts "ahki" arg; do
i)
install=1
;;
+ o)
+ galaxy_version=$OPTARG
+ offline=1
+ all=1
+ ;;
+ p)
+ path=$OPTARG
+ install=1
+ ;;
\?)
echo
usage
@@ -57,25 +75,26 @@ if [ $# != 0 ] && [ $# != 2 ]; then
exit 1
fi
namespace="${1-freeipa}"
-collection="${2-ansible_freeipa}"
+name="${2-ansible_freeipa}"
if [ -z "$namespace" ]; then
echo "Namespace might not be empty"
exit 1
fi
-if [ -z "$collection" ]; then
- echo "Collection might not be empty"
+if [ -z "$name" ]; then
+ echo "Name might not be empty"
exit 1
fi
-collection_prefix="${namespace}.${collection}"
+collection_prefix="${namespace}.${name}"
-galaxy_version=$(git describe --tags 2>/dev/null | sed -e "s/^v//")
+[ -z "$galaxy_version" ] && \
+ galaxy_version=$(git describe --tags 2>/dev/null | sed -e "s/^v//")
if [ -z "$galaxy_version" ]; then
echo "Version could not be detected"
exit 1
fi
-echo "Building collection: ${namespace}-${collection}-${galaxy_version}"
+echo "Building collection: ${namespace}-${name}-${galaxy_version}"
GALAXY_BUILD=".galaxy-build"
@@ -103,14 +122,18 @@ cd "$GALAXY_BUILD" || exit 1
sed -i -e "s/version: .*/version: \"$galaxy_version\"/" galaxy.yml
sed -i -e "s/namespace: .*/namespace: \"$namespace\"/" galaxy.yml
-sed -i -e "s/name: .*/name: \"$collection\"/" galaxy.yml
+sed -i -e "s/name: .*/name: \"$name\"/" galaxy.yml
find . -name "*~" -exec rm {} \;
-echo "Creating CHANGELOG.rst..."
-"$(dirname "$0")/changelog" --galaxy > CHANGELOG.rst
-echo -e "\033[ACreating CHANGELOG.rst... \033[32;1mDONE\033[0m"
+if [ $offline == 0 ]; then
+ echo "Creating CHANGELOG.rst..."
+ "$(dirname "$0")/changelog" --galaxy > CHANGELOG.rst
+ echo -e "\033[ACreating CHANGELOG.rst... \033[32;1mDONE\033[0m"
+else
+ echo "Empty changelog, offline generated." > CHANGELOG.rst
+fi
sed -i -e "s/ansible.module_utils.ansible_freeipa_module/ansible_collections.${collection_prefix}.plugins.module_utils.ansible_freeipa_module/" plugins/modules/*.py
@@ -198,6 +221,6 @@ else
fi
if [ $install == 1 ]; then
- echo "Installing collection ${namespace}-${collection}-${galaxy_version}.tar.gz ..."
- ansible-galaxy collection install "${namespace}-${collection}-${galaxy_version}.tar.gz" --force
+ echo "Installing collection ${namespace}-${name}-${galaxy_version}.tar.gz ..."
+ ansible-galaxy collection install ${path:+"-p$path"} "${namespace}-${name}-${galaxy_version}.tar.gz" --force ${offline/1/--offline}
fi
--
2.44.0
From 2804ec3f8391d03b7bc9a63996160df76ec2ca1c Mon Sep 17 00:00:00 2001
From: Thomas Woerner <twoerner@redhat.com>
Date: Tue, 26 Mar 2024 14:46:11 +0100
Subject: [PATCH] utils/build-galaxy-release.sh: Fix offline default value
The offline default value was 0, which resulted in 0 for
${offline/1/--offline}.
This broke the ansible-galaxy collection install call.
---
utils/build-galaxy-release.sh | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/utils/build-galaxy-release.sh b/utils/build-galaxy-release.sh
index 3c9c609..a1681e0 100755
--- a/utils/build-galaxy-release.sh
+++ b/utils/build-galaxy-release.sh
@@ -35,7 +35,7 @@ all=0
keep=0
install=0
path=
-offline=0
+offline=
galaxy_version=
while getopts "ahkio:p:" arg; do
case $arg in
@@ -127,7 +127,7 @@ sed -i -e "s/name: .*/name: \"$name\"/" galaxy.yml
find . -name "*~" -exec rm {} \;
-if [ $offline == 0 ]; then
+if [ $offline != 1 ]; then
echo "Creating CHANGELOG.rst..."
"$(dirname "$0")/changelog" --galaxy > CHANGELOG.rst
echo -e "\033[ACreating CHANGELOG.rst... \033[32;1mDONE\033[0m"
--
2.44.0