在我的GitHub action yaml文件中,最后有两个命令。第一个是yarn start (启动服务器),第二个是运行测试文件。
我通常在本地服务器上运行yarn start,然后等待前端和后端端口运行,然后才从另一个终端运行测试
但是在GitHub操作中,它会运行yarn start命令,然后立即运行测试脚本,因此当测试文件运行时,服务器不会侦听端口。这就是我的测试脚本失败的原因。如何确保测试脚本在yarn start完成后运行?
这是我的action.yml文件
name: "Github Actions Test"
on:
push:
branches:
- wip/checkout2
jobs:
test:
runs-on: ubuntu-latest
env:
PRISMA_ENDPOINT: ${{secrets.PRISMA_ENDPOINT}}
PRISMA_SECRET: ${{secrets.PRISMA_SECRET}}
steps:
- uses: actions/checkout@v1
- name: "Install Node"
uses: actions/setup-node@v1
with:
node-version: "12.x"
- name: "Install global packages"
run: npm install -g yarn prisma-cli concurrently mocha
- name: "Run docker Container"
run: docker-compose -f docker-compose.yml up --build -d
- name: "Install deps"
run: yarn install
- name: "prisma deploy"
run: yarn deploy:backend
- name: "Seed Backend"
run: yarn seed:backend
- name: "Build app"
run: yarn build
- name: "Start backend and frontend concurrently on background and run tests"
run: |
yarn start &
yarn test发布于 2020-04-11 21:10:55
发布于 2020-06-22 23:31:05
与@DannyB的建议类似,您可以在后台测试服务器是否正常运行,方法是等待几秒钟,然后使用curl测试网络连接。
例如:
- name: "Start backend and frontend concurrently on background and run tests"
run: |
yarn start &
sleep 10 &&
curl http://localhost:8000 &&
yarn test这样,您可以检查工作流作业的日志,并在执行测试之前确认服务器已启动并正在运行。
如果连接成功,默认情况下curl http://localhost:<PORT>会返回网页内容。您还可以在命令的末尾添加一个-I,以确保只返回请求头,并检查它是否具有HTTP/1.0 200 OK状态。
https://stackoverflow.com/questions/61078178
复制相似问题