[prtester] Rework test storage (#4292)

* Update prtester.py

* Update prhtmlgenerator.yml
This commit is contained in:
Bocki 2024-10-16 15:36:57 +02:00 committed by GitHub
parent af26d845d9
commit 63c16e470d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 54 additions and 10 deletions

14
.github/prtester.py vendored
View file

@ -4,7 +4,7 @@ import re
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
from datetime import datetime from datetime import datetime
from typing import Iterable from typing import Iterable
import os.path import os
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
@ -39,6 +39,8 @@ def main(instances: Iterable[Instance], with_upload: bool, with_reduced_upload:
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) -> 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 = []
@ -140,10 +142,10 @@ 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):
termpad = requests.post(url="https://termpad.com/", data=page_text) filename = f'{os.getcwd()}/{instance.name}_{form_number}.html'
termpad_url = termpad.text.strip() with open(file=filename, mode='wb') as file:
termpad_url = termpad_url.replace('termpad.com/','termpad.com/raw/') file.write(page_text)
table_rows.append(f'| {bridge_name} | [{form_number} {context_name}{instance_suffix}]({termpad_url}) | {status} |') table_rows.append(f'| {bridge_name} | [{form_number} {context_name}{instance_suffix}]({tester_url}/{instance.name}_{form_number}.html) | {status} |')
form_number += 1 form_number += 1
return table_rows return table_rows
@ -187,4 +189,4 @@ if __name__ == '__main__':
with_reduced_upload=args.reduced_upload and not args.no_upload, with_reduced_upload=args.reduced_upload and not args.no_upload,
title=args.title, title=args.title,
output_file=args.output_file output_file=args.output_file
); );

View file

@ -13,7 +13,7 @@ jobs:
# 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
steps: steps:
- name: Check out self - name: Check out self
uses: actions/checkout@v3 uses: actions/checkout@v4
with: with:
ref: ${{github.event.pull_request.head.ref}} ref: ${{github.event.pull_request.head.ref}}
repository: ${{github.event.pull_request.head.repo.full_name}} repository: ${{github.event.pull_request.head.repo.full_name}}
@ -33,7 +33,7 @@ jobs:
docker build -t prbuild .; docker build -t prbuild .;
docker run -d -v $GITHUB_WORKSPACE/whitelist.txt:/app/whitelist.txt -v $GITHUB_WORKSPACE/DEBUG:/app/DEBUG -p 3001:80 prbuild docker run -d -v $GITHUB_WORKSPACE/whitelist.txt:/app/whitelist.txt -v $GITHUB_WORKSPACE/DEBUG:/app/DEBUG -p 3001:80 prbuild
- name: Setup python - name: Setup python
uses: actions/setup-python@v4 uses: actions/setup-python@v5
with: with:
python-version: '3.7' python-version: '3.7'
cache: 'pip' cache: 'pip'
@ -51,9 +51,17 @@ jobs:
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
uses: actions/upload-artifact@v4
id: upload-generated-tests
with:
name: tests
path: '*.html'
- name: Find Comment - name: Find Comment
if: ${{ steps.testrun.outputs.bodylength > 130 }} if: ${{ steps.testrun.outputs.bodylength > 130 }}
uses: peter-evans/find-comment@v2 uses: peter-evans/find-comment@v3
id: fc id: fc
with: with:
issue-number: ${{ github.event.pull_request.number }} issue-number: ${{ github.event.pull_request.number }}
@ -61,9 +69,43 @@ jobs:
body-includes: Pull request artifacts body-includes: Pull request artifacts
- name: Create or update comment - name: Create or update comment
if: ${{ steps.testrun.outputs.bodylength > 130 }} if: ${{ steps.testrun.outputs.bodylength > 130 }}
uses: peter-evans/create-or-update-comment@v2 uses: peter-evans/create-or-update-comment@v4
with: with:
comment-id: ${{ steps.fc.outputs.comment-id }} comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }} issue-number: ${{ github.event.pull_request.number }}
body-file: comment.txt body-file: comment.txt
edit-mode: replace edit-mode: replace
upload_tests:
name: Upload tests
runs-on: ubuntu-latest
needs: test-pr
steps:
- uses: actions/checkout@v4
with:
repository: 'RSS-Bridge/rss-bridge-tests'
ref: 'main'
token: ${{ secrets.RSSTESTER_ACTION }}
- name: Setup git config
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "<>"
- name: Download tests
uses: actions/download-artifact@v4
with:
name: tests
- name: Move tests
run: |
cd prs
mkdir -p ${{github.event.number}}
cd ${{github.event.number}}
mv -f $GITHUB_WORKSPACE/*.html .
- name: Commit and push generated tests
run: |
export COMMIT_MESSAGE="Added tests for PR ${{github.event.number}}"
git add .
git commit -m "$COMMIT_MESSAGE"
git push