JSON output format for fauna-shell

I’ve been moving my CI/CD pipelines and Fauna management to FSL, but I’m running into issues with using the schema commands of fauna-shell in a CI/CD environment. I’m trying to achieve the following deployment pipeline for Fauna:

  1. run fauna schema push to stage the newly committed schema.
  2. run fauna schema status to poll for the index build status and wait until the schema is ready to commit, or if the build fails or otherwise doesn’t complete, run fauna schema abandon to abandon the schema changes and fail the pipeline.
  3. run fauna schema commit to commit the changes. run fauna schema abandon if the commit fails and fail the pipeline.
  4. deploy other code changes.

I’m running into issues with this because fauna-shell does not provide a machine readable output format for its commands to key off of in automation. This is leading me to hack together status checks by greping the output of the command for specific strings. This is brittle and prone to error as the command text output is meant for humans and not intended to be a stable machine interface.

Please consider adding a machine readable output format flag to dump the output in a stable JSON format. This can be easily read in CI/CD using something like jq, and would allow easier integration of the fauna schema suite of commands into CI/CD. I would recommend enabling this output format for all commands, not just the fauna schema ones.

Hi @rcausey,

Thanks for your input here. It’s a great suggestion. Making the output of the CLI easily machine readible is important, and we’ll factor that into our development plans for the CLI.

For example, here’s the hacky workaround I have to do in Gitlab CI to make it work using grep:

script:
  - fauna schema diff --no-input --secret $FAUNA_SECRET_KEY --dir $CI_PROJECT_DIR/fauna_schema
  - fauna schema push --no-input --secret $FAUNA_SECRET_KEY --dir $CI_PROJECT_DIR/fauna_schema
  - "sleep_amount=1;
      until fauna schema status --no-input --secret $FAUNA_SECRET_KEY --dir $CI_PROJECT_DIR/fauna_schema
        | grep -e \"Staged status: ready\" -e \"Staged changes: none\"
        || [ \"$sleep_amount\" -gt \"20\" ];
      do echo \"Sleeping for $sleep_amount\";
      sleep $sleep_amount;
      sleep_amount=$((sleep_amount + 1));
      done"
  - "if fauna schema status --no-input --secret $FAUNA_SECRET_KEY --dir $CI_PROJECT_DIR/fauna_schema
        | grep -e \"Staged status: ready\" -e \"Staged changes: none\";
      then echo \"Schema changes exist or there are no changes.\";
        if fauna schema status --no-input --secret $FAUNA_SECRET_KEY --dir $CI_PROJECT_DIR/fauna_schema
          | grep \"Staged changes: none\";
        then echo \"No schema changes.\";
        else echo \"Committing schema changes.\";
          if fauna schema commit --no-input --secret $FAUNA_SECRET_KEY --dir $CI_PROJECT_DIR/fauna_schema;
          then echo \"Schema commit successful.\";
          else echo \"Failed to commit schema. Abandoning the staged schema.\";
          fauna schema abandon --no-input --secret $FAUNA_SECRET_KEY --dir $CI_PROJECT_DIR/fauna_schema;
          exit 1;
          fi;
        fi;
      else echo \"Checking the status of schema failed or it is in an unexpected status. Abandoning schema.\";
      fauna schema abandon --no-input --secret $FAUNA_SECRET_KEY --dir $CI_PROJECT_DIR/fauna_schema;
      exit 1;
      fi"