我创建了一个工作流来自动执行npm run deploy,每当我向回购的main分支推送一些东西,以保持Github页面的网站更新。
# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: Node.js CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run build --if-present
- run: npm test
- name: Deploy
run: |
git config --global user.name $user_name
git config --global user.email $user_email
git remote set-url origin https://${github_token}@github.com/${repository}
npm run deploy
env:
user_name: 'github-actions[bot]'
user_email: 'github-actions[bot]@users.noreply.github.com'
github_token: ${{ secrets.ACTIONS_DEPLOY_ACCESS_TOKEN }}
repository: ${{ github.repository }}因此,基本上,我使用了默认的node.js workflow,并添加了有关Github页面的部分,但是工作流始终失败。
我有以下错误:
build(12.x)
npm test
shell: /usr/bin/bash -e {0}
> react-portfolio@0.1.0 test /home/runner/work/my-portfolio/my-portfolio
> echo "Write tests! -> https://gatsby.dev/unit-testing" && exit 1
Write tests! -> https://gatsby.dev/unit-testing
npm ERR! Test failed. See above for more details.我怎么才能解决这个问题?
发布于 2021-08-18 10:51:55
回显“写测试!-> https://gatsby.dev/unit-testing" &&退出1
这是默认运行npm run test时的输出(在大多数启动器中):
"test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\" && exit 1"基本上,这是在提示echo消息并退出操作(&& exit 1)。这就是你的工作流程崩溃的原因。
因此,对于您当前的用例,我只需将工作流保留如下:
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run build --if-present将来,如果您运行测试,则需要更改命令以添加自定义单元测试,而不会跳过该过程。
https://stackoverflow.com/questions/68830885
复制相似问题