Skip to content

Commit 963afac

Browse files
authored
feat: make --version return java package version (microsoft#748)
1 parent c230bed commit 963afac

6 files changed

Lines changed: 88 additions & 1 deletion

File tree

.github/workflows/test_cli.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@ jobs:
2626
run: mvn install -D skipTests --no-transfer-progress
2727
- name: Test CLI
2828
run: mvn exec:java -e -D exec.mainClass=com.microsoft.playwright.CLI -f playwright/pom.xml -D exec.args=-V
29+
- name: Test CLI version
30+
shell: bash
31+
run: tools/test-cli-version/test.sh

playwright/src/main/java/com/microsoft/playwright/CLI.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ public static void main(String[] args) throws IOException, InterruptedException
3535
if (!pb.environment().containsKey("PW_CLI_TARGET_LANG")) {
3636
pb.environment().put("PW_CLI_TARGET_LANG", "java");
3737
}
38+
String version = Playwright.class.getPackage().getImplementationVersion();
39+
if (version != null) {
40+
pb.environment().put("PW_CLI_DISPLAY_VERSION", version);
41+
}
3842
pb.inheritIO();
3943
Process process = pb.start();
4044
System.exit(process.waitFor());

tools/test-cli-version/pom.xml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>com.microsoft.playwright</groupId>
6+
<artifactId>test-cli-version</artifactId>
7+
<version>1.18.0-SNAPSHOT</version>
8+
<name>Test Playwright Command Line Version</name>
9+
<properties>
10+
<compiler.version>1.8</compiler.version>
11+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
12+
</properties>
13+
<build>
14+
<plugins>
15+
<plugin>
16+
<groupId>org.apache.maven.plugins</groupId>
17+
<artifactId>maven-compiler-plugin</artifactId>
18+
<version>3.1</version>
19+
<configuration>
20+
<source>${compiler.version}</source>
21+
<target>${compiler.version}</target>
22+
</configuration>
23+
</plugin>
24+
</plugins>
25+
</build>
26+
<dependencies>
27+
<dependency>
28+
<groupId>com.microsoft.playwright</groupId>
29+
<artifactId>playwright</artifactId>
30+
<version>${project.version}</version>
31+
</dependency>
32+
</dependencies>
33+
</project>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.microsoft.playwright.testcliversion;
2+
3+
import com.microsoft.playwright.Playwright;
4+
5+
import java.io.IOException;
6+
7+
public class TestApp {
8+
public static void main(String[] args) throws IOException, InterruptedException {
9+
String version = Playwright.class.getPackage().getImplementationVersion();
10+
if (version == null) {
11+
throw new RuntimeException("FAIL: Version is null");
12+
}
13+
System.out.println("ImplementationVersion " + version);
14+
}
15+
}

tools/test-cli-version/test.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
set -e
4+
set +x
5+
6+
trap "cd $(pwd -P)" EXIT
7+
cd "$(dirname $0)"
8+
9+
TMP_DIR=$(mktemp -d)
10+
echo "Created ${TMP_DIR}"
11+
12+
echo "Running CLI..."
13+
mvn exec:java -e -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args="--version" 2>&1 | tee ${TMP_DIR}/cli.txt
14+
15+
echo "Running TestApp..."
16+
mvn compile exec:java -e -Dexec.mainClass=com.microsoft.playwright.testcliversion.TestApp 2>&1 | tee ${TMP_DIR}/app.txt
17+
18+
CLI_VERSION=$(cat ${TMP_DIR}/cli.txt | tail -n 1 | cut -d\ -f2)
19+
PACKAGE_VERSION=$(cat ${TMP_DIR}/app.txt | grep ImplementationVersion | cut -d\ -f2)
20+
21+
rm -rf $TMP_DIR
22+
23+
echo "Comparing versions: ${CLI_VERSION} and ${PACKAGE_VERSION}"
24+
25+
if [[ "$CLI_VERSION" == "$PACKAGE_VERSION" ]];
26+
then
27+
echo "SUCCESS.";
28+
else
29+
echo "FAIL.";
30+
exit 1;
31+
fi;
32+
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
This derictory is populated with test files from playwright and playwright-driver projects. They are copied
1+
This directory is populated with test files from playwright and playwright-driver projects. They are copied
22
here on each test run.

0 commit comments

Comments
 (0)