Skip to content

Commit d4666cf

Browse files
committed
fix: gh action update
1 parent 220b80e commit d4666cf

File tree

1 file changed

+113
-35
lines changed

1 file changed

+113
-35
lines changed

.github/workflows/terraform_ansible_software_availability.yml

Lines changed: 113 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
---
2+
13
name: SAP Software Availability Tests
24

35
on:
@@ -13,62 +15,75 @@ on:
1315
- main
1416

1517
jobs:
16-
terraform_validate:
17-
name: 'Terraform software availability CRON job'
18+
sap_software_availability:
19+
name: 'SAP software availability CRON job'
1820
runs-on: ubuntu-latest
1921
strategy:
2022
fail-fast: false
2123
max-parallel: 1
22-
matrix:
23-
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]
2424
steps:
2525
- name: Checkout
2626
uses: actions/checkout@v4
2727
with:
2828
path: gh_repo
29-
- name: Ansible setup
29+
- name: Python setup
3030
id: local_setup
3131
run: |
3232
python --version
33-
python -m pip install ansible-core==2.16.13 requests beautifulsoup4 lxml
34-
ansible --version
35-
ansible-galaxy collection install git+https://github.com/sap-linuxlab/community.sap_launchpad.git,main -p ./ansible_collections
36-
- name: Terraform Module for Ansible - check software
33+
python -m pip install requests beautifulsoup4 lxml
34+
git clone https://github.com/sap-linuxlab/community.sap_launchpad.git
35+
ls -lha
36+
- name: Terraform Modules for SAP - check SAP software availability
3737
id: identify_software_list
3838
env:
3939
sap_user_id: ${{ secrets.SAP_USER_ID }}
4040
sap_user_id_password: ${{ secrets.SAP_USER_ID_PASSWORD }}
4141
run: |
42-
export ANSIBLE_COLLECTIONS_PATH="$PWD/ansible_collections"
43-
cd "./gh_repo/all/${{ matrix.terraform_module_ansible }}"
42+
if ! which python > /dev/null; then echo 'Python binary not available' && exit 1 ; fi
4443
# Extract from softwarecenter_search_list_.* until first empty line, then remove yaml formatting and sort for unique
45-
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)
44+
# Each file on newline and strip whitespaces or tabs
45+
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}' | sed '/^ *$/d' | sed '/^---*$/d' | tr -d "'" | sort | uniq | tr -d " \t")
4646
export errors_list=""
47-
for item in $software_list
48-
do
49-
shell_exit_code=0
50-
echo "Checking availability of SAP Software: $item"
51-
ansible all --inventory 'localhost,' --connection 'local' --module-name community.sap_launchpad.software_center_download \
52-
--args "suser_id='$sap_user_id' suser_password='$sap_user_id_password' softwarecenter_search_query='$item' dest='.' dry_run=True" \
53-
|| shell_exit_code=$?
54-
if [ $shell_exit_code -ne 0 ]; then
55-
errors_list="$errors_list $item"
56-
continue
57-
fi
58-
done
59-
cd ../../../
47+
echo "Software List:"
48+
echo "$software_list" # Quote command substitution to preserve newline
49+
cd ./community.sap_launchpad/plugins
50+
touch python_module_search_script.py
51+
echo '#!/usr/bin/env python' >> python_module_search_script.py
52+
echo 'import sys' >> python_module_search_script.py
53+
echo 'input_search_file_list=sys.argv[1]' >> python_module_search_script.py
54+
echo 'from module_utils.sap_id_sso import sap_sso_login' >> python_module_search_script.py
55+
echo 'from module_utils.sap_launchpad_software_center_download_runner import *' >> python_module_search_script.py
56+
echo "username='$sap_user_id'" >> python_module_search_script.py
57+
echo "password='$sap_user_id_password'" >> python_module_search_script.py
58+
echo 'sap_sso_login(username, password)' >> python_module_search_script.py
59+
echo 'input_search_file_list_python=iter(input_search_file_list.splitlines())' >> python_module_search_script.py
60+
echo 'for item in input_search_file_list_python:' >> python_module_search_script.py
61+
echo ' try:' >> python_module_search_script.py
62+
echo " download_link, download_filename = search_software_filename(item,'')" >> python_module_search_script.py
63+
echo ' except Exception as e:' >> python_module_search_script.py
64+
echo ' print(item)' >> python_module_search_script.py
65+
echo ' continue' >> python_module_search_script.py
66+
# Pass multi-line string to Python
67+
# Runtime ~30 min to search for ~350 files
68+
# If error returned instead of download link, the file is missing
69+
errors_list="$(python ./python_module_search_script.py "$software_list")" # Quote command substitution to preserve newline
70+
cd ../../
6071
if [ -z "$errors_list" ]
6172
then
6273
exit 0
6374
else
75+
echo ""
6476
echo "### ERRORS identified ####"
6577
echo "Terraform Modules for SAP require updating,"
6678
echo "as the following SAP Software are no longer available:"
67-
echo "$errors_list" | tr " " "\n"
79+
echo "$errors_list" # Quote command substitution to preserve newline
6880
echo ""
69-
cd ./ansible_collections/community/sap_launchpad/plugins
81+
# Ensure stdout accuracy by pause script
82+
sleep 10
83+
cd ./community.sap_launchpad/plugins
84+
sed -i "s|python3|python|g" ./modules/software_center_download.py
7085
touch python_module_fuzzy_call_script.py
71-
echo '#!/usr/bin/env python3' >> python_module_fuzzy_call_script.py
86+
echo '#!/usr/bin/env python' >> python_module_fuzzy_call_script.py
7287
echo 'import sys' >> python_module_fuzzy_call_script.py
7388
echo 'input_search_file=sys.argv[1]' >> python_module_fuzzy_call_script.py
7489
echo 'input_search_file_name_and_version_only=sys.argv[2]' >> python_module_fuzzy_call_script.py
@@ -85,10 +100,27 @@ jobs:
85100
echo " for sublist in query_result:" >> python_module_fuzzy_call_script.py
86101
echo " if sublist['Title'].startswith('DBATL'):" >> python_module_fuzzy_call_script.py
87102
echo " print(sublist['Title'])" >> python_module_fuzzy_call_script.py
103+
echo " elif any('_NW_LANG_' in sublist['Description'] for sublist in query_result):" >> python_module_fuzzy_call_script.py
104+
echo " # Skip _NW_LANG_ files which may have duplicates that are filtered automatically when downloaded" >> python_module_fuzzy_call_script.py
105+
echo " print('')" >> python_module_fuzzy_call_script.py
88106
echo " elif any('SYBCTRL' in sublist['Title'] for sublist in query_result):" >> python_module_fuzzy_call_script.py
89107
echo " for sublist in query_result:" >> python_module_fuzzy_call_script.py
90108
echo " if sublist['Title'].startswith('SYBCTRL'):" >> python_module_fuzzy_call_script.py
91109
echo " print(sublist['Title'])" >> python_module_fuzzy_call_script.py
110+
echo " elif any('SAPEXE_' in sublist['Title'] for sublist in query_result):" >> python_module_fuzzy_call_script.py
111+
echo " list_sapexe = []" >> python_module_fuzzy_call_script.py
112+
echo " for sublist in query_result:" >> python_module_fuzzy_call_script.py
113+
echo " if sublist['Title'].startswith('SAPEXE'):" >> python_module_fuzzy_call_script.py
114+
echo " list_sapexe.append(int((sublist['Title'].split('-', 1)[0]).split('_', 1)[1]))" >> python_module_fuzzy_call_script.py
115+
echo " list_sapexe.sort(reverse=True)" >> python_module_fuzzy_call_script.py
116+
echo " print('SAPEXE_' + str(list_sapexe[0]) + '-' + input_search_file + '.SAR')" >> python_module_fuzzy_call_script.py
117+
echo " elif any('SAPEXEDB_' in sublist['Title'] for sublist in query_result):" >> python_module_fuzzy_call_script.py
118+
echo " list_sapexedb = []" >> python_module_fuzzy_call_script.py
119+
echo " for sublist in query_result:" >> python_module_fuzzy_call_script.py
120+
echo " if sublist['Title'].startswith('SAPEXEDB'):" >> python_module_fuzzy_call_script.py
121+
echo " list_sapexedb.append(int((sublist['Title'].split('-', 1)[0]).split('_', 1)[1]))" >> python_module_fuzzy_call_script.py
122+
echo " list_sapexedb.sort(reverse=True)" >> python_module_fuzzy_call_script.py
123+
echo " print('SAPEXEDB_' + str(list_sapexedb[0]) + '-' + input_search_file + '.SAR')" >> python_module_fuzzy_call_script.py
92124
echo " elif any('IMDB_CLIENT20' in sublist['Title'] for sublist in query_result):" >> python_module_fuzzy_call_script.py
93125
echo " input_imdb_client = input_search_file_name_and_version_only[:-2]" >> python_module_fuzzy_call_script.py
94126
echo " list_imdb_client = []" >> python_module_fuzzy_call_script.py
@@ -114,12 +146,30 @@ jobs:
114146
echo " list_imdb_lcapps.sort(reverse=True)" >> python_module_fuzzy_call_script.py
115147
echo " print(list_imdb_lcapps[0])" >> python_module_fuzzy_call_script.py
116148
echo " elif any('IMDB_SERVER' in sublist['Title'] for sublist in query_result):" >> python_module_fuzzy_call_script.py
149+
echo " list_imdb_server = []" >> python_module_fuzzy_call_script.py
117150
echo " for sublist in query_result:" >> python_module_fuzzy_call_script.py
118151
echo " input_imdb_server = input_search_file_name_and_version_only[:-1]" >> python_module_fuzzy_call_script.py
119152
echo " if sublist['Title'].startswith(input_imdb_server):" >> python_module_fuzzy_call_script.py
120-
echo " print(sublist['Title'])" >> python_module_fuzzy_call_script.py
121-
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
153+
echo " list_imdb_server.append(sublist['Title'])" >> python_module_fuzzy_call_script.py
154+
echo " list_imdb_server.sort(reverse=True)" >> python_module_fuzzy_call_script.py
155+
echo " print(list_imdb_server[0])" >> python_module_fuzzy_call_script.py
156+
echo " # Match LCAPPS and AFL to new SAP HANA DB Server version" >> python_module_fuzzy_call_script.py
157+
echo " imdb_server20_existing_prefix = input_search_file_name_and_version_only.split('_')[-1]" >> python_module_fuzzy_call_script.py
158+
echo " imdb_server20_new_prefix = list_imdb_server[0].split('-')[0]" >> python_module_fuzzy_call_script.py
159+
echo " imdb_server20_new_prefix2 = imdb_server20_new_prefix.rsplit('_', 1)[0]" >> python_module_fuzzy_call_script.py
160+
echo " imdb_server20_new_version = imdb_server20_new_prefix2.split('_')[-1]" >> python_module_fuzzy_call_script.py
161+
echo ' imdb_lcapps20_existing_version = "IMDB_LCAPPS_2" + imdb_server20_existing_prefix' >> python_module_fuzzy_call_script.py
162+
echo ' imdb_lcapps20_version = "IMDB_LCAPPS_2" + imdb_server20_new_version' >> python_module_fuzzy_call_script.py
163+
echo " imdb_lcapps20_query = search_software_fuzzy(imdb_lcapps20_version)" >> python_module_fuzzy_call_script.py
164+
echo " imdb_lcapps20_result_prefix = imdb_lcapps20_query[0]['Title'].split('-')[0]" >> python_module_fuzzy_call_script.py
165+
echo ' imdb_afl20_existing_version = "IMDB_AFL20_" + imdb_server20_existing_prefix' >> python_module_fuzzy_call_script.py
166+
echo ' imdb_afl20_version = "IMDB_AFL20_" + imdb_server20_new_version' >> python_module_fuzzy_call_script.py
167+
echo " imdb_afl20_query = search_software_fuzzy(imdb_afl20_version)" >> python_module_fuzzy_call_script.py
168+
echo " imdb_afl20_result_prefix = imdb_afl20_query[0]['Title'].split('-')[0]" >> python_module_fuzzy_call_script.py
169+
echo " print(imdb_lcapps20_existing_version + ';' + imdb_lcapps20_result_prefix)" >> python_module_fuzzy_call_script.py
170+
echo " print(imdb_afl20_existing_version + ';' + imdb_afl20_result_prefix)" >> python_module_fuzzy_call_script.py
122171
echo " elif any('SAPWEBDISP' in sublist['Title'] for sublist in query_result):" >> python_module_fuzzy_call_script.py
172+
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
123173
echo " input_webdisp = input_search_file_name_and_version_only[:-2]" >> python_module_fuzzy_call_script.py
124174
echo " list_webdisp = []" >> python_module_fuzzy_call_script.py
125175
echo " for sublist in query_result:" >> python_module_fuzzy_call_script.py
@@ -137,31 +187,59 @@ jobs:
137187
echo ' else:' >> python_module_fuzzy_call_script.py
138188
echo " print(query_result[0]['Title'])" >> python_module_fuzzy_call_script.py
139189
export exit1_check=0
140-
cd ../../../../
190+
cd ../../
191+
# Pass list to for loop, not multi-line string. Do not use quote command substitution
141192
for filename in $errors_list
142193
do
143194
filename_noext="${filename%.*}"
144195
filename_id_only="${filename_noext##*-}"
145196
filename_name_and_version_only="${filename_noext%_*}"
146-
cd ./ansible_collections/community/sap_launchpad/plugins
197+
#echo "DEBUG - Filename"
198+
#echo $filename
199+
#echo "DEBUG - Filename NO EXT"
200+
#echo $filename_noext
201+
#echo "DEBUG - Filename ID ONLY"
202+
#echo $filename_id_only
203+
#echo "DEBUG - Filename NAME AND VERSION ONLY"
204+
#echo $filename_name_and_version_only
205+
cd ./community.sap_launchpad/plugins
147206
search_file="$(python ./python_module_fuzzy_call_script.py $filename_id_only $filename_name_and_version_only)" # Quote command substitution to preserve newline
148-
cd ../../../../
207+
cd ../../
149208
if [[ "$search_file" == *"ERROR"* ]]; then
150209
echo -e "$search_file" # Quote variable to preserve newline
151210
exit1_check=1
211+
elif [[ "$search_file" == "" ]]; then
212+
echo "Skipped file $filename"
213+
elif [[ "$search_file" == *"IMDB_SERVER"* ]]; then
214+
echo "Perform recursive sed for SAP HANA and SAP HANA Components"
215+
cd "./gh_repo"
216+
echo "$search_file" | while IFS= read -r line ; do
217+
stripped_search_file=$(echo $line | tr -d '\n')
218+
if [[ "$stripped_search_file" == *.* ]]; then
219+
echo "-> Perform recursive sed for $filename change to $search_file"
220+
find . -type f -not -path '*/\.*' -exec sed -i "s/$filename/$stripped_search_file/g" {} \;
221+
elif [[ "$stripped_search_file" == *\;* ]]; then
222+
origin_prefix="${stripped_search_file%;*}"
223+
replace_prefix="${stripped_search_file##*;}"
224+
echo "-> Perform recursive sed for $origin_prefix change to $replace_prefix"
225+
find . -type f -not -path '*/\.*' -exec sed -i "s/$origin_prefix.[0-9]\{1,\}/$replace_prefix/g" {} \;
226+
fi
227+
done
228+
cd ../
152229
else
153230
echo "Perform recursive sed for $filename change to $search_file"
154231
stripped_search_file=$(echo $search_file | tr -d '\n')
155-
cd "./gh_repo/all/${{ matrix.terraform_module_ansible }}"
232+
cd "./gh_repo"
156233
find . -type f -not -path '*/\.*' -exec sed -i "s/$filename/$stripped_search_file/g" {} \;
157-
cd ../../../
234+
cd ../
158235
fi
159236
done
160237
if [[ "$exit1_check" -eq 1 ]]; then
161238
exit 1
162239
fi
163240
fi
164241
- name: Commit to main branch
242+
if: always() # Ensure even if errors on previous step, that any replaced filenames are committed
165243
id: git_commit_auto
166244
run: |
167245
cd ./gh_repo

0 commit comments

Comments
 (0)