Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use array input for a custom GitHub Actions

I'm working on a GitHub Action workflow that uses an array for input.

I used this solution to simulate an array:

      - uses: actions/my-custom-ci
        with:
          subdirectories: src/main/java src/test/java

But I want to use a solution like this:

      - uses: actions/my-custom-ci
        with:
          subdirectories: 
                - src/main/java 
                - src/test/java

Is it possible to use an array input for custom GitHub Actions? If yes, how can we use an array input for custom GitHub Actions?

like image 875
ThrowsError Avatar asked Sep 02 '25 04:09

ThrowsError


1 Answers

At the time of writing this answer, GitHub Actions doesn't support array types as input for actions. It only supports string | number | boolean (schema: with ref: definitions/env). So your approach is a valid workaround for now.

Just note that GitHub runners have jq installed by default, and GitHub Actions offers methods like fromJSON, toJSON and join, which may help you create a cleaner solution in case you want to generate a dynamic input of your custom action.

You can check google-github-actions/get-secretmanager-secrets's implementation where they accept multiple inputs specified by line breaks, not as a yaml array:

    - id: 'secrets'
      uses: 'google-github-actions/get-secretmanager-secrets@v1'
      with:
        secrets: |-
          token:my-project/docker-registry-token
          anotherOne:my-project/a-secret
          anotherOneToo:my-project/another-secret

Definitely, this might not be what you want to achieve. And it might not be worth refactoring your action. But it's a workaround for now.

like image 67
Fcmam5 Avatar answered Sep 05 '25 00:09

Fcmam5