semantic-release-replace-plugin icon indicating copy to clipboard operation
semantic-release-replace-plugin copied to clipboard

use regex matches in `to` replacement

Open JanMalte opened this issue 6 months ago • 0 comments

How can I use regex match groups and reference them in the to config?

Example

services:
  app:
    image: namespace/project:1.0.0
    command: "run-server"
  db:
    image: postgres:17.5
module.exports = {
    branches: ["main"],
    plugins: [
        // ...
        [
            "semantic-release-replace-plugin",
            {
                replacements: [
                    {
                        files: ["docker-compose.yml"],
                        from: '^(?<ident>\s*)image:\s*(?<registry>.*)?(?<image>namespace\/project):(.*)\s*$',
                        to: '${ident}image: ${registry}${image}:${nextRelease.version}',
                        results: [
                            {
                                file: "pyproject.toml",
                                hasChanged: true,
                                numMatches: 1,
                                numReplacements: 1,
                            },
                        ],
                        countMatches: true,
                    },
                ],
            },
        ],
        // ...
    ],
};

Expected for 1.0.0 to 1.1.0

services:
  app:
    image: namespace/project:1.1.0
    command: "run-server"
  db:
    image: postgres:17.5

JanMalte avatar Jun 08 '25 19:06 JanMalte