github-action icon indicating copy to clipboard operation
github-action copied to clipboard

Port conflict on parallel runs

Open qWici opened this issue 3 years ago • 0 comments

I have a React application that is built with Vite. If I don't specify a specific port for the preview application, the port is taken randomly. And then Cypress doesn't know which host/port to go to. If I specify a specific port I get an error that the port is already in use. I don't really know what to do and how to get around this.

My action config:

name: Node.js CI

# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the master branch
  pull_request:
    branches: [ master ]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    strategy:
      fail-fast: false
      matrix:
        node-version: [16.x, 17.x]
        containers: [1, 2, 3, 4]

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
    - uses: actions/checkout@v3
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v3
      with:
        node-version: ${{ matrix.node-version }}
    - run: npm ci
    - name: Cypress run
      uses: cypress-io/github-action@v2
      with:
        record: true
        parallel: true
        group: 'Actions example'
        build: npm run cypress:build
        start: npm run serve:ci
      env:
        CYPRESS_host: http://localhost
        CYPRESS_port: 41732
        CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

package.json

...
"scripts": {
	"serve:ci": "vite preview --port=41732",
}
...

qWici avatar Apr 02 '22 16:04 qWici