bahmutov / bahmutov/grep-tests-from-pull-requests
Not picking up tests from pull request
- Dominant language
- JavaScript
- Stars
- 6
- Forks
- 2
- PR merge metrics
- No merged PRs in 30d
Description
Not sure if bug or I am doing something wrong, I get the following:
```
picked tests to run from app repo undefined
checking if there are tests to run in this repo pull request
pull request ref refs/heads/main
Cannot find the pull request number in the URL refs/heads/main
```
My plugin file uses the same code from [here](https://github.com/bahmutov/todomvc-tests-circleci/blob/main/cypress/plugins/index.js)
**Test repo workflow:**
```
name: Front-End Pull Request Tests
on:
workflow_dispatch:
inputs:
TEST_BRANCH:
description: 'By default, test the main branch'
type: string
default: 'main'
required: false
TEST_URL:
description: 'Test URL, default is dev.'
type: string
default: ''
# allow running selected tests once or multiple times
# using the cypress-grep plugin
# https://github.com/cypress-io/cypress-grep
GREP:
description: 'Tests to run using grep tags, default is all.'
type: string
default: ''
BURN:
description: 'Time to repeat tests, default is 1'
type: string
default: '1'
TEST_COMMIT:
description: 'Source commit SHA if known to report status checks'
type: string
default: ''
BRANCH_NAME:
description: 'Branch name.'
type: string
default: ''
jobs:
switch_branch:
permissions: write-all
runs-on: ubuntu-latest
# Changes the current branch to the latest commit on the specific branch.
# NOTE: if the branch does not exist, does nothing.
steps:
- name: Checkout branch ${{ github.event.inputs.BRANCH_NAME }}
if: ${{ github.event.inputs.BRANCH_NAME != '' }}
run: echo "Switching to branch ${{ github.event.inputs.BRANCH_NAME }} if it exists"
git checkout ${{ github.event.inputs.BRANCH_NAME }} || true
git pull origin ${{ github.event.inputs.BRANCH_NAME }} || true
print_git:
permissions: write-all
runs-on: ubuntu-latest
steps:
- name: Print current git info
run: echo current branch is ${{ github.event.inputs.BRANCH_NAME }}
echo current commit is ${{ github.event.pull_request.head.sha }}
info:
permissions: write-all
runs-on: ubuntu-latest
steps:
- name: Print variables
run: |
echo "TEST_BRANCH is ${{ github.event.inputs.TEST_BRANCH }}"
echo "TEST_URL is ${{ github.event.inputs.TEST_URL }}"
echo "GREP is ${{ github.event.inputs.GREP }}"
echo "BURN is ${{ github.event.inputs.BURN }}"
echo "TEST_COMMIT is ${{ github.event.inputs.TEST_COMMIT }}"
wait-for-deploy:
permissions: write-all
runs-on: ubuntu-latest
steps:
- name: Wait for deployment
run: |
echo "Using wait-on to check if the URL ${{ github.event.inputs.TEST_URL }} responds"
echo "See https://www.npmjs.com/package/wait-on"
npx wait-on --verbose \
--interval 10000 --timeout 480000 \
${{ github.event.inputs.TEST_URL }}
cypress-run:
permissions: write-all
if: success()
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
# run 3 copies of the current job in parallel
containers: [1, 2, 3]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: "18.7.0"
cache: "npm"
- run: npm install
- name: Set common commit status
run: |
if [[ ! -z "${{ github.event.inputs.TEST_COMMIT }}" ]]; then
echo "Setting commit status to pending"
export PERSONAL_GH_TOKEN=${{ secrets.PERSONAL_GH_TOKEN }}
npx set-gh-status \
--owner comapany-name --repo frontend \
--sha ${{ github.event.inputs.TEST_COMMIT }} --status pending \
--context "Cypress E2E tests" --description "Running tests..."
else
echo "No commit to set status for"
fi
- name:
Write the credentials.json and serviceAccountKeyDev.json file 📝
# use quotes around the secret, as its value
# is simply inserted as a string into the command
run: |
echo '${{ secrets.CYPRESS_ENV_CI }}' > cypress/config/credentials.json
echo '${{ secrets.CYPRESS_ENV_SERVICE_ACCOUNT_KEY }}' > cypress/plugins/serviceAccountKeyDev.json
# Run Cypress tests
- run: URL=${{ github.event.inputs.TEST_URL }} npm start -- --record --parallel --browser chrome --tag "dev, ${{ github.event.inputs.TEST_BRANCH }} --env grepTags=${{ github.event.inputs.GREP }}, burn=${{github.event.inputs.BURN }}, testCommit= ${{github.event.inputs.TEST_COMMIT}}"
env:
# and pass the Dashboard record key as an environment variable
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
GOOGLE_APPLICATION_CREDENTIALS: cypress/plugins/serviceAccountKeyDev.json
```
**Front-end repo (no tests):**
```
jobs:
build-and-deploy:
runs-on: ubuntu-latest
permissions:
actions: write
contents: "read"
id-token: "write"
env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
TEST_COMMIT: ${{ github.event.pull_request.head.sha }}
TEST_URL: ${{ format('https://{0}.preview-dev', inputs.DEPLOY_CHANNEL_ID) }}
- name: Trigger Cypress tests
uses: benc-uk/workflow-dispatch@v1.2.2
with:
workflow: front-end-pull-request.yml
ref: main
token: ${{ secrets.SRE_PAT }}
repo: company-name/company-core-cypress
inputs: '{ "BRANCH_NAME": "${{ env.BRANCH_NAME }}", "TEST_URL": "${{ env.TEST_URL }}", "TEST_COMMIT": "${{ env.TEST_COMMIT }}" }'
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with cypress/plugins/index.js from the linked example and compare its pull-request detection with the refs/heads/main value shown in the report. Then inspect the front-end-pull-request.yml workflow and the workflow-dispatch inputs, especially BRANCH_NAME and TEST_COMMIT. Done means determining why the pull request number is unavailable and documenting or correcting the test-selection flow.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cypress, github-actions, javascript
- Domain
- ci-cd, testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100