github-action-json-property icon indicating copy to clipboard operation
github-action-json-property copied to clipboard

Property value contains brackets

Open jan-cerny opened this issue 3 years ago • 2 comments

After the version 0.1.20 of the notiz-dev/github-action-json-property action has been released, we experience a different behavior of the .prop property which causes our CI jobs to fail. The value returned by this property now contains brackets [ and ] which weren't there with the previous version.

An example of a workflow affected by this change is https://github.com/ComplianceAsCode/content/blob/master/.github/workflows/automatus-cs9.yaml

In our workflow, we have a JSON output.json that can look for example like this:

{"rules": ["accounts_passwords_pam_faillock_dir"], "product": "rhel8", "bash": "True", "ansible": "True"}

Then, we have a step that is using notiz-dev/github-action-json-property:


      - name: Get rule ids to be tested
        if: ${{ steps.ctf.outputs.CTF_OUTPUT_SIZE != '0' }}
        id: rules
        uses: notiz-dev/github-action-json-property@release
        with:
          path: 'output.json'
          prop_path: 'rules'

Then, we use this step in another step in a run command as ${{join(steps.rules.outputs.prop)}}.

      - name: Run tests in a container - Ansible
        if: ${{ steps.ansible.outputs.prop == 'True' && steps.ctf.outputs.CTF_OUTPUT_SIZE != '0' }}
        run: tests/test_rule_in_container.sh --dontclean --logdir logs_ansible --remediate-using ansible --name ssg_test_suite --datastream $DATASTREAM ${{join(steps.rules.outputs.prop)}}
        env:
          ADDITIONAL_TEST_OPTIONS: "--duplicate-templates --add-product-to-fips-certified centos9 --product rhel9"

Previously, the string returned by ${{join(steps.rules.outputs.prop)}} didn't contain [ and ].

For example, in the job https://github.com/ComplianceAsCode/content/actions/runs/3036087676/jobs/4887043536 for the JSON {"rules": ["accounts_umask_etc_profile"], "product": "rhel8", "bash": "False", "ansible": "True"} it returned accounts_umask_etc_profile.

After the update, the format changes and looks like the raw JSON with [ and ] and quotes.

For example, in the job https://github.com/ComplianceAsCode/content/actions/runs/3418678327/jobs/5691495274 for the JSON {"rules": ["accounts_passwords_pam_faillock_dir"], "product": "rhel8", "bash": "True", "ansible": "True"} it returned ["accounts_passwords_pam_faillock_dir"].

For this moment, we have fixed this by using the older version v0.1.0 explicitly in our GH actions workflows.

But what would be the proper fix? Should we use the output in a different way? Or can it be a bug in your tool?

Thanks for any advice.

jan-cerny avatar Nov 09 '22 12:11 jan-cerny

Previously, the string returned by ${{join(steps.rules.outputs.prop)}} didn't contain [ and ].

Is it perhaps returning the prop value as string instead of parsed now? (@jan-cerny you could attempt ${{join(fromJson(steps.rules.outputs.prop))}} instead to confirm this)

jlsjonas avatar Dec 23 '22 14:12 jlsjonas

Previously, the string returned by ${{join(steps.rules.outputs.prop)}} didn't contain [ and ].

Is it perhaps returning the prop value as string instead of parsed now? (@jan-cerny you could attempt ${{join(fromJson(steps.rules.outputs.prop))}} instead to confirm this)

It seems to work. Let's see how it goes: https://github.com/ComplianceAsCode/content/pull/11019/commits/5ffe39ff9fb047c4a0e7ee1de183e77121bd1064

ggbecker avatar Sep 13 '23 17:09 ggbecker