如何在 github 操作中修复管道
Posted
技术标签:
【中文标题】如何在 github 操作中修复管道【英文标题】:how to fix pipeline in github actions 【发布时间】:2021-12-22 13:10:12 【问题描述】:我从未在 github 操作中编写管道,我被要求为拉取请求创建管道,我做了一些事情:
# This is a basic workflow to help you get started with Actions
name: pipeline_action_on_pull_request
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the master branch
pull_request:
branches:
- dev
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
lint_and_test:
# The type of runner that the job will run on
runs-on: linux
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '16'
- run: npm install
- run: npm lint
- run: npm test
但在拉取请求后它的输出:
No runner matching the specified labels was found: linux
【问题讨论】:
"linux" 未列在 docs.github.com/en/actions/learn-github-actions/… 中,因此除非您有自托管运行器(在这种情况下,您需要查看它们的实际名称),否则这是行不通的。跨度> 【参考方案1】:我准备了一个 esquema 来部署到生产环境,你需要像这样使用 npm install、Clean .cache、Build Development 等:
jobs:
build:
if: contains(github.ref, 'development') || contains(github.ref, 'production')
name: Build
runs-on: ubuntu-latest
steps:
- name: node version
run: node -v
- run: echo $ github.ref
- name: Checkout Repo
uses: actions/checkout@v2
- name: Install dependencies
run: npm install
- name: Build Development
if: contains(github.ref, 'development')
run: npm run build
通过文档https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idruns-on
GitHub 托管的运行器 如果您使用 GitHub 托管的运行器,每个作业都会运行 在由 runs-on 指定的虚拟环境的新实例中。
可用的 GitHub 托管运行器类型有:
虚拟环境 YAML 工作流标签 Notes Windows Server 2022[beta] windows-2022 windows-latest 标签目前使用的是 Windows Server 2019 运行器映像。 Windows Server 2019 最新版 或 windows-2019 Windows Server 2016[已弃用] windows-2016 迁移 到 Windows 2019 或 Windows 2022。有关详细信息,请参阅博客 邮政。 Ubuntu 20.04 ubuntu-latest 或 ubuntu-20.04 Ubuntu 18.04 ubuntu-18.04 macOS Big Sur 11 macos-11 macos-latest 标签目前使用 macOS 10.15 runner 镜像。 macOS 卡塔利娜 10.15 macos-latest 或 macos-10.15
【讨论】:
npm run build
和- run: npm lint - run: npm test
一样吗?
@igaro4ak337 我认为是一样的,因为构建应该生成所有测试以上是关于如何在 github 操作中修复管道的主要内容,如果未能解决你的问题,请参考以下文章
如何使用可重用的Github Actions和Heroku构建简单的部署管道
如何使用 cypress github 操作修复缺少的构建脚本?