Skip to content

Instantly share code, notes, and snippets.

@mpdude
Created January 18, 2022 20:52
Show Gist options
  • Save mpdude/d0f74f46c54e00c164177b096ff114e0 to your computer and use it in GitHub Desktop.
Save mpdude/d0f74f46c54e00c164177b096ff114e0 to your computer and use it in GitHub Desktop.
Use `jq` to tweak `composer.json` requirements

Change Symfony requirements in composer.json

This took me two hours on stackoverflow.com, 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.

#!/bin/bash
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