Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce function count() for arrays & strings #864

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sshymko
Copy link

@sshymko sshymko commented Dec 17, 2020

Usage example with dynamic jobs:

name: Dynamic jobs
on:
  workflow_dispatch:
    inputs:
      versions:   
jobs:
  deploy:
    name: Deploy ${{ count(fromJson(github.event.inputs.versions)) }} versions
    runs-on: ubuntu-latest
    strategy:
      matrix:
        version: ${{ fromJson(github.event.inputs.versions) }}
    name: Deploy version ${{ matrix.version }}
    steps:
      - run: echo "hello world"

Sample input:

{
  "versions": "[\"1\",\"2\",\"3\"]"
}

@sshymko
Copy link
Author

sshymko commented Dec 17, 2020

I'd prefer à la JavaScript property syntax array.length over the count() function, but have no idea how to implement that.

Desirable syntax:

${{ fromJson(github.event.inputs.versions).length }}
${{ (fromJson(steps.example.outputs.json).items.*).length }}

Note that the filtering items.* converts object properties (hash map) to an array.

@sshymko
Copy link
Author

sshymko commented Dec 17, 2020

See related #865 introducing split() function to parse arrays from strings instead of JSON.

@JoannaaKL JoannaaKL requested a review from a team as a code owner June 1, 2023 06:46
@AllanOricil
Copy link

Why haven't this been merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants