英文:
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 <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?
答案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 "$(${PWD}/.github/workflows/scripts/generate-check-i18n-matrix.sh)\n" >> $GITHUB_OUTPUT
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论