首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何创建一个工作流,以便在React & Gatsby应用程序上部署到Github页面?

如何创建一个工作流,以便在React & Gatsby应用程序上部署到Github页面?
EN

Stack Overflow用户
提问于 2021-08-18 10:43:29
回答 1查看 211关注 0票数 1

我创建了一个工作流来自动执行npm run deploy,每当我向回购的main分支推送一些东西,以保持Github页面的网站更新。

代码语言:javascript
复制
# 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页面的部分,但是工作流始终失败。

我有以下错误:

代码语言:javascript
复制
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.

我怎么才能解决这个问题?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-08-18 10:51:55

回显“写测试!-> https://gatsby.dev/unit-testing" &&退出1

这是默认运行npm run test时的输出(在大多数启动器中):

代码语言:javascript
复制
"test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\" && exit 1"

基本上,这是在提示echo消息并退出操作(&& exit 1)。这就是你的工作流程崩溃的原因。

因此,对于您当前的用例,我只需将工作流保留如下:

代码语言:javascript
复制
   - 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

将来,如果您运行测试,则需要更改命令以添加自定义单元测试,而不会跳过该过程。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68830885

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档