如何将与模式匹配的标签放入变量以供后续作业使用

huangapple go评论55阅读模式
英文:

how to put a label matching a pattern into a variable for later use within the job

问题

I want the PRs labeled with the following pattern I18n <product-id> <lang-tag>, i.e. I18n 1234 de_DE to run a job which extracts that label and set two variables: productID and langTag.

The two variables will be used as parameters of a script the actions executes:

Something like:

jobs:
    checkI18NTokensJob:
        if: startsWith(github.event.pull_request.labels.*.name, 'i18n')
        container: xxx
        env:
            FORCE_OUTPUT_MISSING_TRANSLATION_TO_FILE: true
        steps:
            - name: checkout
              uses: actions/checkout@v3
            - name: Install dependencies
              run: yarn
            - name: extract the parameters from the matching label
              # how to do it? 🔀
            - name: Check i18n tokens
              run: <my-script-here> <product-id> <lang tag>

Is that possible?

英文:

I want the PRs labeled with the following pattern I18n &lt;product-id&gt; &lt;lang-tag&gt;, i.e. I18n 1234 de_DE to run a job which extracts that label and set two variables: productID and langTag.
The two variables will be used as parameters of a script the actions executes:

Something like:

jobs:
    checkI18NTokensJob:
        if: startsWith(github.event.pull_request.labels.*.name, &#39;i18n&#39;)
        container: xxx
        env:
            FORCE_OUTPUT_MISSING_TRANSLATION_TO_FILE: true
        steps:
            - name: checkout
              uses: actions/checkout@v3
            - name: Install dependencies
              run: yarn
            - name: extract the parameters from the matching label
              # how to do it? &#129300;
            - name: Check i18n tokens
              run: &lt;my-script-here&gt; &lt;product-id&gt; &lt;lang tag&gt;

is that possible?

答案1

得分: 0

I've finally used an expansion variable along with toJson, which set an environment variable that a script can easily read and parse. Then, I can output the wanted result to $GITHUB_OUTPUT:

i.e.

jobs:
    generate-matrix:
        ...
        env:
            GITHUB_CONTEXT: ${{ toJson(github.event.pull_request.labels.*.name) }}
        steps:
            - name: set-matrix
              id: set-matrix
              run: echo "$(${PWD}/.github/workflows/scripts/generate-check-i18n-matrix.sh)\n" >> $GITHUB_OUTPUT
英文:

I've finally used an expansion variable along with toJson, which set an environament variable that a script can easily read and parse. Then, I can output the wanted result to $GITHUB_OUTPUT:

i.e.

jobs:
    generate-matrix:
        ...
        env:
            GITHUB_CONTEXT: ${{ toJson(github.event.pull_request.labels.*.name) }}
        steps:
            - name: set-matrix
              id: set-matrix
              run: echo &quot;$(${PWD}/.github/workflows/scripts/generate-check-i18n-matrix.sh)\n&quot; &gt;&gt; $GITHUB_OUTPUT

huangapple
  • 本文由 发表于 2023年6月26日 20:23:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/76556658.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定