Skip to content

Commit

Permalink
feat: make --version return java package version (microsoft#748)
Browse files Browse the repository at this point in the history
  • Loading branch information
yury-s authored Dec 16, 2021
1 parent c230bed commit 963afac
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .github/workflows/test_cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ jobs:
run: mvn install -D skipTests --no-transfer-progress
- name: Test CLI
run: mvn exec:java -e -D exec.mainClass=com.microsoft.playwright.CLI -f playwright/pom.xml -D exec.args=-V
- name: Test CLI version
shell: bash
run: tools/test-cli-version/test.sh
4 changes: 4 additions & 0 deletions playwright/src/main/java/com/microsoft/playwright/CLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public static void main(String[] args) throws IOException, InterruptedException
if (!pb.environment().containsKey("PW_CLI_TARGET_LANG")) {
pb.environment().put("PW_CLI_TARGET_LANG", "java");
}
String version = Playwright.class.getPackage().getImplementationVersion();
if (version != null) {
pb.environment().put("PW_CLI_DISPLAY_VERSION", version);
}
pb.inheritIO();
Process process = pb.start();
System.exit(process.waitFor());
Expand Down
33 changes: 33 additions & 0 deletions tools/test-cli-version/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.microsoft.playwright</groupId>
<artifactId>test-cli-version</artifactId>
<version>1.18.0-SNAPSHOT</version>
<name>Test Playwright Command Line Version</name>
<properties>
<compiler.version>1.8</compiler.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${compiler.version}</source>
<target>${compiler.version}</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.microsoft.playwright</groupId>
<artifactId>playwright</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.microsoft.playwright.testcliversion;

import com.microsoft.playwright.Playwright;

import java.io.IOException;

public class TestApp {
public static void main(String[] args) throws IOException, InterruptedException {
String version = Playwright.class.getPackage().getImplementationVersion();
if (version == null) {
throw new RuntimeException("FAIL: Version is null");
}
System.out.println("ImplementationVersion " + version);
}
}
32 changes: 32 additions & 0 deletions tools/test-cli-version/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

set -e
set +x

trap "cd $(pwd -P)" EXIT
cd "$(dirname $0)"

TMP_DIR=$(mktemp -d)
echo "Created ${TMP_DIR}"

echo "Running CLI..."
mvn exec:java -e -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args="--version" 2>&1 | tee ${TMP_DIR}/cli.txt

echo "Running TestApp..."
mvn compile exec:java -e -Dexec.mainClass=com.microsoft.playwright.testcliversion.TestApp 2>&1 | tee ${TMP_DIR}/app.txt

CLI_VERSION=$(cat ${TMP_DIR}/cli.txt | tail -n 1 | cut -d\ -f2)
PACKAGE_VERSION=$(cat ${TMP_DIR}/app.txt | grep ImplementationVersion | cut -d\ -f2)

rm -rf $TMP_DIR

echo "Comparing versions: ${CLI_VERSION} and ${PACKAGE_VERSION}"

if [[ "$CLI_VERSION" == "$PACKAGE_VERSION" ]];
then
echo "SUCCESS.";
else
echo "FAIL.";
exit 1;
fi;

2 changes: 1 addition & 1 deletion tools/test-local-installation/src/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
This derictory is populated with test files from playwright and playwright-driver projects. They are copied
This directory is populated with test files from playwright and playwright-driver projects. They are copied
here on each test run.

0 comments on commit 963afac

Please sign in to comment.