Skip to content

Commit

Permalink
[prtester] support forks to upload to their own "rss-bridge-tests"
Browse files Browse the repository at this point in the history
add parameter "--artifact-base-url" and "--artifact-directory"
  • Loading branch information
User123698745 committed Oct 20, 2024
1 parent c3dc46a commit cb36bc2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 34 deletions.
35 changes: 18 additions & 17 deletions .github/prtester.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,10 @@ class Instance:
name = ''
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()

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):
for file in glob.glob(f'*{ARTIFACT_FILE_EXTENSION}', root_dir=artifacts_directory):
os.remove(file)

table_rows = []
Expand All @@ -38,10 +35,10 @@ def main(instances: Iterable[Instance], with_upload: bool, with_reduced_upload:
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_artifacts=with_artifacts,
with_reduced_artifacts=with_reduced_artifacts,
artifacts_directory=artifacts_directory,
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:
table_rows_value = '\n'.join(sorted(table_rows))
file.write(f'''
Expand All @@ -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")}*
'''.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 = ''
if instance.name:
instance_suffix = f' ({instance.name})'
Expand Down Expand Up @@ -155,12 +152,12 @@ def testBridges(instance: Instance, bridge_cards: Iterable, with_upload: bool, w
status_is_ok = status == '';
if status_is_ok:
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 = 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)
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} |')
form_number += 1
return table_rows
Expand All @@ -177,8 +174,10 @@ def getFirstLine(value: str) -> str:
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--instances', nargs='+')
parser.add_argument('--no-upload', action='store_true')
parser.add_argument('--reduced-upload', action='store_true')
parser.add_argument('--no-artifacts', 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('--output-file', default=os.getcwd() + '/comment.txt')
args = parser.parse_args()
Expand All @@ -201,8 +200,10 @@ def getFirstLine(value: str) -> str:
instances.append(instance)
main(
instances=instances,
with_upload=not args.no_upload,
with_reduced_upload=args.reduced_upload and not args.no_upload,
with_artifacts=not args.no_artifacts,
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,
output_file=args.output_file
);
35 changes: 18 additions & 17 deletions .github/workflows/prhtmlgenerator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,29 @@ on:
branches: [ master ]

jobs:
check-bridges:
checks:
name: Check if bridges were changed
runs-on: ubuntu-latest
outputs:
BRIDGES: ${{ steps.check1.outputs.BRIDGES }}
BRIDGES: ${{ steps.check_bridges.outputs.BRIDGES }}
WITH_UPLOAD: ${{ steps.check_upload.outputs.WITH_UPLOAD }}
steps:
- name: Check number of bridges
id: check1
id: check_bridges
run: |
PR=${{github.event.number}};
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);
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:
name: Generate HTML
runs-on: ubuntu-latest
needs: check-bridges
if: needs.check-bridges.outputs.BRIDGES > 0
needs: checks
if: needs.checks.outputs.BRIDGES > 0
env:
PYTHONUNBUFFERED: 1
# Needs additional permissions https://github.com/actions/first-interaction/issues/10#issuecomment-1041402989
Expand Down Expand Up @@ -60,14 +65,12 @@ jobs:
id: testrun
run: |
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="${body//'%'/'%25'}";
body="${body//$'\n'/'%0A'}";
body="${body//$'\r'/'%0D'}";
echo "bodylength=${#body}" >> $GITHUB_OUTPUT
env:
PR: ${{ github.event.number }}
- name: Upload generated tests
uses: actions/upload-artifact@v4
id: upload-generated-tests
Expand All @@ -94,33 +97,31 @@ jobs:
name: Upload tests
runs-on: ubuntu-latest
needs: test-pr
if: needs.checks.outputs.WITH_UPLOAD == 'true'
steps:
- uses: actions/checkout@v4
with:
repository: 'RSS-Bridge/rss-bridge-tests'
repository: "${{ github.repository_owner }}/${{ vars.ARTIFACTS_REPO || '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}}
DIRECTORY="$GITHUB_WORKSPACE/prs/${{ github.event.number }}"
rm -rf $DIRECTORY
mkdir -p $DIRECTORY
cd $DIRECTORY
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 commit -m "$COMMIT_MESSAGE" || exit 0
git push

0 comments on commit cb36bc2

Please sign in to comment.