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

matches not found in google action

Open shaunc opened this issue 3 years ago • 3 comments

I am trying to use semantic-release-replace-plugin to change version in pyproject.toml and src/demo/__init__.py In the first I have:

[tool.poetry]
...
version = "0.1.5"

In the second:

__version__ = "0.1.5"

My semantic-release config:

branches:
  - main
  - {name: alpha, prerelease: true}
  - {name: beta, prerelease: true}
plugins:
  - "@semantic-release/commit-analyzer"
  - "@semantic-release/release-notes-generator"
  - - "@google/semantic-release-replace-plugin"
    - replacements:
      - files:
        - pyproject.toml
        from: 'version = ".*"'
        to: 'version = "${nextRelease.version}"'
        results:
          - file: pyproject.toml
            hasChanged: true
            numMatches: 1
            numReplacements: 1
        countMatches: true
      - files:
        - src/demo/__init__.py
        from: '__VERSION__ = ".*"'
        to: '__VERSION__ = "${nextRelease.version}"'
        results:
          - file: src/demo/__init__.py
            hasChanged: true
            numMatches: 1
            numReplacements: 1
        countMatches: true
  - - "@semantic-release/git"
    - assets:
      - pyproject.toml
      - src/demo/*.py
  - "@semantic-release/github"

I run using:

  Release:
    needs: Quality
    runs-on: ubuntu-latest
    concurrency: release
    # https://github.community/t/how-do-i-specify-job-dependency-running-in-another-workflow/16482
    if: github.event_name == 'push' && github.ref == 'refs/heads/main' && !contains(github.event.head_commit.message, 'chore(release):')

    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
      - name: Setup Node.js
        uses: actions/setup-node@v1
        with:
          node-version: 14
      - name: Install semantic-release
        run: npm install -g semantic-release @semantic-release/github @semantic-release/commit-analyzer @semantic-release/git @semantic-release/release-notes-generator "@google/semantic-release-replace-plugin"
        # semantic-release-pypi
      - name: Set up Python
        uses: actions/setup-python@v2
        with:
          python-version: 3.9
      - name: Install setuptools
        run: python -m pip install --upgrade setuptools wheel twine
      - name: Release
        env:
          GITHUB_TOKEN: ${{ github.token }}
          # PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
        run: npx semantic-release

This gives me the error below. It would seem that "expected" is no matches, but actual results in match. However, I specify that I do expect a match. (??) Also why does the error message read "expected match not found" when the detail is consistent with "unexpected match found"?

[5:17:45 PM] [semantic-release] › ✖  An error occurred while running semantic-release: Error: Expected match not found!
- Expected
+ Received

  Array [
    Object {
-     "file": "src/demo/__init__.py",
-     "hasChanged": false,
-     "numMatches": 0,
-     "numReplacements": 0,
+     "file": "demo/__init__.py",
+     "hasChanged": true,
+     "numMatches": 1,
+     "numReplacements": 1,
    },
  ]
    at /opt/hostedtoolcache/node/14.19.0/x64/lib/node_modules/@google/semantic-release-replace-plugin/dist/index.js:98:35
    at step (/opt/hostedtoolcache/node/14.19.0/x64/lib/node_modules/@google/semantic-release-replace-plugin/dist/index.js:59:23)
    at Object.next (/opt/hostedtoolcache/node/14.19.0/x64/lib/node_modules/@google/semantic-release-replace-plugin/dist/index.js:40:53)
    at fulfilled (/opt/hostedtoolcache/node/14.19.0/x64/lib/node_modules/@google/semantic-release-replace-plugin/dist/index.js:31:58) {
  pluginName: '@google/semantic-release-replace-plugin'
}
Error: Expected match not found!
- Expected
+ Received

  Array [
    Object {
-     "file": "src/demo/__init__.py",
-     "hasChanged": false,
-     "numMatches": 0,
-     "numReplacements": 0,
+     "file": "demo/__init__.py",
+     "hasChanged": true,
+     "numMatches": 1,
+     "numReplacements": 1,
    },
  ]
    at /opt/hostedtoolcache/node/14.19.0/x64/lib/node_modules/@google/semantic-release-replace-plugin/dist/index.js:98:35
    at step (/opt/hostedtoolcache/node/14.19.0/x64/lib/node_modules/@google/semantic-release-replace-plugin/dist/index.js:59:23)
    at Object.next (/opt/hostedtoolcache/node/14.19.0/x64/lib/node_modules/@google/semantic-release-replace-plugin/dist/index.js:40:53)
    at fulfilled (/opt/hostedtoolcache/node/14.19.0/x64/lib/node_modules/@google/semantic-release-replace-plugin/dist/index.js:31:58) {
  pluginName: '@google/semantic-release-replace-plugin'
}
Error: Process completed with exit code 1.

shaunc avatar Feb 14 '22 17:02 shaunc

I ran in the same problem too

Daniele-Tentoni avatar Jan 20 '23 08:01 Daniele-Tentoni

we had the same problems and maybe here are some hints to resolve it:

Our configs finally started to work AFTER once a simple replace without a results-check had been done, something likes this:

 [
            "@google/semantic-release-replace-plugin",
            {
                "replacements": [
                    {
                        "files": ["src/app-version.ts"],
                        "from": "appVersion = '.*'",
                        "to": "appVersion = '${nextRelease.version}'"
                    },
                ]
            }
        ],

AFTER this initial replacement our configs now are working as expected:

[
            "@google/semantic-release-replace-plugin",
            {
                "replacements": [
                    {
                        "files": ["src/app-version.ts"],
                        "from": "appVersion = '.*'",
                        "to": "appVersion = '${nextRelease.version}'",
                        "results": [
                            {
                                "file": "src/app-version.ts",
                                "hasChanged": true,
                                "numMatches": 1,
                                "numReplacements": 1
                            }
                        ],
                        "countMatches": true
                    }
                    
                ]
            }
        ],

So it seemed that there maybe is a problem with the state coming in from semantic release which is compared to the expected results if there has not been a successful run and git commit before.

We encountered this in a new repo in which we copy&pasted sem rel configs from another repo with similar structure (and where it was working perfectly).

JanJordan avatar Jun 05 '23 10:06 JanJordan

I don't see anything in the code that would cause this. 🤔

jpoehnelt avatar Jul 05 '23 23:07 jpoehnelt