diff --git a/.github/workflows/pull-request.yaml b/.github/workflows/pull-request.yaml index 770a1666c..eb90f6ffd 100644 --- a/.github/workflows/pull-request.yaml +++ b/.github/workflows/pull-request.yaml @@ -406,8 +406,11 @@ jobs: env: os: windows-latest DOCKER: "false" + FUZZBUCKET_SSH_KEY: ${{ secrets.FUZZBUCKET_SSH_KEY }} + FUZZBUCKET_URL: ${{ secrets.FUZZBUCKET_URL }} + FUZZBUCKET_CREDENTIALS: ${{ secrets.FUZZBUCKET_CREDENTIALS }} run: | - just web/build-and-test-ci-e2e $env:os + just test/init-connect $env:os test-macos: @@ -450,8 +453,11 @@ jobs: env: os: macos-latest DOCKER: "false" + FUZZBUCKET_SSH_KEY: ${{ secrets.FUZZBUCKET_SSH_KEY }} + FUZZBUCKET_URL: ${{ secrets.FUZZBUCKET_URL }} + FUZZBUCKET_CREDENTIALS: ${{ secrets.FUZZBUCKET_CREDENTIALS }} run: | - just web/build-and-test-ci-e2e ${os} + just test/init-connect ${os} build-linux-amd64: runs-on: ubuntu-latest @@ -561,6 +567,9 @@ jobs: env: os: linux-amd64 DOCKER: "false" + FUZZBUCKET_SSH_KEY: ${{ secrets.FUZZBUCKET_SSH_KEY }} + FUZZBUCKET_URL: ${{ secrets.FUZZBUCKET_URL }} + FUZZBUCKET_CREDENTIALS: ${{ secrets.FUZZBUCKET_CREDENTIALS }} run: | just test/ui-client ${os} @@ -677,11 +686,15 @@ jobs: os: linux-arm64 run: | just test/run-client ${os} - # - - # name: Run linux-arm64 Cypress Tests - # env: - # os: linux-arm64 - # DOCKER: "false" - # run: | - # just web/build && \ - # just test/ui-client ${os} + - + name: Run linux-arm64 Cypress Tests + env: + os: linux-arm64 + DOCKER: "false" + FUZZBUCKET_SSH_KEY: ${{ secrets.FUZZBUCKET_SSH_KEY }} + FUZZBUCKET_URL: ${{ secrets.FUZZBUCKET_URL }} + FUZZBUCKET_CREDENTIALS: ${{ secrets.FUZZBUCKET_CREDENTIALS }} + + run: | + just web/build && \ + just test/ui-client ${os} diff --git a/justfile b/justfile index 2f5f60104..82438d305 100644 --- a/justfile +++ b/justfile @@ -181,11 +181,10 @@ start-agent-for-e2e: GOARCH="${GOARCH%%[[:cntrl:]]}" echo "Working directory is $(pwd)" + echo "COMMAND ARGS: ${CMD_ARGS}" ./bin/$GOOS-$GOARCH/connect-client publish-ui \ - ./test/sample-content/fastapi-simple \ - --listen=127.0.0.1:9000 \ - --token=abc123 + ${CMD_ARGS} [private] _with_docker *args: diff --git a/test/environments/.basic b/test/environments/.basic new file mode 100644 index 000000000..a786124a8 --- /dev/null +++ b/test/environments/.basic @@ -0,0 +1 @@ +CMD_ARGS="./test/sample-content/fastapi-simple --listen=localhost:9000 --token=abc123 -n connect" \ No newline at end of file diff --git a/test/justfile b/test/justfile index 295bd2ac9..22ad1729f 100644 --- a/test/justfile +++ b/test/justfile @@ -47,11 +47,10 @@ init-connect target: echo "${FUZZBUCKET_SSH_KEY}" > .fuzzbucket-ssh-key chmod 600 .fuzzbucket-ssh-key export SSH_OPTIONS="-i.fuzzbucket-ssh-key" - export CONNECT_VERSION=$(curl https://cdn.posit.co/connect/latest-packages.json | - jq ".packages[0].version") export CONNECT_IP="$(python setup/connect-setup.py)" - ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@$CONNECT_IP "${SSH_OPTIONS}" sudo -E UNATTENDED=1 bash installer-ci.sh ${CONNECT_VERSION} python setup/client-setup.py + source ./environments/.basic && \ + export CMD_ARGS="$CMD_ARGS" && \ just ../web/build-and-test-ci-e2e {{target}} run-client target: diff --git a/test/setup/connect-setup.py b/test/setup/connect-setup.py index 55a04f55f..3ec215b65 100644 --- a/test/setup/connect-setup.py +++ b/test/setup/connect-setup.py @@ -1,13 +1,38 @@ +import hashlib import subprocess import json import requests import time +import logging +# use the perftest fuzzbucket instance since it already has all the deps alias = "perftest-connect-20230518" box_name = "connect-ci" list_command = "fuzzbucket-client -j list" create_command = "fuzzbucket-client create -c " + alias + " -n " + box_name remove_command = "fuzzbucket-client rm " + box_name +ssh_options = "-i.fuzzbucket-ssh-key" +# connect_version = $(curl https://cdn.posit.co/connect/latest-packages.json | +# jq ".packages[0].version") + + +def get_api_key(username): + # Calculate the MD5 hash for the username to get an API Key + api_key = hashlib.md5(username.encode()).hexdigest() + return api_key + +def get_latest_connect_version(): + response = requests.get("https://cdn.posit.co/connect/latest-packages.json") + latest_connect = response.json()['packages'][0]['version'] + return latest_connect + +def get_current_connect_version(connect_ip, api_key): + response = requests.get( + 'http://' + connect_ip + ':3939/__api__/server_settings', + headers={'Authorization': 'Key ' + api_key}, + ) + current_connect = response.json()['version'] + return current_connect def check_existing_boxes(box_name): output = subprocess.check_output(list_command, shell=True, text=True) @@ -31,8 +56,12 @@ def connect_ready(box_name, max_attempts, interval): attempts = 0 while attempts < max_attempts: try: + logging.info("Checking Connect Status") response = requests.get("http://"+connect_box+":3939/__ping__") if response.status_code == 200: + if latest_connect != current_connect: + logging.info("Installing Connect...") + subprocess.check_output(install_connect, shell=True, text=True) return response.text except requests.RequestException: pass @@ -41,6 +70,11 @@ def connect_ready(box_name, max_attempts, interval): attempts += 1 return None +api_key=get_api_key('admin') +latest_connect=get_latest_connect_version() +current_connect=get_current_connect_version(get_ip(box_name), api_key) +install_connect = "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@" + get_ip(box_name) + " " + ssh_options + " sudo -E UNATTENDED=1 bash installer-ci.sh " + latest_connect + response = connect_ready(box_name, 20, 5) if response: diff --git a/web/justfile b/web/justfile index 1d538e031..1d2097a27 100644 --- a/web/justfile +++ b/web/justfile @@ -72,6 +72,7 @@ build-and-test-ci-e2e target: # cache within root's home dir. # use a different cache per os export CYPRESS_CACHE_FOLDER="./cypress/{{target}}/.cache" + export CYPRESS_CONNECT_ADDRESS="http://$CONNECT_IP:3939/connect/\#/login" # install cypress npx cypress install diff --git a/web/package.json b/web/package.json index e4048b883..c3de2fac2 100644 --- a/web/package.json +++ b/web/package.json @@ -15,7 +15,7 @@ "test:e2e:ci": "start-server-and-test --expect 401 'just ../start-agent-for-e2e' http-get://127.0.0.1:9000 cypress:run:ci", "cypress:open": "cypress open", "cypress:run": "cypress run", - "cypress:run:ci": "cypress run --env publishing-token=abc123" + "cypress:run:ci": "cypress run --env publishing-token=abc123,CYPRESS_CONNECT_ADDRESS=$CYPRESS_CONNECT_ADDRESS" }, "dependencies": { "@quasar/extras": "^1.16.5",