Skip to content

Commit a6d9688

Browse files
fix(logging): add logging for file search patterns and replacement results in prepare function
1 parent 029cf8c commit a6d9688

File tree

9 files changed

+192
-654
lines changed

9 files changed

+192
-654
lines changed

README.md

Lines changed: 101 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ $ npm install https://github.com/centralnicgroup-opensource/semantic-release-rep
2121

2222
The following example uses this plugin to demonstrate using semantic-release in a Python package where `__VERSION__` is defined in the root `__init__.py` file.
2323

24+
### Configuration Example
25+
2426
```json
2527
{
2628
"plugins": [
@@ -30,10 +32,10 @@ The following example uses this plugin to demonstrate using semantic-release in
3032
{
3133
"replacements": [
3234
{
33-
"files": ["foo/**.py"],
35+
"files": ["foo/**/*.py"],
3436
"from": "__VERSION__ = \".*\"",
3537
"to": "__VERSION__ = \"${nextRelease.version}\"",
36-
"ignore" ["foo/go.py"],
38+
"ignore": ["foo/go.py"],
3739
"results": [
3840
{
3941
"file": "foo/__init__.py",
@@ -50,13 +52,71 @@ The following example uses this plugin to demonstrate using semantic-release in
5052
[
5153
"@semantic-release/git",
5254
{
53-
"assets": ["foo/*.py"]
55+
"assets": ["foo/**/*.py"]
5456
}
5557
]
5658
]
5759
}
5860
```
5961

62+
### Real-world Examples
63+
64+
#### JSON Version (like whmcs.json)
65+
```json
66+
{
67+
"replacements": [
68+
{
69+
"files": ["./modules/addons/cnicdnsmanager/whmcs.json"],
70+
"from": "\"version\": \"\\d+\\.\\d+\\.\\d+\"",
71+
"to": "\"version\": \"${nextRelease.version}\"",
72+
"countMatches": true
73+
}
74+
]
75+
}
76+
```
77+
78+
#### Gradle Build File
79+
```json
80+
{
81+
"replacements": [
82+
{
83+
"files": ["./build.gradle"],
84+
"from": "version = '[^']+'",
85+
"to": "version = '${nextRelease.version}'",
86+
"countMatches": true
87+
}
88+
]
89+
}
90+
```
91+
92+
#### Multiple Files with Results Validation
93+
```json
94+
{
95+
"replacements": [
96+
{
97+
"files": ["./release.json", "./COPYRIGHTS"],
98+
"from": "(19|20)\\d{2}[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12]\\d|3[01])",
99+
"to": "${(new Date()).toISOString().split('T')[0]}",
100+
"countMatches": true,
101+
"results": [
102+
{
103+
"file": "./release.json",
104+
"hasChanged": true,
105+
"numMatches": 1,
106+
"numReplacements": 1
107+
},
108+
{
109+
"file": "./COPYRIGHTS",
110+
"hasChanged": true,
111+
"numMatches": 1,
112+
"numReplacements": 1
113+
}
114+
]
115+
}
116+
]
117+
}
118+
```
119+
60120
### Validation
61121

62122
The presence of the `results` array will trigger validation that a replacement has been made. This is optional but recommended.
@@ -74,6 +134,44 @@ This plugin will not commit changes unless you specify assets for the @semantic-
74134
]
75135
```
76136

137+
## Troubleshooting
138+
139+
### Common Issues
140+
141+
#### Pattern Not Matching
142+
**Problem:** "No files found matching pattern"
143+
144+
**Solutions:**
145+
- Verify glob pattern is correct (use `foo/**/*.py` not `foo/**.py`)
146+
- Check file paths relative to project root
147+
- Use `countMatches: true` to get detailed feedback
148+
- Test your regex pattern at [regex101.com](https://regex101.com/)
149+
150+
#### JSON Escaping Issues
151+
**Problem:** Regex pattern not matching (common in `.releaserc.json`)
152+
153+
**Remember:** In JSON, backslashes must be escaped with another backslash:
154+
- ❌ Wrong: `"from": "\d+\.\d+"`
155+
- ✅ Correct: `"from": "\\d+\\.\\d+"`
156+
157+
**Rule:** Double every backslash in JSON strings
158+
159+
#### Results Validation Failed
160+
**Problem:** "Expected match not found"
161+
162+
**Check:**
163+
1. Does the file actually exist?
164+
2. Is the glob pattern matching the right file?
165+
3. Do the `numMatches` and `numReplacements` match actual replacements?
166+
4. Is `countMatches: true` enabled?
167+
168+
### Debugging Tips
169+
170+
1. **Enable verbose logging**: The plugin logs all matched files and replacements
171+
2. **Start simple**: Test with a single replacement first
172+
3. **Use `results` validation**: It forces you to be explicit about expectations
173+
4. **Test regex patterns separately**: Use online tools before adding to config
174+
77175
## Options
78176

79177
Please refer to the [documentation](./docs/README.md) for more options.

dist/index.d.ts

Lines changed: 0 additions & 106 deletions
This file was deleted.

0 commit comments

Comments
 (0)