Skip to content

Commit

Permalink
fix: gh action update
Browse files Browse the repository at this point in the history
  • Loading branch information
sean-freeman committed Nov 14, 2024
1 parent 220b80e commit 5da9284
Showing 1 changed file with 99 additions and 35 deletions.
134 changes: 99 additions & 35 deletions .github/workflows/terraform_ansible_software_availability.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
---

name: SAP Software Availability Tests

on:
Expand All @@ -13,62 +15,75 @@ on:
- main

jobs:
terraform_validate:
name: 'Terraform software availability CRON job'
sap_software_availability:
name: 'SAP software availability CRON job'
runs-on: ubuntu-latest
strategy:
fail-fast: false
max-parallel: 1
matrix:
terraform_module_ansible: [ansible_sap_bw4hana_install, ansible_sap_ecc_hana_install, ansible_sap_ecc_hana_system_copy_hdb, ansible_sap_ecc_ibmdb2_install, ansible_sap_ecc_oracledb_install, ansible_sap_ecc_sapase_install, ansible_sap_ecc_sapmaxdb_install, ansible_sap_hana_install, ansible_sap_nwas_abap_hana_install, ansible_sap_nwas_abap_ibmdb2_install, ansible_sap_nwas_abap_oracledb_install, ansible_sap_nwas_abap_sapase_install, ansible_sap_nwas_abap_sapmaxdb_install, ansible_sap_nwas_java_ibmdb2_install, ansible_sap_nwas_java_sapase_install, ansible_sap_s4hana_distributed_install_maintplan, ansible_sap_s4hana_install, ansible_sap_s4hana_install_maintplan, ansible_sap_s4hana_system_copy_hdb, ansible_sap_solman_sapase_install, ansible_sap_solman_saphana_install]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
path: gh_repo
- name: Ansible setup
- name: Python setup
id: local_setup
run: |
python --version
python -m pip install ansible-core==2.16.13 requests beautifulsoup4 lxml
ansible --version
ansible-galaxy collection install git+https://github.com/sap-linuxlab/community.sap_launchpad.git,main -p ./ansible_collections
- name: Terraform Module for Ansible - check software
python -m pip install requests beautifulsoup4 lxml
git clone https://github.com/sap-linuxlab/community.sap_launchpad.git
ls -lha
- name: Terraform Modules for SAP - check SAP software availability
id: identify_software_list
env:
sap_user_id: ${{ secrets.SAP_USER_ID }}
sap_user_id_password: ${{ secrets.SAP_USER_ID_PASSWORD }}
run: |
export ANSIBLE_COLLECTIONS_PATH="$PWD/ansible_collections"
cd "./gh_repo/all/${{ matrix.terraform_module_ansible }}"
if ! which python > /dev/null; then echo 'Python binary not available' && exit 1 ; fi
# Extract from softwarecenter_search_list_.* until first empty line, then remove yaml formatting and sort for unique
export software_list=$(cat create_ansible_extravars.tf | awk '!NF{f=0} /^.*softwarecenter_search_list.*/{f=1} f{print}' | awk '!/.*softwarecenter_search_list.*/' | awk '{sub(/#.*/,""); print}' | awk '{sub(/ .*- '\''/,""); print}' | tr -d "'" | sort | uniq)
# Each file on newline and strip whitespaces or tabs
export software_list=$(cat ./gh_repo/all/**/create_ansible_extravars.tf | awk '!NF{f=0} /^.*softwarecenter_search_list.*/{f=1} f{print}' | awk '!/.*softwarecenter_search_list.*/' | awk '{sub(/#.*/,""); print}' | awk '{sub(/ .*- '\''/,""); print}' | tr -d "'" | grep "\S" | sort | uniq)
export errors_list=""
for item in $software_list
do
shell_exit_code=0
echo "Checking availability of SAP Software: $item"
ansible all --inventory 'localhost,' --connection 'local' --module-name community.sap_launchpad.software_center_download \
--args "suser_id='$sap_user_id' suser_password='$sap_user_id_password' softwarecenter_search_query='$item' dest='.' dry_run=True" \
|| shell_exit_code=$?
if [ $shell_exit_code -ne 0 ]; then
errors_list="$errors_list $item"
continue
fi
done
cd ../../../
echo "Software List:"
echo "$software_list" # Quote command substitution to preserve newline
cd ./community.sap_launchpad/plugins
touch python_module_search_script.py
echo '#!/usr/bin/env python' >> python_module_search_script.py
echo 'import sys' >> python_module_search_script.py
echo 'input_search_file_list=sys.argv[1]' >> python_module_search_script.py
echo 'from module_utils.sap_id_sso import sap_sso_login' >> python_module_search_script.py
echo 'from module_utils.sap_launchpad_software_center_download_runner import *' >> python_module_search_script.py
echo "username='$sap_user_id'" >> python_module_search_script.py
echo "password='$sap_user_id_password'" >> python_module_search_script.py
echo 'sap_sso_login(username, password)' >> python_module_search_script.py
echo 'input_search_file_list_python=iter(input_search_file_list.splitlines())' >> python_module_search_script.py
echo 'for item in input_search_file_list_python:' >> python_module_search_script.py
echo ' try:' >> python_module_search_script.py
echo " download_link, download_filename = search_software_filename(item,'')" >> python_module_search_script.py
echo ' except Exception as e:' >> python_module_search_script.py
echo ' print(item)' >> python_module_search_script.py
echo ' continue' >> python_module_search_script.py
# Pass multi-line string to Python
# Runtime ~30 min to search for ~350 files
# If error returned instead of download link, the file is missing
errors_list="$(python ./python_module_search_script.py "$software_list")" # Quote command substitution to preserve newline
cd ../../
if [ -z "$errors_list" ]
then
exit 0
else
echo ""
echo "### ERRORS identified ####"
echo "Terraform Modules for SAP require updating,"
echo "as the following SAP Software are no longer available:"
echo "$errors_list" | tr " " "\n"
echo "$errors_list" # Quote command substitution to preserve newline
echo ""
cd ./ansible_collections/community/sap_launchpad/plugins
# Ensure stdout accuracy by pause script
sleep 10
cd ./community.sap_launchpad/plugins
sed -i "s|python3|python|g" ./modules/software_center_download.py
touch python_module_fuzzy_call_script.py
echo '#!/usr/bin/env python3' >> python_module_fuzzy_call_script.py
echo '#!/usr/bin/env python' >> python_module_fuzzy_call_script.py
echo 'import sys' >> python_module_fuzzy_call_script.py
echo 'input_search_file=sys.argv[1]' >> python_module_fuzzy_call_script.py
echo 'input_search_file_name_and_version_only=sys.argv[2]' >> python_module_fuzzy_call_script.py
Expand All @@ -85,6 +100,9 @@ jobs:
echo " for sublist in query_result:" >> python_module_fuzzy_call_script.py
echo " if sublist['Title'].startswith('DBATL'):" >> python_module_fuzzy_call_script.py
echo " print(sublist['Title'])" >> python_module_fuzzy_call_script.py
echo " elif any('_NW_LANG_' in sublist['Description'] for sublist in query_result):" >> python_module_fuzzy_call_script.py
echo " # Skip _NW_LANG_ files which may have duplicates that are filtered automatically when downloaded" >> python_module_fuzzy_call_script.py
echo " print('')" >> python_module_fuzzy_call_script.py
echo " elif any('SYBCTRL' in sublist['Title'] for sublist in query_result):" >> python_module_fuzzy_call_script.py
echo " for sublist in query_result:" >> python_module_fuzzy_call_script.py
echo " if sublist['Title'].startswith('SYBCTRL'):" >> python_module_fuzzy_call_script.py
Expand Down Expand Up @@ -114,12 +132,30 @@ jobs:
echo " list_imdb_lcapps.sort(reverse=True)" >> python_module_fuzzy_call_script.py
echo " print(list_imdb_lcapps[0])" >> python_module_fuzzy_call_script.py
echo " elif any('IMDB_SERVER' in sublist['Title'] for sublist in query_result):" >> python_module_fuzzy_call_script.py
echo " list_imdb_server = []" >> python_module_fuzzy_call_script.py
echo " for sublist in query_result:" >> python_module_fuzzy_call_script.py
echo " input_imdb_server = input_search_file_name_and_version_only[:-1]" >> python_module_fuzzy_call_script.py
echo " if sublist['Title'].startswith(input_imdb_server):" >> python_module_fuzzy_call_script.py
echo " print(sublist['Title'])" >> python_module_fuzzy_call_script.py
echo " # As SAP WebDisp file name numbering does not use preceeding 0's, manually filter out v7 which is older than v69:" >> python_module_fuzzy_call_script.py
echo " list_imdb_server.append(sublist['Title'])" >> python_module_fuzzy_call_script.py
echo " list_imdb_server.sort(reverse=True)" >> python_module_fuzzy_call_script.py
echo " print(list_imdb_server[0])" >> python_module_fuzzy_call_script.py
echo " # Match LCAPPS and AFL to new SAP HANA DB Server version" >> python_module_fuzzy_call_script.py
echo " imdb_server20_existing_prefix = input_search_file_name_and_version_only.split('_')[-1]" >> python_module_fuzzy_call_script.py
echo " imdb_server20_new_prefix = list_imdb_server[0].split('-')[0]" >> python_module_fuzzy_call_script.py
echo " imdb_server20_new_prefix2 = imdb_server20_new_prefix.rsplit('_', 1)[0]" >> python_module_fuzzy_call_script.py
echo " imdb_server20_new_version = imdb_server20_new_prefix2.split('_')[-1]" >> python_module_fuzzy_call_script.py
echo ' imdb_lcapps20_existing_version = "IMDB_LCAPPS_2" + imdb_server20_existing_prefix' >> python_module_fuzzy_call_script.py
echo ' imdb_lcapps20_version = "IMDB_LCAPPS_2" + imdb_server20_new_version' >> python_module_fuzzy_call_script.py
echo " imdb_lcapps20_query = search_software_fuzzy(imdb_lcapps20_version)" >> python_module_fuzzy_call_script.py
echo " imdb_lcapps20_result_prefix = imdb_lcapps20_query[0]['Title'].split('-')[0]" >> python_module_fuzzy_call_script.py
echo ' imdb_afl20_existing_version = "IMDB_AFL20_" + imdb_server20_existing_prefix' >> python_module_fuzzy_call_script.py
echo ' imdb_afl20_version = "IMDB_AFL20_" + imdb_server20_new_version' >> python_module_fuzzy_call_script.py
echo " imdb_afl20_query = search_software_fuzzy(imdb_afl20_version)" >> python_module_fuzzy_call_script.py
echo " imdb_afl20_result_prefix = imdb_afl20_query[0]['Title'].split('-')[0]" >> python_module_fuzzy_call_script.py
echo " print(imdb_lcapps20_existing_version + ';' + imdb_lcapps20_result_prefix)" >> python_module_fuzzy_call_script.py
echo " print(imdb_afl20_existing_version + ';' + imdb_afl20_result_prefix)" >> python_module_fuzzy_call_script.py
echo " elif any('SAPWEBDISP' in sublist['Title'] for sublist in query_result):" >> python_module_fuzzy_call_script.py
echo " # As SAP WebDisp file name numbering does not use preceeding 0's, manually filter out v7 which is older than v69:" >> python_module_fuzzy_call_script.py
echo " input_webdisp = input_search_file_name_and_version_only[:-2]" >> python_module_fuzzy_call_script.py
echo " list_webdisp = []" >> python_module_fuzzy_call_script.py
echo " for sublist in query_result:" >> python_module_fuzzy_call_script.py
Expand All @@ -137,31 +173,59 @@ jobs:
echo ' else:' >> python_module_fuzzy_call_script.py
echo " print(query_result[0]['Title'])" >> python_module_fuzzy_call_script.py
export exit1_check=0
cd ../../../../
cd ../../
# Pass list to for loop, not multi-line string. Do not use quote command substitution
for filename in $errors_list
do
filename_noext="${filename%.*}"
filename_id_only="${filename_noext##*-}"
filename_name_and_version_only="${filename_noext%_*}"
cd ./ansible_collections/community/sap_launchpad/plugins
#echo "DEBUG - Filename"
#echo $filename
#echo "DEBUG - Filename NO EXT"
#echo $filename_noext
#echo "DEBUG - Filename ID ONLY"
#echo $filename_id_only
#echo "DEBUG - Filename NAME AND VERSION ONLY"
#echo $filename_name_and_version_only
cd ./community.sap_launchpad/plugins
search_file="$(python ./python_module_fuzzy_call_script.py $filename_id_only $filename_name_and_version_only)" # Quote command substitution to preserve newline
cd ../../../../
cd ../../
if [[ "$search_file" == *"ERROR"* ]]; then
echo -e "$search_file" # Quote variable to preserve newline
exit1_check=1
elif [[ "$search_file" == "" ]]; then
echo "Skipped file $filename"
elif [[ "$search_file" == *"IMDB_SERVER"* ]]; then
echo "Perform recursive sed for SAP HANA and SAP HANA Components"
cd "./gh_repo"
echo "$search_file" | while IFS= read -r line ; do
stripped_search_file=$(echo $line | tr -d '\n')
if [[ "$stripped_search_file" == *.* ]]; then
echo "-> Perform recursive sed for $filename change to $search_file"
find . -type f -not -path '*/\.*' -exec sed -i "s/$filename/$stripped_search_file/g" {} \;
elif [[ "$stripped_search_file" == *\;* ]]; then
origin_prefix="${stripped_search_file%;*}"
replace_prefix="${stripped_search_file##*;}"
echo "-> Perform recursive sed for $origin_prefix change to $replace_prefix"
find . -type f -not -path '*/\.*' -exec sed -i "s/$origin_prefix.[0-9]\{1,\}/$replace_prefix/g" {} \;
fi
done
cd ../
else
echo "Perform recursive sed for $filename change to $search_file"
stripped_search_file=$(echo $search_file | tr -d '\n')
cd "./gh_repo/all/${{ matrix.terraform_module_ansible }}"
cd "./gh_repo"
find . -type f -not -path '*/\.*' -exec sed -i "s/$filename/$stripped_search_file/g" {} \;
cd ../../../
cd ../
fi
done
if [[ "$exit1_check" -eq 1 ]]; then
exit 1
fi
fi
- name: Commit to main branch
if: always() # Ensure even if errors on previous step, that any replaced filenames are committed
id: git_commit_auto
run: |
cd ./gh_repo
Expand Down

0 comments on commit 5da9284

Please sign in to comment.