|
| 1 | +name: <project-name-goes-here> Test Runner by Codebase Mentor |
| 2 | +on: |
| 3 | + pull_request_target: |
| 4 | + branches: ["main"] |
| 5 | +permissions: write-all |
| 6 | +jobs: |
| 7 | + check_is_signed_up: |
| 8 | + runs-on: ubuntu-latest |
| 9 | + strategy: |
| 10 | + fail-fast: true |
| 11 | + matrix: |
| 12 | + status: [200] |
| 13 | + steps: |
| 14 | + - name: Set up environment variables |
| 15 | + env: |
| 16 | + USER_ID: ${{ github.event.sender.id }} |
| 17 | + GH_TOKEN: ${{ github.token }} |
| 18 | + run: | |
| 19 | + echo "USER_ID=${USER_ID}" >> $GITHUB_ENV |
| 20 | + echo "GH_TOKEN=${GH_TOKEN}" >> $GITHUB_ENV |
| 21 | + - uses: actions/checkout@v3 |
| 22 | + - name: Call API endpoint |
| 23 | + if: ${{ matrix.status == 200 }} |
| 24 | + run: | |
| 25 | + status_code=$(curl -s -o /dev/null -w "%{http_code}" -X POST -d "${USER_ID}" https://jobsim-pr-user-check.deno.dev) |
| 26 | + if [ $status_code -ne 200 ]; then |
| 27 | + gh pr review ${{ github.event.number }} --comment --body "It looks like your GitHub account is not registered with JobSimulator.Dev. Please sign up at https://www.jobsimulator.dev to have your PR be tested automatically. Once you've signed up, close and open your PR to start the tests. Thanks!" |
| 28 | + exit 1 |
| 29 | + fi |
| 30 | + test: |
| 31 | + runs-on: ubuntu-latest |
| 32 | + container: |
| 33 | + image: mcr.microsoft.com/playwright:v1.31.0-focal |
| 34 | + needs: check_is_signed_up |
| 35 | + steps: |
| 36 | + - uses: actions/checkout@v3 |
| 37 | + with: |
| 38 | + ref: ${{ github.event.pull_request.head.sha }} # checkout the PR branch |
| 39 | + - uses: actions/setup-node@v3 # setup node |
| 40 | + with: |
| 41 | + node-version: 18 |
| 42 | + - run: rm -rf tests # remove any user provided test dir |
| 43 | + - uses: actions/checkout@v3 # checkout tests repo |
| 44 | + with: |
| 45 | + repository: developer-job-simulation/<project-name-goes-here>-tests |
| 46 | + path: tests |
| 47 | + - name: Install dependencies |
| 48 | + run: npm ci && cd tests && npm ci |
| 49 | + - name: start frontend |
| 50 | + run: npm run dev:frontend & |
| 51 | + - name: start backend |
| 52 | + run: npm run dev:backend > /logs.txt & |
| 53 | + - name: Run Tests |
| 54 | + run: node tests/test.js |
| 55 | + - name: Upload logs |
| 56 | + if: failure() |
| 57 | + uses: actions/upload-artifact@v3 |
| 58 | + with: |
| 59 | + name: logs |
| 60 | + path: /logs.txt |
| 61 | + - name: Upload screenshot |
| 62 | + if: failure() |
| 63 | + uses: actions/upload-artifact@v3 |
| 64 | + with: |
| 65 | + name: screenshot |
| 66 | + path: /test.png |
0 commit comments