mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-04-10 17:08:47 +00:00
[prtester] fix prtester no longer supporting multiple bridges being changed, because the filenames are not unique (#4310)
This commit is contained in:
parent
668f3a9d7e
commit
6c88f2c21e
1
.github/.gitignore
vendored
1
.github/.gitignore
vendored
@ -4,3 +4,4 @@
|
|||||||
# Generated files
|
# Generated files
|
||||||
comment*.md
|
comment*.md
|
||||||
comment*.txt
|
comment*.txt
|
||||||
|
*.html
|
||||||
|
36
.github/prtester.py
vendored
36
.github/prtester.py
vendored
@ -5,6 +5,7 @@ from bs4 import BeautifulSoup
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Iterable
|
from typing import Iterable
|
||||||
import os
|
import os
|
||||||
|
import glob
|
||||||
import urllib
|
import urllib
|
||||||
|
|
||||||
# This script is specifically written to be used in automation for https://github.com/RSS-Bridge/rss-bridge
|
# This script is specifically written to be used in automation for https://github.com/RSS-Bridge/rss-bridge
|
||||||
@ -14,18 +15,33 @@ import urllib
|
|||||||
# It also add a <base> tag with the url of em's public instance, so viewing
|
# It also add a <base> tag with the url of em's public instance, so viewing
|
||||||
# the HTML file locally will actually work as designed.
|
# the HTML file locally will actually work as designed.
|
||||||
|
|
||||||
|
ARTIFACT_FILE_EXTENSION = '.html'
|
||||||
|
|
||||||
class Instance:
|
class Instance:
|
||||||
name = ''
|
name = ''
|
||||||
url = ''
|
url = ''
|
||||||
|
|
||||||
def main(instances: Iterable[Instance], with_upload: bool, with_reduced_upload: bool, title: str, output_file: str):
|
def main(instances: Iterable[Instance], with_upload: bool, with_reduced_upload: bool, title: str, output_file: str):
|
||||||
start_date = datetime.now()
|
start_date = datetime.now()
|
||||||
|
|
||||||
|
prid = os.getenv('PR')
|
||||||
|
artifact_base_url = f'https://rss-bridge.github.io/rss-bridge-tests/prs/{prid}'
|
||||||
|
artifact_directory = os.getcwd()
|
||||||
|
for file in glob.glob(f'*{ARTIFACT_FILE_EXTENSION}', root_dir=artifact_directory):
|
||||||
|
os.remove(file)
|
||||||
|
|
||||||
table_rows = []
|
table_rows = []
|
||||||
for instance in instances:
|
for instance in instances:
|
||||||
page = requests.get(instance.url) # Use python requests to grab the rss-bridge main page
|
page = requests.get(instance.url) # Use python requests to grab the rss-bridge main page
|
||||||
soup = BeautifulSoup(page.content, "html.parser") # use bs4 to turn the page into soup
|
soup = BeautifulSoup(page.content, "html.parser") # use bs4 to turn the page into soup
|
||||||
bridge_cards = soup.select('.bridge-card') # get a soup-formatted list of all bridges on the rss-bridge page
|
bridge_cards = soup.select('.bridge-card') # get a soup-formatted list of all bridges on the rss-bridge page
|
||||||
table_rows += testBridges(instance, bridge_cards, with_upload, with_reduced_upload) # run the main scraping code with the list of bridges
|
table_rows += testBridges(
|
||||||
|
instance=instance,
|
||||||
|
bridge_cards=bridge_cards,
|
||||||
|
with_upload=with_upload,
|
||||||
|
with_reduced_upload=with_reduced_upload,
|
||||||
|
artifact_directory=artifact_directory,
|
||||||
|
artifact_base_url=artifact_base_url) # run the main scraping code with the list of bridges
|
||||||
with open(file=output_file, mode='w+', encoding='utf-8') as file:
|
with open(file=output_file, mode='w+', encoding='utf-8') as file:
|
||||||
table_rows_value = '\n'.join(sorted(table_rows))
|
table_rows_value = '\n'.join(sorted(table_rows))
|
||||||
file.write(f'''
|
file.write(f'''
|
||||||
@ -37,10 +53,8 @@ def main(instances: Iterable[Instance], with_upload: bool, with_reduced_upload:
|
|||||||
*last change: {start_date.strftime("%A %Y-%m-%d %H:%M:%S")}*
|
*last change: {start_date.strftime("%A %Y-%m-%d %H:%M:%S")}*
|
||||||
'''.strip())
|
'''.strip())
|
||||||
|
|
||||||
def testBridges(instance: Instance, bridge_cards: Iterable, with_upload: bool, with_reduced_upload: bool) -> Iterable:
|
def testBridges(instance: Instance, bridge_cards: Iterable, with_upload: bool, with_reduced_upload: bool, artifact_directory: str, artifact_base_url: str) -> Iterable:
|
||||||
instance_suffix = ''
|
instance_suffix = ''
|
||||||
prid = os.getenv("PR")
|
|
||||||
tester_url = f'https://rss-bridge.github.io/rss-bridge-tests/prs/{prid}'
|
|
||||||
if instance.name:
|
if instance.name:
|
||||||
instance_suffix = f' ({instance.name})'
|
instance_suffix = f' ({instance.name})'
|
||||||
table_rows = []
|
table_rows = []
|
||||||
@ -105,13 +119,13 @@ def testBridges(instance: Instance, bridge_cards: Iterable, with_upload: bool, w
|
|||||||
selectionvalue = selectionentry.get('value')
|
selectionvalue = selectionentry.get('value')
|
||||||
break
|
break
|
||||||
context_parameters[listname] = selectionvalue
|
context_parameters[listname] = selectionvalue
|
||||||
termpad_url = 'about:blank'
|
artifact_url = 'about:blank'
|
||||||
if error_messages:
|
if error_messages:
|
||||||
status = '<br>'.join(map(lambda m: f'❌ `{m}`', error_messages))
|
status = '<br>'.join(map(lambda m: f'❌ `{m}`', error_messages))
|
||||||
else:
|
else:
|
||||||
# if all example/default values are present, form the full request url, run the request, add a <base> tag with
|
# if all example/default values are present, form the full request url, run the request, add a <base> tag with
|
||||||
# the url of em's public instance to the response text (so that relative paths work, e.g. to the static css file) and
|
# the url of em's public instance to the response text (so that relative paths work, e.g. to the static css file) and
|
||||||
# then upload it to termpad.com, a pastebin-like-site.
|
# then save it to a html file.
|
||||||
context_parameters.update({
|
context_parameters.update({
|
||||||
'action': 'display',
|
'action': 'display',
|
||||||
'bridge': bridgeid,
|
'bridge': bridgeid,
|
||||||
@ -142,16 +156,18 @@ def testBridges(instance: Instance, bridge_cards: Iterable, with_upload: bool, w
|
|||||||
if status_is_ok:
|
if status_is_ok:
|
||||||
status = '✔️'
|
status = '✔️'
|
||||||
if with_upload and (not with_reduced_upload or not status_is_ok):
|
if with_upload and (not with_reduced_upload or not status_is_ok):
|
||||||
filename = f'{os.getcwd()}/{instance.name}_{form_number}.html'
|
filename = f'{bridge_name} {form_number}{instance_suffix}{ARTIFACT_FILE_EXTENSION}'
|
||||||
with open(file=filename, mode='wb') as file:
|
filename = re.sub(r'[^a-z0-9 \_\-\.]', '', filename, flags=re.I).replace(' ', '_')
|
||||||
|
with open(file=f'{artifact_directory}/{filename}', mode='wb') as file:
|
||||||
file.write(page_text)
|
file.write(page_text)
|
||||||
table_rows.append(f'| {bridge_name} | [{form_number} {context_name}{instance_suffix}]({tester_url}/{instance.name}_{form_number}.html) | {status} |')
|
artifact_url = f'{artifact_base_url}/{filename}'
|
||||||
|
table_rows.append(f'| {bridge_name} | [{form_number} {context_name}{instance_suffix}]({artifact_url}) | {status} |')
|
||||||
form_number += 1
|
form_number += 1
|
||||||
return table_rows
|
return table_rows
|
||||||
|
|
||||||
def getFirstLine(value: str) -> str:
|
def getFirstLine(value: str) -> str:
|
||||||
# trim whitespace and remove text that can break the table or is simply unnecessary
|
# trim whitespace and remove text that can break the table or is simply unnecessary
|
||||||
clean_value = re.sub('^\[[^\]]+\]\s*rssbridge\.|[\|`]', '', value.strip())
|
clean_value = re.sub(r'^\[[^\]]+\]\s*rssbridge\.|[\|`]', '', value.strip())
|
||||||
first_line = next(iter(clean_value.splitlines()), '')
|
first_line = next(iter(clean_value.splitlines()), '')
|
||||||
max_length = 250
|
max_length = 250
|
||||||
if (len(first_line) > max_length):
|
if (len(first_line) > max_length):
|
||||||
|
Loading…
Reference in New Issue
Block a user