Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions scripts/update_readme.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ mvn install --no-transfer-progress -D skipTests

echo "Updating browser versions in README.md"
mvn compile exec:java --f ./tools/update-docs-version -D exec.mainClass=com.microsoft.playwright.tools.UpdateBrowserVersions

echo "Updating Playwright dependency version in README.md"
mvn compile exec:java --f ./tools/update-docs-version -D exec.mainClass=com.microsoft.playwright.tools.UpdatePlaywrightVersion
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.microsoft.playwright.tools;

import java.io.FileWriter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.NoSuchElementException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static java.nio.charset.StandardCharsets.UTF_8;

public class UpdatePlaywrightVersion {
private static final Pattern VERSION_PATTERN = Pattern.compile(
"<groupId>com.microsoft.playwright</groupId>\\s*<artifactId>parent-pom</artifactId>\\s*<version>(\\d+\\.\\d+\\.\\d+)(?:-SNAPSHOT)?</version>"
);
private static final Pattern MAVEN_PATTERN = Pattern.compile(
"(<dependency>\\s*<groupId>com.microsoft.playwright</groupId>\\s*<artifactId>playwright</artifactId>\\s*)<version>\\d+\\.\\d+\\.\\d+</version>(\\s*</dependency>)"
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it much multiline by default (without MULTILINE flag) ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes
Zrzut ekranu 2025-03-14 o 18 03 47

private static final Pattern GRADLE_PATTERN = Pattern.compile(
"(implementation group: 'com.microsoft.playwright', name: 'playwright', version: )'\\d+\\.\\d+\\.\\d+'"
);

public static void main(String[] args) throws Exception {
Path pomPath = Paths.get("pom.xml");
String pomContent = Files.readString(pomPath, UTF_8);

Matcher versionMatcher = VERSION_PATTERN.matcher(pomContent);
if (!versionMatcher.find()) {
throw new NoSuchElementException("Project version was not found");
}
String version = versionMatcher.group(1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Version in pom.xml usually refers to the next development version, which hasn't been published yet. Let's set it to major.(minor-1).0 similar to what we did in #1748.

Also would be nice to unify this two places, sot that the versions are patched at the same place with the same deps version.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can move it to JS like its done in https://github.com/microsoft/playwright-java/pull/1748/files - then the actual PR should be much smaller.


Path readmePath = Paths.get("README.md");
String readme = Files.readString(readmePath, UTF_8);

String updatedReadme = updateDependencies(readme, version);

try (FileWriter writer = new FileWriter(readmePath.toFile(), UTF_8)) {
writer.write(updatedReadme);
}
}

private static String updateDependencies(String readme, String version) {
readme = MAVEN_PATTERN.matcher(readme)
.replaceAll("$1<version>" + version + "</version>$2");

readme = GRADLE_PATTERN.matcher(readme)
.replaceAll("$1'" + version + "'");

return readme;
}
}
Loading