My library is about http server. I want to test it with github actions.
The code in my yml file looks like this:
jobs: linux: runs-on: ubuntu-18.04 steps: - name: build run: | nohup start-http-server 8000 & curl http://127.0.0.1:8000/
The server can be started successfully, but curl fails.
I also tested with python and it failed again:
jobs: linux: runs-on: ubuntu-18.04 steps: - name: build run: | nohup python -m SimpleHTTPServer & curl http://127.0.0.1:8000/
What should I do?
Can you share your repository with us? So that we can check the full configurations of your workflow and the detailed debug logs of the workflow run to analyze the root cause.
In addition, did you try the same commands on your local Linux machine (or VM) to see if they can work as expected?
Is here, a very simple demo:
I have tried it on my local computer and everything works fine.
I've looked at the workflow log at https://github.com/ygj6/verify/runs/441227761, an I think here's your problem (from the Python process):
socket.error: [Errno 13] Permission denied
According to the workflow file you're trying to bind port 80 as a non-root user, which is not allowed. I'd recommend using another port (>1000). If port 80 is required for some reason you could try running your job in a container, or the relevant command with sudo.
In your latest run (https://github.com/ygj6/verify/runs/445583346) the "permission denied" error from Python is gone at least.
My guess is that Curl tries to connect (and fails) before the Python server is ready to accept connections. In the previous log the Curl error also appeared before Python reported its own problem. To check if that's the issue you could try adding something like "sleep 5" between the commands. If that helps I'd recommend replacing the fixed sleep with something that actually waits for the service to be ready.
Putting that in the background and running curl will basically hit that immediately. Are you sure that your server actually is able to start and bind to the port before you try to hit it? Does a `sleep` help?