Running background services on GitHub Actions can be helpful when you want to run some tests. For instance, start up the local server before running the tests. In my case, I was testing out Dev Proxy on GitHub Actions to see if I could use it in combination with Playwright to provide my mocks for my tests. Unfortunately, GitHub Actions does not support running multiple steps in parallel, so I had to find a workaround.
When searching for ways to run background processes on Linux environments, I found a solution to using an ampersand &
at the end of the command.
Using the ampersand starts the service in the background and allows you to continue with the following command.
|
|
infoThanks Michael Heap for confirming that this is the right approach.
Starting a background service in your GitHub Actions workflow
The same approach can be used in GitHub Actions. When you use the ampersand &
in your step, it starts up the service and continues to the next step in your workflow.
Here is an example of how to start a service in the background and then run your tests.
|
|
In the above example, the npm start &
command starts the local server in the background and continues to the next step: running the tests.
I hope this helps you when running a background service on GitHub Actions.