diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index e758c32c..3ae1bf22 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -17,8 +17,8 @@ jobs: - name: Run ansible-lint run: | pip install "ansible-core>=2.16,<2.17" 'ansible-lint==6.22' - utils/build-galaxy-release.sh -ki - cd .galaxy-build + utils/build-collection.sh -ki rpm + cd .collection-build ansible-lint --profile production --exclude tests/integration/ --exclude tests/unit/ --parseable --nocolor yamllint: diff --git a/infra/azure/templates/run_tests.yml b/infra/azure/templates/run_tests.yml index ef5c4ff9..ab93015d 100644 --- a/infra/azure/templates/run_tests.yml +++ b/infra/azure/templates/run_tests.yml @@ -54,7 +54,7 @@ jobs: - script: | git fetch --unshallow - utils/build-galaxy-release.sh -i + utils/build-collection.sh -i rpm retryCountOnTaskFailure: 5 displayName: Build Galaxy release condition: ${{ parameters.test_galaxy }} diff --git a/tests/sanity/sanity.sh b/tests/sanity/sanity.sh index e269750d..05a36849 100644 --- a/tests/sanity/sanity.sh +++ b/tests/sanity/sanity.sh @@ -19,7 +19,7 @@ pip install galaxy_importer rm -f "$ANSIBLE_COLLECTION"-*.tar.gz rm -f importer_result.json -utils/build-galaxy-release.sh +utils/build-collection.sh rpm sed "s/LOCAL_IMAGE_DOCKER = True/LOCAL_IMAGE_DOCKER = ${use_docker}/" < tests/sanity/galaxy-importer.cfg > ${VENV}/galaxy-importer.cfg export GALAXY_IMPORTER_CONFIG=${VENV}/galaxy-importer.cfg diff --git a/utils/build-galaxy-release.sh b/utils/build-collection.sh similarity index 56% rename from utils/build-galaxy-release.sh rename to utils/build-collection.sh index 1704e551..0bd264ec 100755 --- a/utils/build-galaxy-release.sh +++ b/utils/build-collection.sh @@ -8,21 +8,28 @@ pwd=$(pwd) usage() { cat < ] +Usage: $prog [options] rpm|aah|galaxy Build Anible Collection for ansible-freeipa. -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. +The namespace and name are defined according to the argument: + + rpm freeipa.ansible_freeipa - General use and RPMs + galaxy freeipa.ansible_freeipa - Ansible Galaxy + aah redhat.rhel_idm - Ansible AutomationHub + +The generated file README-COLLECTION.md is set in galaxy.yml as the +documentation entry point for the collections generated with aah and galaxy +as Ansible AutomationHub and also Ansible Galaxy are not able to render the +documentation README files in the collection properly. Options: - -a Add all files, no only files known to git repo + -a Add all files, not only files known to git repo -k Keep build directory -i Install the generated collection -o Build offline without using git, using version A.B.C Also enables -a - -p Installation the generated collection in the path, the + -p Install the generated collection in the given path, the ansible_collections sub directory will be created and will contain the collection: ansible_collections// Also enables -i @@ -36,7 +43,9 @@ keep=0 install=0 path= offline= -galaxy_version= +version= +namespace="freeipa" +name="ansible_freeipa" while getopts "ahkio:p:" arg; do case $arg in a) @@ -53,7 +62,7 @@ while getopts "ahkio:p:" arg; do install=1 ;; o) - galaxy_version=$OPTARG + version=$OPTARG offline=1 all=1 ;; @@ -70,60 +79,97 @@ while getopts "ahkio:p:" arg; do done shift $((OPTIND-1)) -if [ $# != 0 ] && [ $# != 2 ]; then +if [ $# != 1 ]; then usage exit 1 fi -namespace="${1-freeipa}" -name="${2-ansible_freeipa}" -if [ -z "$namespace" ]; then - echo "Namespace might not be empty" - exit 1 -fi -if [ -z "$name" ]; then - echo "Name might not be empty" - exit 1 -fi + +collection="$1" +case "$collection" in + rpm|galaxy) + # namespace and name are already set + ;; + aah) + namespace="redhat" + name="rhel_idm" + ;; + *) + echo "Unknown collection '$collection'" + usage + exit 1 + ;; +esac collection_prefix="${namespace}.${name}" +collection_uname="${collection^^}" -[ -z "$galaxy_version" ] && \ - galaxy_version=$(git describe --tags 2>/dev/null | sed -e "s/^v//") +[ -z "$version" ] && \ + version=$(git describe --tags 2>/dev/null | sed -e "s/^v//") -if [ -z "$galaxy_version" ]; then +if [ -z "$version" ]; then echo "Version could not be detected" exit 1 fi -echo "Building collection: ${namespace}-${name}-${galaxy_version}" +echo "Building collection: ${namespace}-${name}-${version} for ${collection_uname}" -GALAXY_BUILD=".galaxy-build" +BUILD=".collection-build" -if [ -e "$GALAXY_BUILD" ]; then - echo "Removing existing $GALAXY_BUILD ..." - rm -rf "$GALAXY_BUILD" - echo -e "\033[ARemoving existing $GALAXY_BUILD ... \033[32;1mDONE\033[0m" +if [ -e "$BUILD" ]; then + echo "Removing existing $BUILD ..." + rm -rf "$BUILD" + echo -e "\033[ARemoving existing $BUILD ... \033[32;1mDONE\033[0m" fi -mkdir "$GALAXY_BUILD" -echo "Copying files to build dir $GALAXY_BUILD ..." +mkdir "$BUILD" +echo "Copying files to build dir $BUILD ..." if [ $all == 1 ]; then - # Copy all files except galaxy build dir + # Copy all files except collection build dir for file in .[A-z]* [A-z]*; do - [[ "$file" == "${GALAXY_BUILD}" ]] && continue - cp -a "$file" "${GALAXY_BUILD}/" + [[ "$file" == "${BUILD}" ]] && continue + cp -a "$file" "${BUILD}/" done else # git ls-tree is quoting, therefore ignore SC2046: Quote this to prevent # word splitting # shellcheck disable=SC2046 - tar -cf - $(git ls-tree HEAD --name-only -r) | (cd "$GALAXY_BUILD/" && tar -xf -) + tar -cf - $(git ls-tree HEAD --name-only -r) | (cd "$BUILD/" && tar -xf -) fi -echo -e "\033[ACopying files to build dir $GALAXY_BUILD ... \033[32;1mDONE\033[0m" -cd "$GALAXY_BUILD" || exit 1 +echo -e "\033[ACopying files to build dir $BUILD ... \033[32;1mDONE\033[0m" +cd "$BUILD" || exit 1 -sed -i -e "s/version: .*/version: \"$galaxy_version\"/" galaxy.yml +echo "Removing .copr, .git* and .pre* files from build dir $BUILD ..." +rm -rf .copr .git* .pre* +echo -e "\033[ARemoving files from build dir $BUILD ... \033[32;1mDONE\033[0m" + +if [ "$collection" != "rpm" ]; then + cat > README-COLLECTION.md <> README-COLLECTION.md <