2

I would like to serve local files through a web-server and execute some tests inside GitHub Action that runs Windows, but I cannot make it run server in the background

Here's my setup:

name: CI Windows

on:
  push:
    branches:
    - '*'

jobs:
  build:
    runs-on: windows-2019

    steps:
    - uses: actions/checkout@v1

    - uses: actions/setup-python@v2
      with:
        python-version: '3.x'

    - name: Test local api
      run: |
        cmd /c "START /b run-local-api-server.bat"
        curl -X GET "http://localhost:9195/README.md"

And run-local-api-server.bat script:

@echo off

python3 -m http.server 9195

The error I get is curl: (7) Failed to connect to localhost port 9195: Connection refused.

Links:

Ribtoks
  • 6,634
  • 1
  • 25
  • 37

1 Answers1

2

Check first if adding a small pause would help.
And check the expected port is listening.

    - name: Test local api
      run: |
        cmd /c "START /b run-local-api-server.bat"
        ping 127.0.0.1 -n 6 > nul
        netstat -o -n -a | findstr 9195
        curl -X GET "http://localhost:9195/README.md"
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Adding the pause helped – Ribtoks Apr 02 '21 at 18:40
  • also, the way you proposed to add pause did not work on GitHub Action: `FileStream was asked to open a device that was not a file` – Ribtoks Apr 02 '21 at 18:50
  • @Ribtoks I understand. I believe there are other ways to simulate a pause in a bat file though. Starting wiht the vanilla SLEEP (https://stackoverflow.com/a/48000823/6309) – VonC Apr 02 '21 at 18:52