Reputation: 1689
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?
Upvotes: 31
Views: 23383
Reputation: 6852
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.
Upvotes: 33