Skip to content

Instantly share code, notes, and snippets.

Created January 18, 2022 20:52
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Use `jq` to tweak `composer.json` requirements

Change Symfony requirements in composer.json

This took me two hours on, so I'm going to document it to future me:

In the composer.json require section, for all packages starting with symfony/, but not for symfony/monolog-bundle, change the required version to the value of the $VERSION environment variable.

Write out the updated composer.json file in a way that works _without sponge`, which is not installed on GitHub Action runners by default.

cat <<< $(jq --arg version $VERSION '.require |= with_entries(if ((.key != "symfony/monolog-bundle") and (.key|test("^symfony/"))) then .value=$version else . end)' < composer.json) > composer.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment