[英]Combine dynamic Github Workflow matrix with input values and predefined values
我有一個有效的 GitHub 工作流,它使用矩陣並構建所有定義的產品。
name: Build
on:
push:
tags:
- "*"
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
product: [yellow, green, black]
limits: [10,20,50,100]
steps:
- uses: actions/checkout@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
...
現在我希望能夠手動觸發構建過程並使用輸入值來僅構建我想要的產品。 我可以在 Github 界面上輸入值,但看起來使用它們的語法不正確。
構建:.github#L1 評估作業“構建”的“策略”時出錯。 .github/workflows/build.yml(第 27 行,第 18 行):意外值“黃色”,.github/workflows/build.yml(第 28 行,第 17 行):意外值“50”
此外,如何將所有預定義產品的先前自動構建與通過輸入在一個工作流中手動完成的構建結合起來?
name: Build
on:
push:
tags:
- "*"
workflow_dispatch:
inputs:
product:
description: "Product"
default: "yellow"
limit:
description: "Limit"
default: "50"
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
product: ${{ github.event.inputs.product}}
limits: ${{ github.event.inputs.limit }}
# product: [yellow, green, black]
# limits: [10,20,50,100]
steps:
- uses: actions/checkout@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
...
矩陣值必須是列表,例如[yellow, green, black]
。 您輸入的名為 product 的不是列表,而是字符串"yellow"
。 不幸的是,輸入數據類型只能是string、choice、boolean 或 environment之一。
但是,您可以將字符串'["yellow", "green", "black"]'
轉換為 json 列表值,並使用fromJSON(value)
方法將其指定為矩陣值。 fromJSON 文檔中的第一個示例顯示將 json 語法列表計算為一個作業的 output 中的字符串,並在下一個作業的矩陣策略中使用它。
該示例顯示使用作業中計算的 output。 我已經嘗試使用工作流調度輸入,例如您的問題中的以下內容:
on:
workflow_dispatch:
inputs:
products:
description: "List of Products"
default: '["yellow"]'
limits:
description: "List of limits"
default: '[50]'
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
product: ${{ fromJSON(github.event.inputs.products)}}
limits: ${{ fromJSON(github.event.inputs.limits) }}
好像您在輸入名稱中打錯了字(應該是product
而不是edition
)?
strategy:
matrix:
edition: ${{ github.event.inputs.product }}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.