Skip to content

Commit

Permalink
devops: roll_driver script (#1605)
Browse files Browse the repository at this point in the history
  • Loading branch information
yury-s committed Jun 25, 2024
1 parent 626050d commit a08ab2d
Show file tree
Hide file tree
Showing 14 changed files with 104 additions and 91 deletions.
2 changes: 1 addition & 1 deletion .azure-pipelines/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ extends:
GPG_PRIVATE_KEY_BASE64: $(GPG_PRIVATE_KEY_BASE64) # secret variable has to be mapped to an env variable
displayName: "Import gpg key"
- bash: ./scripts/download_driver_for_all_platforms.sh
- bash: ./scripts/download_driver.sh
displayName: 'Download driver'

- bash: mvn -B deploy -D skipTests --no-transfer-progress --activate-profiles release -D gpg.passphrase=$GPG_PASSPHRASE -DaltDeploymentRepository=snapshot-repo::default::file:$(pwd)/local-build
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
java-version: 8
- name: Download drivers
shell: bash
run: scripts/download_driver_for_all_platforms.sh
run: scripts/download_driver.sh
- name: Build & Install
run: mvn -B install -D skipTests --no-transfer-progress
- name: Run tests
Expand Down Expand Up @@ -75,7 +75,7 @@ jobs:
java-version: 8
- name: Download drivers
shell: bash
run: scripts/download_driver_for_all_platforms.sh
run: scripts/download_driver.sh
- name: Build & Install
run: mvn -B install -D skipTests --no-transfer-progress
- name: Install MS Edge
Expand Down Expand Up @@ -105,7 +105,7 @@ jobs:
java-version: 17
- name: Download drivers
shell: bash
run: scripts/download_driver_for_all_platforms.sh
run: scripts/download_driver.sh
- name: Build & Install
run: mvn -B install -D skipTests --no-transfer-progress
- name: Run tests
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test_cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Download drivers
run: scripts/download_driver_for_all_platforms.sh
run: scripts/download_driver.sh
- name: Intall Playwright
run: mvn install -D skipTests --no-transfer-progress
- name: Test CLI
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test_docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
paths:
- .github/workflows/test_docker.yml
- '**/Dockerfile*'
- scripts/CLI_VERSION
- scripts/DRIVER_VERSION
- '**/pom.xml'
branches:
- main
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/verify_api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- uses: actions/checkout@v2
- uses: microsoft/playwright-github-action@v1
- name: Download drivers
run: scripts/download_driver_for_all_platforms.sh
run: scripts/download_driver.sh
- name: Regenerate APIs
run: scripts/generate_api.sh
- name: Update browser versions in README
Expand Down
20 changes: 6 additions & 14 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@ git clone https://github.com/microsoft/playwright-java
cd playwright-java
```

2. Run the following script to download playwright-cli binaries for all platforms into `driver-bundle/src/main/resources/driver/` directory (browser binaries for Chromium, Firefox and WebKit will be automatically downloaded later on first Playwright run).
2. Run the following script to download Playwright driver for all platforms into `driver-bundle/src/main/resources/driver/` directory (browser binaries for Chromium, Firefox and WebKit will be automatically downloaded later on first Playwright run).

```bash
scripts/download_driver_for_all_platforms.sh
scripts/download_driver.sh
```

Names of published driver archives can be found at https://github.com/microsoft/playwright-cli/actions

### Building and running the tests with Maven

```bash
Expand All @@ -41,25 +39,19 @@ BROWSER=chromium mvn test --projects=playwright -Dtest=TestPageNetworkSizes

### Generating API

Public Java API is generated from api.json which is produced by `playwright-cli print-api-json`. To regenerate
Java interfaces for the current driver run the following commands:
Public Java API is generated from api.json which is produced by `print-api-json` command of playwright CLI. To regenerate Java interfaces for the current driver run the following commands:

```bash
./scripts/download_driver_for_all_platforms.sh
./scripts/download_driver.sh
./scripts/generate_api.sh
```

#### Updating driver version

Driver version is read from [scripts/CLI_VERSION](https://github.com/microsoft/playwright-java/blob/main/scripts/CLI_VERSION) and can be found in the upstream [GHA build](https://github.com/microsoft/playwright/actions/workflows/publish_canary.yml) logs. To update the driver to a particular version run the following commands:
Versions of published driver archives can be found in [publish canary](https://github.com/microsoft/playwright/actions/workflows/publish_canary.yml) and [publish release](https://github.com/microsoft/playwright/actions/workflows/publish_release_driver.yml) actions logs. To update the driver to a particular version run the following command:

```bash
cat > scripts/CLI_VERSION
<paste new version>
^D
./scripts/download_driver_for_all_platforms.sh -f
./scripts/generate_api.sh
./scripts/update_readme.sh
scripts/roll_driver.sh [version]
```

### Code Style
Expand Down
4 changes: 2 additions & 2 deletions ROLLING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

* make sure to have at least Java 8 and Maven 3.6.3
* clone playwright for java: http://github.com/microsoft/playwright-java
* set new driver version in `scripts/CLI_VERSION`
* regenerate API: `./scripts/download_driver_for_all_platforms.sh -f && ./scripts/generate_api.sh && ./scripts/update_readme.sh`
* set new driver version in `scripts/DRIVER_VERSION`
* regenerate API: `./scripts/download_driver.sh -f && ./scripts/generate_api.sh && ./scripts/update_readme.sh`
* commit & send PR with the roll

### Finding driver version
Expand Down
File renamed without changes.
57 changes: 57 additions & 0 deletions scripts/download_driver.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash

set -e
set +x

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

if [[ ($1 == '-h') || ($1 == '--help') ]]; then
echo ""
echo "This script for downloading playwright driver for all platforms."
echo "The downloaded files will be put under 'driver-bundle/src/main/resources/driver'."
echo ""
echo "Usage: scripts/download_driver.sh [option]"
echo ""
echo "Options:"
echo " -h, --help display help information"
echo ""
exit 0
fi

DRIVER_VERSION=$(head -1 ./DRIVER_VERSION)
FILE_PREFIX=playwright-$DRIVER_VERSION

cd ../driver-bundle/src/main/resources

if [[ -d 'driver' ]]; then
echo "Deleting existing drivers from $(pwd)"
rm -rf driver
fi

mkdir -p driver
cd driver

for PLATFORM in mac mac-arm64 linux linux-arm64 win32_x64
do
FILE_NAME=$FILE_PREFIX-$PLATFORM.zip
mkdir $PLATFORM
cd $PLATFORM
echo "Downloading driver for $PLATFORM to $(pwd)"

URL=https://playwright.azureedge.net/builds/driver
if [[ "$DRIVER_VERSION" == *-alpha* || "$DRIVER_VERSION" == *-beta* || "$DRIVER_VERSION" == *-next* ]]; then
URL=$URL/next
fi
URL=$URL/$FILE_NAME
echo "Using url: $URL"
curl -O $URL
unzip $FILE_NAME -d .
rm $FILE_NAME

cd -
done

echo ""
echo "All drivers have been successfully downloaded."
echo ""
63 changes: 0 additions & 63 deletions scripts/download_driver_for_all_platforms.sh

This file was deleted.

27 changes: 27 additions & 0 deletions scripts/roll_driver.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

set -e
set +x

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

if [ "$#" -ne 1 ]; then
echo ""
echo "Usage: scripts/roll_driver.sh [new version]"
echo ""
exit 1
fi

NEW_VERSION=$1
CURRENT_VERSION=$(head -1 ./DRIVER_VERSION)

if [[ "$CURRENT_VERSION" == "$NEW_VERSION" ]]; then
echo "Current version is up to date. Skipping driver download.";
else
echo $NEW_VERSION > ./DRIVER_VERSION
./download_driver.sh
fi;

./generate_api.sh
./update_readme.sh
6 changes: 3 additions & 3 deletions tools/test-cli-version/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ mvn exec:java -e -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args="--ve
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)
DRIVER_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}"
echo "Comparing versions: ${DRIVER_VERSION} and ${PACKAGE_VERSION}"

if [[ "$CLI_VERSION" == "$PACKAGE_VERSION" ]];
if [[ "$DRIVER_VERSION" == "$PACKAGE_VERSION" ]];
then
echo "SUCCESS.";
else
Expand Down
2 changes: 1 addition & 1 deletion utils/docker/Dockerfile.focal
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ RUN mkdir /ms-playwright && \
COPY . /tmp/pw-java

RUN cd /tmp/pw-java && \
./scripts/download_driver_for_all_platforms.sh && \
./scripts/download_driver.sh && \
mvn install -D skipTests --no-transfer-progress && \
DEBIAN_FRONTEND=noninteractive mvn exec:java -e -D exec.mainClass=com.microsoft.playwright.CLI \
-D exec.args="install-deps" -f playwright/pom.xml --no-transfer-progress && \
Expand Down
2 changes: 1 addition & 1 deletion utils/docker/Dockerfile.jammy
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ RUN mkdir /ms-playwright && \
COPY . /tmp/pw-java

RUN cd /tmp/pw-java && \
./scripts/download_driver_for_all_platforms.sh && \
./scripts/download_driver.sh && \
mvn install -D skipTests --no-transfer-progress && \
DEBIAN_FRONTEND=noninteractive mvn exec:java -e -D exec.mainClass=com.microsoft.playwright.CLI \
-D exec.args="install-deps" -f playwright/pom.xml --no-transfer-progress && \
Expand Down

0 comments on commit a08ab2d

Please sign in to comment.