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

Support arrays #63

Open
mrmeyers99 opened this issue Sep 24, 2021 · 2 comments
Open

Support arrays #63

mrmeyers99 opened this issue Sep 24, 2021 · 2 comments

Comments

@mrmeyers99
Copy link
Contributor

It would be nice if this supported arrays so that we could plugin the array as a matrix variable. Not sure if this is supported by Github Actions though. I'm thinking something like this:

  determine-regions:
    outputs:
      regions: ${{ steps.export.outputs.regions }}
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - id: var-map
        run: |
          echo ::set-output name=content::$(cat ./.github/env_vars.json)

      - uses: kanga333/variable-mapper@master
        id: export
        with:
          key: "${{ github.event.inputs.environment }}"
          map: ${{ steps.var-map.outputs.content }}
          export_to: log,output
  deploy:
    environment: ${{ github.event.inputs.environment }}
    needs: [ determine-regions ]
    runs-on: ubuntu-latest
    strategy:
      matrix:
        region: ${{ needs.determine-regions.outputs.regions }}
        stack: [a, b, c]
      fail-fast: true
      max-parallel: 1

where the env_vars.json looks like this:

{
 "production": {
   "regions": ["us-east-1", "us-west-2"]
 },
 "uat": {
   "regions": ["us-east-1", "us-west-2"]
 }
}

I guess the work around is to encode the JSON array in the string and then use the toJson function github provides, but it would be nice to not have to do that.

@kanga333
Copy link
Owner

kanga333 commented Oct 7, 2021

@mrmeyers99 Thank you for your report. Unfortunately, the output of Github Actions supports only string type. So, we can't export the output as an array. However, If we support export value as a JSON string, is it helpful for you?

It will be able to use like below.

determine-regions:
  outputs:
    regions: ${{ steps.export.outputs.regions }}
  runs-on: ubuntu-latest
  steps:
    - uses: actions/checkout@v2

    - id: var-map
      run: |
        echo ::set-output name=content::$(cat ./.github/env_vars.json)

    - uses: kanga333/variable-mapper@master
      id: export
      with:
        key: "${{ github.event.inputs.environment }}"
        map: |
          {
            "production": {
              "regions": ["us-east-1", "us-west-2"]
            },
            "uat": {
              "regions": ["us-east-1", "us-west-2"]
            }
          }
        export_to: log,output
        # Flag to serialize map value as a JSON string
        serialize_json: true
deploy:
  environment: ${{ github.event.inputs.environment }}
  needs: [ determine-regions ]
  runs-on: ubuntu-latest
  strategy:
    matrix:
      # using with fromJson, because outputs value is JSON string.
      region: ${{ fromJson(needs.determine-regions.outputs.regions) }}
      stack: [a, b, c]
    fail-fast: true
    max-parallel: 1

In this example, variable-mapper outputs the serialized JSON string ["us-east-1", "us-west-2"]. And user can use it with formJson. I will try to work on this problem.

@mrmeyers99
Copy link
Contributor Author

Yeah that would work, thanks!

@kanga333 kanga333 reopened this Nov 12, 2021
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

No branches or pull requests

2 participants