[prtester] support forks to upload to their own "rss-bridge-tests"

add parameter "--artifact-base-url" and "--artifact-directory"
This commit is contained in:
User123698745 2024-10-20 23:10:14 +02:00
parent c3dc46a307
commit cb36bc2375
2 changed files with 36 additions and 34 deletions

35
.github/prtester.py vendored
View File

@ -21,13 +21,10 @@ 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_artifacts: bool, with_reduced_artifacts: bool, artifacts_directory: str, artifacts_base_url: str, title: str, output_file: str):
start_date = datetime.now() start_date = datetime.now()
prid = os.getenv('PR') for file in glob.glob(f'*{ARTIFACT_FILE_EXTENSION}', root_dir=artifacts_directory):
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) os.remove(file)
table_rows = [] table_rows = []
@ -38,10 +35,10 @@ def main(instances: Iterable[Instance], with_upload: bool, with_reduced_upload:
table_rows += testBridges( table_rows += testBridges(
instance=instance, instance=instance,
bridge_cards=bridge_cards, bridge_cards=bridge_cards,
with_upload=with_upload, with_artifacts=with_artifacts,
with_reduced_upload=with_reduced_upload, with_reduced_artifacts=with_reduced_artifacts,
artifact_directory=artifact_directory, artifacts_directory=artifacts_directory,
artifact_base_url=artifact_base_url) # run the main scraping code with the list of bridges artifacts_base_url=artifacts_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'''
@ -53,7 +50,7 @@ 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, artifact_directory: str, artifact_base_url: str) -> Iterable: def testBridges(instance: Instance, bridge_cards: Iterable, with_artifacts: bool, with_reduced_artifacts: bool, artifacts_directory: str, artifacts_base_url: str) -> Iterable:
instance_suffix = '' instance_suffix = ''
if instance.name: if instance.name:
instance_suffix = f' ({instance.name})' instance_suffix = f' ({instance.name})'
@ -155,12 +152,12 @@ def testBridges(instance: Instance, bridge_cards: Iterable, with_upload: bool, w
status_is_ok = status == ''; status_is_ok = status == '';
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_artifacts and (not with_reduced_artifacts or not status_is_ok):
filename = f'{bridge_name} {form_number}{instance_suffix}{ARTIFACT_FILE_EXTENSION}' filename = f'{bridge_name} {form_number}{instance_suffix}{ARTIFACT_FILE_EXTENSION}'
filename = re.sub(r'[^a-z0-9 \_\-\.]', '', filename, flags=re.I).replace(' ', '_') filename = re.sub(r'[^a-z0-9 \_\-\.]', '', filename, flags=re.I).replace(' ', '_')
with open(file=f'{artifact_directory}/{filename}', mode='wb') as file: with open(file=f'{artifacts_directory}/{filename}', mode='wb') as file:
file.write(page_text) file.write(page_text)
artifact_url = f'{artifact_base_url}/{filename}' artifact_url = f'{artifacts_base_url}/{filename}'
table_rows.append(f'| {bridge_name} | [{form_number} {context_name}{instance_suffix}]({artifact_url}) | {status} |') 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
@ -177,8 +174,10 @@ def getFirstLine(value: str) -> str:
if __name__ == '__main__': if __name__ == '__main__':
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('--instances', nargs='+') parser.add_argument('--instances', nargs='+')
parser.add_argument('--no-upload', action='store_true') parser.add_argument('--no-artifacts', action='store_true')
parser.add_argument('--reduced-upload', action='store_true') parser.add_argument('--reduced-artifacts', action='store_true')
parser.add_argument('--artifacts-directory', default=os.getcwd())
parser.add_argument('--artifacts-base-url', default='')
parser.add_argument('--title', default='Pull request artifacts') parser.add_argument('--title', default='Pull request artifacts')
parser.add_argument('--output-file', default=os.getcwd() + '/comment.txt') parser.add_argument('--output-file', default=os.getcwd() + '/comment.txt')
args = parser.parse_args() args = parser.parse_args()
@ -201,8 +200,10 @@ if __name__ == '__main__':
instances.append(instance) instances.append(instance)
main( main(
instances=instances, instances=instances,
with_upload=not args.no_upload, with_artifacts=not args.no_artifacts,
with_reduced_upload=args.reduced_upload and not args.no_upload, with_reduced_artifacts=args.reduced_artifacts and not args.no_artifacts,
artifacts_directory=args.artifacts_directory,
artifacts_base_url=args.artifacts_base_url,
title=args.title, title=args.title,
output_file=args.output_file output_file=args.output_file
); );

View File

@ -5,24 +5,29 @@ on:
branches: [ master ] branches: [ master ]
jobs: jobs:
check-bridges: checks:
name: Check if bridges were changed name: Check if bridges were changed
runs-on: ubuntu-latest runs-on: ubuntu-latest
outputs: outputs:
BRIDGES: ${{ steps.check1.outputs.BRIDGES }} BRIDGES: ${{ steps.check_bridges.outputs.BRIDGES }}
WITH_UPLOAD: ${{ steps.check_upload.outputs.WITH_UPLOAD }}
steps: steps:
- name: Check number of bridges - name: Check number of bridges
id: check1 id: check_bridges
run: | run: |
PR=${{github.event.number}}; PR=${{github.event.number}};
wget https://patch-diff.githubusercontent.com/raw/$GITHUB_REPOSITORY/pull/$PR.patch; wget https://patch-diff.githubusercontent.com/raw/$GITHUB_REPOSITORY/pull/$PR.patch;
bridgeamount=$(cat $PR.patch | grep "\bbridges/[A-Za-z0-9]*Bridge\.php\b" | sed "s=.*\bbridges/\([A-Za-z0-9]*\)Bridge\.php\b.*=\1=g" | sort | uniq | wc -l); bridgeamount=$(cat $PR.patch | grep "\bbridges/[A-Za-z0-9]*Bridge\.php\b" | sed "s=.*\bbridges/\([A-Za-z0-9]*\)Bridge\.php\b.*=\1=g" | sort | uniq | wc -l);
echo "BRIDGES=$bridgeamount" >> "$GITHUB_OUTPUT" echo "BRIDGES=$bridgeamount" >> "$GITHUB_OUTPUT"
- name: "Check upload token secret RSSTESTER_ACTION is set"
id: check_upload
run: |
echo "WITH_UPLOAD=$([ -n "${{ secrets.RSSTESTER_ACTION }}" ] && echo "true" || echo "false")" >> "$GITHUB_OUTPUT"
test-pr: test-pr:
name: Generate HTML name: Generate HTML
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: check-bridges needs: checks
if: needs.check-bridges.outputs.BRIDGES > 0 if: needs.checks.outputs.BRIDGES > 0
env: env:
PYTHONUNBUFFERED: 1 PYTHONUNBUFFERED: 1
# Needs additional permissions https://github.com/actions/first-interaction/issues/10#issuecomment-1041402989 # Needs additional permissions https://github.com/actions/first-interaction/issues/10#issuecomment-1041402989
@ -60,14 +65,12 @@ jobs:
id: testrun id: testrun
run: | run: |
mkdir results; mkdir results;
python prtester.py; python prtester.py --artifacts-base-url "https://${{ github.repository_owner }}.github.io/${{ vars.ARTIFACTS_REPO || 'rss-bridge-tests' }}/prs/${{ github.event.number }}";
body="$(cat comment.txt)"; body="$(cat comment.txt)";
body="${body//'%'/'%25'}"; body="${body//'%'/'%25'}";
body="${body//$'\n'/'%0A'}"; body="${body//$'\n'/'%0A'}";
body="${body//$'\r'/'%0D'}"; body="${body//$'\r'/'%0D'}";
echo "bodylength=${#body}" >> $GITHUB_OUTPUT echo "bodylength=${#body}" >> $GITHUB_OUTPUT
env:
PR: ${{ github.event.number }}
- name: Upload generated tests - name: Upload generated tests
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
id: upload-generated-tests id: upload-generated-tests
@ -94,33 +97,31 @@ jobs:
name: Upload tests name: Upload tests
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: test-pr needs: test-pr
if: needs.checks.outputs.WITH_UPLOAD == 'true'
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
with: with:
repository: 'RSS-Bridge/rss-bridge-tests' repository: "${{ github.repository_owner }}/${{ vars.ARTIFACTS_REPO || 'rss-bridge-tests' }}"
ref: 'main' ref: 'main'
token: ${{ secrets.RSSTESTER_ACTION }} token: ${{ secrets.RSSTESTER_ACTION }}
- name: Setup git config - name: Setup git config
run: | run: |
git config --global user.name "GitHub Actions" git config --global user.name "GitHub Actions"
git config --global user.email "<>" git config --global user.email "<>"
- name: Download tests - name: Download tests
uses: actions/download-artifact@v4 uses: actions/download-artifact@v4
with: with:
name: tests name: tests
- name: Move tests - name: Move tests
run: | run: |
cd prs DIRECTORY="$GITHUB_WORKSPACE/prs/${{ github.event.number }}"
mkdir -p ${{github.event.number}} rm -rf $DIRECTORY
cd ${{github.event.number}} mkdir -p $DIRECTORY
cd $DIRECTORY
mv -f $GITHUB_WORKSPACE/*.html . mv -f $GITHUB_WORKSPACE/*.html .
- name: Commit and push generated tests - name: Commit and push generated tests
run: | run: |
export COMMIT_MESSAGE="Added tests for PR ${{github.event.number}}" export COMMIT_MESSAGE="Added tests for PR ${{github.event.number}}"
git add . git add .
git commit -m "$COMMIT_MESSAGE" git commit -m "$COMMIT_MESSAGE" || exit 0
git push git push