name: 'PR Testing' on: pull_request_target: branches: [ master ] jobs: checks: name: Check if bridges were changed runs-on: ubuntu-latest outputs: BRIDGES: ${{ steps.check_bridges.outputs.BRIDGES }} WITH_UPLOAD: ${{ steps.check_upload.outputs.WITH_UPLOAD }} steps: - name: Check number of bridges id: check_bridges run: | PR=${{ github.event.number || 'none' }}; 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: checks if: needs.checks.outputs.BRIDGES > 0 env: PYTHONUNBUFFERED: 1 # Needs additional permissions https://github.com/actions/first-interaction/issues/10#issuecomment-1041402989 steps: - name: Check out self uses: actions/checkout@v4 with: ref: ${{github.event.pull_request.head.ref}} repository: ${{github.event.pull_request.head.repo.full_name}} - name: Check out rss-bridge run: | PR=${{ github.event.number || 'none' }}; wget -O requirements.txt https://raw.githubusercontent.com/$GITHUB_REPOSITORY/${{ github.event.pull_request.base.ref }}/.github/prtester-requirements.txt; wget https://raw.githubusercontent.com/$GITHUB_REPOSITORY/${{ github.event.pull_request.base.ref }}/.github/prtester.py; wget https://patch-diff.githubusercontent.com/raw/$GITHUB_REPOSITORY/pull/$PR.patch; touch DEBUG; 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 > whitelist.txt - name: Start Docker - Current run: | docker run -d -v $GITHUB_WORKSPACE/whitelist.txt:/app/whitelist.txt -v $GITHUB_WORKSPACE/DEBUG:/app/DEBUG -p 3000:80 ghcr.io/rss-bridge/rss-bridge:latest - name: Start Docker - PR run: | 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 - name: Setup python uses: actions/setup-python@v5 with: python-version: '3.13' cache: 'pip' - name: Install requirements run: | cd $GITHUB_WORKSPACE pip install -r requirements.txt - name: Run bridge tests id: testrun run: | mkdir results; python prtester.py --artifacts-base-url "https://${{ github.repository_owner }}.github.io/${{ vars.ARTIFACTS_REPO || 'rss-bridge-tests' }}/prs/${{ github.event.number || 'none' }}"; body="$(cat comment.txt)"; body="${body//'%'/'%25'}"; body="${body//$'\n'/'%0A'}"; body="${body//$'\r'/'%0D'}"; echo "bodylength=${#body}" >> $GITHUB_OUTPUT - name: Upload generated tests uses: actions/upload-artifact@v4 id: upload-generated-tests with: name: tests path: '*.html' - name: Find Comment if: ${{ steps.testrun.outputs.bodylength > 130 }} uses: peter-evans/find-comment@v3 id: fc with: issue-number: ${{ github.event.pull_request.number }} comment-author: 'github-actions[bot]' body-includes: Pull request artifacts - name: Create or update comment if: ${{ steps.testrun.outputs.bodylength > 130 }} uses: peter-evans/create-or-update-comment@v4 with: comment-id: ${{ steps.fc.outputs.comment-id }} issue-number: ${{ github.event.pull_request.number }} body-file: comment.txt edit-mode: replace upload_tests: name: Upload tests runs-on: ubuntu-latest needs: test-pr if: needs.checks.outputs.WITH_UPLOAD == 'true' steps: - uses: actions/checkout@v4 with: 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: | DIRECTORY="$GITHUB_WORKSPACE/prs/${{ github.event.number || 'none' }}" 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 || 'none' }}" git add . git commit -m "$COMMIT_MESSAGE" || exit 0 git push