Skip to content

Commit 482f5fa

Browse files
committed
chore: create UpdatePlaywrightVersion.java
1 parent 84eaf8f commit 482f5fa

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.microsoft.playwright.tools;
2+
3+
import java.io.FileWriter;
4+
import java.nio.file.Files;
5+
import java.nio.file.Path;
6+
import java.nio.file.Paths;
7+
import java.util.NoSuchElementException;
8+
import java.util.regex.Matcher;
9+
import java.util.regex.Pattern;
10+
11+
import static java.nio.charset.StandardCharsets.UTF_8;
12+
13+
public class UpdatePlaywrightVersion {
14+
private static final Pattern VERSION_PATTERN = Pattern.compile(
15+
"<groupId>com.microsoft.playwright</groupId>\\s*<artifactId>parent-pom</artifactId>\\s*<version>(\\d+\\.\\d+\\.\\d+)(?:-SNAPSHOT)?</version>"
16+
);
17+
private static final Pattern MAVEN_PATTERN = Pattern.compile(
18+
"(<dependency>\\s*<groupId>com.microsoft.playwright</groupId>\\s*<artifactId>playwright</artifactId>\\s*)<version>\\d+\\.\\d+\\.\\d+</version>(\\s*</dependency>)"
19+
);
20+
private static final Pattern GRADLE_PATTERN = Pattern.compile(
21+
"(implementation group: 'com.microsoft.playwright', name: 'playwright', version: )'\\d+\\.\\d+\\.\\d+'"
22+
);
23+
24+
public static void main(String[] args) throws Exception {
25+
Path pomPath = Paths.get("pom.xml");
26+
String pomContent = Files.readString(pomPath, UTF_8);
27+
28+
Matcher versionMatcher = VERSION_PATTERN.matcher(pomContent);
29+
if (!versionMatcher.find()) {
30+
throw new NoSuchElementException("Project version was not found");
31+
}
32+
String version = versionMatcher.group(1);
33+
34+
Path readmePath = Paths.get("README.md");
35+
String readme = Files.readString(readmePath, UTF_8);
36+
37+
String updatedReadme = updateDependencies(readme, version);
38+
39+
try (FileWriter writer = new FileWriter(readmePath.toFile(), UTF_8)) {
40+
writer.write(updatedReadme);
41+
}
42+
}
43+
44+
private static String updateDependencies(String readme, String version) {
45+
readme = MAVEN_PATTERN.matcher(readme)
46+
.replaceAll("$1<version>" + version + "</version>$2");
47+
48+
readme = GRADLE_PATTERN.matcher(readme)
49+
.replaceAll("$1'" + version + "'");
50+
51+
return readme;
52+
}
53+
}

0 commit comments

Comments
 (0)