Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

matches not found in google action #164

Open
shaunc opened this issue Feb 14, 2022 · 3 comments
Open

matches not found in google action #164

shaunc opened this issue Feb 14, 2022 · 3 comments

Comments

@shaunc
Copy link

shaunc commented Feb 14, 2022

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.
@Daniele-Tentoni
Copy link

I ran in the same problem too

@JanJordan
Copy link

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).

@jpoehnelt
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants