【问题标题】:GitHub actions using Node.JS and .NET in same job在同一作业中使用 Node.JS 和 .NET 的 GitHub 操作
【发布时间】:2021-02-01 09:06:47
【问题描述】:

我正在为 .NET 项目制作 JavaScript API。所以我需要 GitHub 操作来安装 Node.JS 和 .NET Core(2.1、2.2、3.0 或 3.1)。这可能吗?

这是我的 GitHub 操作配置 YAML 文件:

# This workflow will do a clean install of node dependencies, 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: [10.x, 12.x, 14.x]

    steps:
    - uses: actions/checkout@v2
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v1
      with:
        node-version: ${{ matrix.node-version }}
    - run: npm ci
    - run: npm run build
    - run: npm test

【问题讨论】:

    标签: javascript c# .net github-actions


    【解决方案1】:

    是的,这是可能的,你可以有多个矩阵参数:

    name: Node.js CI
    
    on:
      push:
        branches: [ main ]
      pull_request:
        branches: [ main ]
    
    jobs:
      build:
    
        runs-on: ubuntu-latest
    
        strategy:
          matrix:
            node-version: [10.x, 12.x, 14.x]
            dotnet: [ '2.1.811', '2.2.103', '3.0', '3.1.x' ]
    
        steps:
        - uses: actions/checkout@v2
        - name: Use Node.js ${{ matrix.node-version }}
          uses: actions/setup-node@v1
          with:
            node-version: ${{ matrix.node-version }}
        - name: Setup dotnet
          uses: actions/setup-dotnet@v1
          with:
            dotnet-version: ${{ matrix.dotnet }}
        - run: npm ci
        - run: npm run build
        - run: npm test
        - run: dotnet build <my project>
    

    【讨论】:

    • 是否也可以有多个with 参数。 with: dotnet-version: ${{ matrix.dotnet }} node-version: ${{ matrix.node-version }}
    猜你喜欢
    • 2022-08-23
    • 1970-01-01
    • 1970-01-01
    • 2020-05-02
    • 2022-09-28
    • 2021-04-10
    • 2021-12-05
    • 2021-07-29
    • 2021-06-08
    相关资源
    最近更新 更多