Skip to content

use regex matches in to replacement #278

@JanMalte

Description

@JanMalte

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions