#DevHack: Running a background service on GitHub Actions
This post is over a year old, some of this information may be out of date.
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.
npm start &
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.
name: Run tests
on: push: branches: - main - dev
jobs: testing: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4
- uses: actions/setup-node@v4
- name: Install dependencies run: npm ci
- name: Start service run: npm start &
- name: Run tests run: npm test
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.
Related articles
Using the Office 365 CLI in your Azure DevOps CI/CD pipelines for SharePoint Framework solutions
Speed up your SharePoint Framework build and release process in Azure DevOps
Automate publishing process of MkDocs to Static Website hosting in Azure Storage with VSTS
Report issues or make changes on GitHub
Found a typo or issue in this article? Visit the GitHub repository to make changes or submit a bug report.
Comments
Let's build together
Manage content in VS Code
Present from VS Code