Skip to content

Instantly share code, notes, and snippets.

@mxr576
Forked from mpdude/README.md
Created November 7, 2022 12:34
Show Gist options
  • Save mxr576/9918b88212dc424361b78ba595e15117 to your computer and use it in GitHub Desktop.
Save mxr576/9918b88212dc424361b78ba595e15117 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