Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a command in background in Windows GitHub Action

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:

  • full repository with this code
  • failed run
like image 611
Ribtoks Avatar asked Feb 22 '26 17:02

Ribtoks


1 Answers

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"
like image 108
VonC Avatar answered Feb 24 '26 11:02

VonC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!