SAP Software Availability Tests #187
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
# This GitHub Action requires the repository to have GitHub Action 'Read and write permissions' under Settings -> Action -> General -> Workflow permissions. | |
# Amend GitHub Action 'Artifact and log retention' to 60 days to avoid error 'You are running out of disk space. The runner will stop working when the machine runs out of disk space.' | |
name: SAP Software Availability Tests | |
on: | |
# * is a special character in YAML, quote string to avoid | |
# schedule uses UTC | |
# only uses the main branch, to alter use 'with: ref: branch_name' for the step using actions/checkout | |
# At 05:00 on every day-of-week from Monday through Friday | |
schedule: | |
- cron: '0 5 * * 1-5' | |
push: | |
branches: | |
- main | |
jobs: | |
sap_software_availability: | |
name: 'SAP software availability CRON job' | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
max-parallel: 1 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
path: gh_repo | |
- name: Ansible setup | |
id: local_setup | |
run: | | |
python --version | |
python -m pip install requests beautifulsoup4 lxml | |
git clone https://github.com/sap-linuxlab/community.sap_launchpad.git | |
ls -lha | |
- name: Ansible Playbooks 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: | | |
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 | |
# Each file on newline and strip whitespaces or tabs | |
export software_list=$(cat ./gh_repo/**/**/ansible_extravars.yml | awk '!NF{f=0} /^.*softwarecenter_search_list.*/{f=1} f{print}' | awk '!/.*softwarecenter_search_list.*/' | awk '{sub(/#.*/,""); print}' | awk '{sub(/ .*- '\''/,""); print}' | sed '/^ *$/d' | sed '/^---*$/d' | tr -d "'" | sort | uniq | tr -d " \t") | |
export errors_list="" | |
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 "Ansible Playbooks for SAP require updating," | |
echo "as the following SAP Software are no longer available:" | |
echo "$errors_list" # Quote command substitution to preserve newline | |
echo "" | |
# 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 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 | |
echo 'from module_utils.sap_id_sso import sap_sso_login' >> python_module_fuzzy_call_script.py | |
echo 'from module_utils.sap_launchpad_software_center_download_search_fuzzy import *' >> python_module_fuzzy_call_script.py | |
echo "username='$sap_user_id'" >> python_module_fuzzy_call_script.py | |
echo "password='$sap_user_id_password'" >> python_module_fuzzy_call_script.py | |
echo 'sap_sso_login(username, password)' >> python_module_fuzzy_call_script.py | |
echo 'query_result = search_software_fuzzy(input_search_file)' >> python_module_fuzzy_call_script.py | |
echo 'if len(query_result) >= 2:' >> python_module_fuzzy_call_script.py | |
echo " if '70SWPM' in query_result[0]['Title']:" >> python_module_fuzzy_call_script.py | |
echo " print(query_result[-1]['Title'])" >> python_module_fuzzy_call_script.py | |
echo " elif any('DBATL' 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('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 | |
echo " print(sublist['Title'])" >> python_module_fuzzy_call_script.py | |
echo " elif any('IMDB_CLIENT20' in sublist['Title'] for sublist in query_result):" >> python_module_fuzzy_call_script.py | |
echo " input_imdb_client = input_search_file_name_and_version_only[:-2]" >> python_module_fuzzy_call_script.py | |
echo " list_imdb_client = []" >> python_module_fuzzy_call_script.py | |
echo " for sublist in query_result:" >> python_module_fuzzy_call_script.py | |
echo " if sublist['Title'].startswith(input_imdb_client):" >> python_module_fuzzy_call_script.py | |
echo " list_imdb_client.append(sublist['Title'])" >> python_module_fuzzy_call_script.py | |
echo " list_imdb_client.sort(reverse=True)" >> python_module_fuzzy_call_script.py | |
echo " print(list_imdb_client[0])" >> python_module_fuzzy_call_script.py | |
echo " elif any('IMDB_AFL' in sublist['Title'] for sublist in query_result):" >> python_module_fuzzy_call_script.py | |
echo " input_imdb_afl = input_search_file_name_and_version_only[:-1]" >> python_module_fuzzy_call_script.py | |
echo " list_imdb_afl = []" >> python_module_fuzzy_call_script.py | |
echo " for sublist in query_result:" >> python_module_fuzzy_call_script.py | |
echo " if sublist['Title'].startswith(input_imdb_afl):" >> python_module_fuzzy_call_script.py | |
echo " list_imdb_afl.append(sublist['Title'])" >> python_module_fuzzy_call_script.py | |
echo " list_imdb_afl.sort(reverse=True)" >> python_module_fuzzy_call_script.py | |
echo " print(list_imdb_afl[0])" >> python_module_fuzzy_call_script.py | |
echo " elif any('IMDB_LCAPPS' in sublist['Title'] for sublist in query_result):" >> python_module_fuzzy_call_script.py | |
echo " input_imdb_lcapps = input_search_file_name_and_version_only[:-1]" >> python_module_fuzzy_call_script.py | |
echo " list_imdb_lcapps = []" >> python_module_fuzzy_call_script.py | |
echo " for sublist in query_result:" >> python_module_fuzzy_call_script.py | |
echo " if sublist['Title'].startswith(input_imdb_lcapps):" >> python_module_fuzzy_call_script.py | |
echo " list_imdb_lcapps.append(sublist['Title'])" >> python_module_fuzzy_call_script.py | |
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 " 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 | |
echo " if sublist['Title'].startswith(input_webdisp) and not sublist['Title'].startswith('SAPWEBDISP_SP_7'):" >> python_module_fuzzy_call_script.py | |
echo " list_webdisp.append(sublist['Title'])" >> python_module_fuzzy_call_script.py | |
echo " list_webdisp.sort(reverse=True)" >> python_module_fuzzy_call_script.py | |
echo " print(list_webdisp[0])" >> python_module_fuzzy_call_script.py | |
echo " else:" >> python_module_fuzzy_call_script.py | |
echo ' print("\nERROR. More than 1 result for " + input_search_file + ", manual intervention required....")' >> python_module_fuzzy_call_script.py | |
echo ' for item in query_result:' >> python_module_fuzzy_call_script.py | |
echo " print('Identified ' + item['Title'] + ' : ' + item['Description'] + ', ' + item['Infotype'],end='\n')" >> python_module_fuzzy_call_script.py | |
echo 'else:' >> python_module_fuzzy_call_script.py | |
echo ' if len(query_result) == 0:' >> python_module_fuzzy_call_script.py | |
echo ' print("\nERROR. No result for " + input_search_file + ", manual intervention required....")' >> python_module_fuzzy_call_script.py | |
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 ../../ | |
# 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%_*}" | |
#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 ../../ | |
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" | |
find . -type f -not -path '*/\.*' -exec sed -i "s/$filename/$stripped_search_file/g" {} \; | |
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 | |
if [[ $(git status --porcelain) ]]; then | |
git config user.name github-actions | |
git config user.email [email protected] | |
git stash | |
git pull | |
git stash pop | |
git add . | |
git status | |
git commit -m "software-update: replace with new filenames $(date +%F_%H-%M)" | |
git push | |
else | |
exit 0 | |
fi |