From a08ab2dcae08bc0ec78b2fce886a4e9ade420eab Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Tue, 25 Jun 2024 08:34:20 -0700 Subject: [PATCH] devops: roll_driver script (#1605) --- .azure-pipelines/publish.yml | 2 +- .github/workflows/test.yml | 6 +- .github/workflows/test_cli.yml | 2 +- .github/workflows/test_docker.yml | 2 +- .github/workflows/verify_api.yml | 2 +- CONTRIBUTING.md | 20 ++----- ROLLING.md | 4 +- scripts/{CLI_VERSION => DRIVER_VERSION} | 0 scripts/download_driver.sh | 57 ++++++++++++++++++ scripts/download_driver_for_all_platforms.sh | 63 -------------------- scripts/roll_driver.sh | 27 +++++++++ tools/test-cli-version/test.sh | 6 +- utils/docker/Dockerfile.focal | 2 +- utils/docker/Dockerfile.jammy | 2 +- 14 files changed, 104 insertions(+), 91 deletions(-) rename scripts/{CLI_VERSION => DRIVER_VERSION} (100%) create mode 100755 scripts/download_driver.sh delete mode 100755 scripts/download_driver_for_all_platforms.sh create mode 100755 scripts/roll_driver.sh diff --git a/.azure-pipelines/publish.yml b/.azure-pipelines/publish.yml index 89c5b954..42ab5793 100644 --- a/.azure-pipelines/publish.yml +++ b/.azure-pipelines/publish.yml @@ -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 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 558066f0..3fc8aa22 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 @@ -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 @@ -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 diff --git a/.github/workflows/test_cli.yml b/.github/workflows/test_cli.yml index 52801895..9b877de1 100644 --- a/.github/workflows/test_cli.yml +++ b/.github/workflows/test_cli.yml @@ -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 diff --git a/.github/workflows/test_docker.yml b/.github/workflows/test_docker.yml index 0a9a401f..79f888a7 100644 --- a/.github/workflows/test_docker.yml +++ b/.github/workflows/test_docker.yml @@ -11,7 +11,7 @@ on: paths: - .github/workflows/test_docker.yml - '**/Dockerfile*' - - scripts/CLI_VERSION + - scripts/DRIVER_VERSION - '**/pom.xml' branches: - main diff --git a/.github/workflows/verify_api.yml b/.github/workflows/verify_api.yml index 99c22809..39834549 100644 --- a/.github/workflows/verify_api.yml +++ b/.github/workflows/verify_api.yml @@ -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 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c4f0ae8b..ab3033cd 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 @@ -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 - -^D -./scripts/download_driver_for_all_platforms.sh -f -./scripts/generate_api.sh -./scripts/update_readme.sh +scripts/roll_driver.sh [version] ``` ### Code Style diff --git a/ROLLING.md b/ROLLING.md index 3a7e65bb..f30744ac 100644 --- a/ROLLING.md +++ b/ROLLING.md @@ -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 diff --git a/scripts/CLI_VERSION b/scripts/DRIVER_VERSION similarity index 100% rename from scripts/CLI_VERSION rename to scripts/DRIVER_VERSION diff --git a/scripts/download_driver.sh b/scripts/download_driver.sh new file mode 100755 index 00000000..c7dc1979 --- /dev/null +++ b/scripts/download_driver.sh @@ -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 "" diff --git a/scripts/download_driver_for_all_platforms.sh b/scripts/download_driver_for_all_platforms.sh deleted file mode 100755 index 789596a4..00000000 --- a/scripts/download_driver_for_all_platforms.sh +++ /dev/null @@ -1,63 +0,0 @@ -#!/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-cli binaries for all platforms." - echo "The downloaded files will be put into directory 'driver-bundle/src/main/resources/driver'." - echo "" - echo "Usage: scripts/download_driver_for_all_platforms.sh [option]" - echo "" - echo "Options:" - echo " -h, --help display help information" - echo " -f, --force delete existing drivers and download them again" - echo "" - exit 0 -fi - -CLI_VERSION=$(head -1 ./CLI_VERSION) -FILE_PREFIX=playwright-$CLI_VERSION - -cd ../driver-bundle/src/main/resources - -if [[ ($1 == '-f') || ($1 == '--force') ]]; 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 - if [[ -d $PLATFORM ]]; then - echo "Skipping driver download for $PLATFORM ($(pwd)/$PLATFORM already exists)" - continue - fi - mkdir $PLATFORM - cd $PLATFORM - echo "Downloading driver for $PLATFORM to $(pwd)" - - URL=https://playwright.azureedge.net/builds/driver - if [[ "$CLI_VERSION" == *-alpha* || "$CLI_VERSION" == *-beta* || "$CLI_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 downloaded successfully, use '-f' or '--force' option to delete and download them again if you want." -echo "For more details, you can use '-h' or '--help' option, or read the CONTRIBUTING.md for reference." -echo "" diff --git a/scripts/roll_driver.sh b/scripts/roll_driver.sh new file mode 100755 index 00000000..2c47c3af --- /dev/null +++ b/scripts/roll_driver.sh @@ -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 \ No newline at end of file diff --git a/tools/test-cli-version/test.sh b/tools/test-cli-version/test.sh index 486539a8..4f5826e1 100755 --- a/tools/test-cli-version/test.sh +++ b/tools/test-cli-version/test.sh @@ -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 diff --git a/utils/docker/Dockerfile.focal b/utils/docker/Dockerfile.focal index 31c6d591..4e598b30 100644 --- a/utils/docker/Dockerfile.focal +++ b/utils/docker/Dockerfile.focal @@ -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 && \ diff --git a/utils/docker/Dockerfile.jammy b/utils/docker/Dockerfile.jammy index 973b86bb..3f5e4546 100644 --- a/utils/docker/Dockerfile.jammy +++ b/utils/docker/Dockerfile.jammy @@ -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 && \