From 8e5ebc80b04413b3429724f00c83b0b8ec6c14e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mischa=20J=C3=B6rg?= Date: Thu, 1 Jun 2023 00:50:32 +0200 Subject: [PATCH 1/6] chore(cypress): update to latest version --- Dockerfile | 4 ++-- README.md | 5 ++++- action.yml | 10 +++++++--- entrypoint.sh | 12 +++++++++--- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 955a2a5..b86f810 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM cypress/included:3.2.0 +FROM cypress/included:12.13.0 # https://docs.cypress.io/guides/continuous-integration/introduction#Machine-requirements RUN apt-get update && apt-get install -y curl jq @@ -7,4 +7,4 @@ RUN apt-get update && apt-get install -y curl jq COPY entrypoint.sh /entrypoint.sh # Code file to execute when the docker container starts up (`entrypoint.sh`) -ENTRYPOINT ["/entrypoint.sh"] +ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/README.md b/README.md index 70209bf..4bfb913 100644 --- a/README.md +++ b/README.md @@ -23,8 +23,11 @@ jobs: regression: runs-on: ubuntu-latest steps: + - uses: actions/checkout@v3 + - uses: actions/vercel-cypress@v1 with: vercel-token: ${{ secrets.VERCEL_TOKEN }} - repo: my-repo + team: your-team-name + options: "--browser chrome --spec cypress/e2e/base/*" ``` diff --git a/action.yml b/action.yml index 2273c04..a0815d5 100644 --- a/action.yml +++ b/action.yml @@ -7,12 +7,16 @@ inputs: vercel-token: description: "Vercel API token" required: true - repo: - description: "Repository name" + team: + description: "Team name" required: true + options: + description: "Cypress options" + required: false runs: using: "docker" image: "Dockerfile" args: - ${{ inputs.vercel-token }} - - ${{ inputs.repo }} + - ${{ inputs.team }} + - ${{ inputs.options }} diff --git a/entrypoint.sh b/entrypoint.sh index 585d7a8..3729cf9 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,5 +1,11 @@ #!/bin/sh -l -DEPLOYMENT_URL=$(curl --insecure -H "Content-type: application/json" -H "Authorization: Bearer $1" "https://api.vercel.com/v5/deployments?meta-githubRepo=${2}" | jq -r '.deployments[0].url') -npm install -npx cypress run --config baseUrl="https://$DEPLOYMENT_URL" +# reference: https://vercel.com/docs/rest-api/endpoints#list-deployments +echo "=> checking url from latest deployment for team ${2}" +DEPLOYMENT_URL=$(curl -X GET "https://api.vercel.com/v6/deployments?teamId=$2" -H "Authorization: Bearer $1" | jq -r '.deployments[0].url') +echo "=> found deployment url: ${DEPLOYMENT_URL}" + +yarn install + +export CYPRESS_BASE_URL="https://${DEPLOYMENT_URL}" +npx cypress run $3 \ No newline at end of file From b33ced964dfc1accabbca8b29b3c9dbed29e4a69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mischa=20J=C3=B6rg?= Date: Thu, 1 Jun 2023 01:08:54 +0200 Subject: [PATCH 2/6] docs(readme): update and clarify notes --- README.md | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 4bfb913..eaa40ad 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,38 @@ # vercel-cypress -GitHub action which allows you to run Cypress tests against a Vercel preview deployment. +GitHub action which allows you to run Cypress tests against a Vercel preview +deployment. -## Prerequesites +## Prerequisites -This guide assumes you have set up the [Vercel GitHub integration](https://vercel.com/docs/concepts/git/vercel-for-github). +- [Vercel GitHub integration](https://vercel.com/docs/concepts/git/vercel-for-github). +- [Vercel API token](https://vercel.com/account/tokens) which should be stored + as an [encrypted secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets) +- You Vercel team id or slug -To use this action you will need to first generate a [Vercel token](https://vercel.com/account/tokens). +Make sure that the API token has the right access scope and that your team id is +correct. You can do this with the following check; the output should be a large +json payload. -Then you can either store this with your account or repository's [secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets). +```sh +export TEAM_ID=YOUR_TEAM_ID +export TOKEN=YOUR_VERCEL_API_TOKEN + +# reference: https://vercel.com/docs/rest-api/endpoints#list-deployments +curl -X GET "https://api.vercel.com/v6/deployments?teamId=${TEAM_ID}" \ + -H "Authorization: Bearer ${TOKEN}" +``` ## Usage -The following action will wait for the Vercel deployment to finish, then run Cypress but override the URL provided to Cypress' config to the latest Vercel deployment URL. +The following action will wait for the Vercel deployment to finish, then run +Cypress but override the URL provided to Cypress' config to the latest Vercel +deployment URL. ```yml name: my-action +# (only) run after a successful deployment on: deployment jobs: @@ -27,7 +43,10 @@ jobs: - uses: actions/vercel-cypress@v1 with: + # required: vercel API token vercel-token: ${{ secrets.VERCEL_TOKEN }} + # required: vercel team name / slug team: your-team-name + # optional: parameters that are passed to 'npx cypress run ' options: "--browser chrome --spec cypress/e2e/base/*" ``` From af3d0a58b53eba63a5c5a3adc9439564f0331744 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mischa=20J=C3=B6rg?= Date: Sat, 24 Jun 2023 17:04:57 +0200 Subject: [PATCH 3/6] feat(vercel): add optional team filter --- README.md | 11 ++++++++--- action.yml | 4 ++-- entrypoint.sh | 14 +++++++++++--- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index eaa40ad..8d2adf6 100644 --- a/README.md +++ b/README.md @@ -8,17 +8,22 @@ deployment. - [Vercel GitHub integration](https://vercel.com/docs/concepts/git/vercel-for-github). - [Vercel API token](https://vercel.com/account/tokens) which should be stored as an [encrypted secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets) -- You Vercel team id or slug +- If the project is in a team, you also need the team ID Make sure that the API token has the right access scope and that your team id is correct. You can do this with the following check; the output should be a large json payload. ```sh -export TEAM_ID=YOUR_TEAM_ID +# reference: https://vercel.com/docs/rest-api/endpoints#list-deployments export TOKEN=YOUR_VERCEL_API_TOKEN -# reference: https://vercel.com/docs/rest-api/endpoints#list-deployments +# for personal projects +curl -X GET "https://api.vercel.com/v6/deployments" \ + -H "Authorization: Bearer ${TOKEN}" + +# for project in teams +export TEAM_ID=YOUR_TEAM_ID curl -X GET "https://api.vercel.com/v6/deployments?teamId=${TEAM_ID}" \ -H "Authorization: Bearer ${TOKEN}" ``` diff --git a/action.yml b/action.yml index a0815d5..4716776 100644 --- a/action.yml +++ b/action.yml @@ -9,7 +9,7 @@ inputs: required: true team: description: "Team name" - required: true + required: false options: description: "Cypress options" required: false @@ -18,5 +18,5 @@ runs: image: "Dockerfile" args: - ${{ inputs.vercel-token }} - - ${{ inputs.team }} - ${{ inputs.options }} + - ${{ inputs.team }} diff --git a/entrypoint.sh b/entrypoint.sh index 3729cf9..baf4d5e 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,11 +1,19 @@ #!/bin/sh -l # reference: https://vercel.com/docs/rest-api/endpoints#list-deployments -echo "=> checking url from latest deployment for team ${2}" -DEPLOYMENT_URL=$(curl -X GET "https://api.vercel.com/v6/deployments?teamId=$2" -H "Authorization: Bearer $1" | jq -r '.deployments[0].url') + +# if a team ID is passed, we filter for deployments of this team +if [[ -z "$3" ]]; then + echo "=> checking url from latest deployment for team ${3}" + DEPLOYMENT_URL=$(curl -X GET "https://api.vercel.com/v6/deployments?teamId=$2" -H "Authorization: Bearer $1" | jq -r '.deployments[0].url') +else + echo "=> checking url from latest deployment" + DEPLOYMENT_URL=$(curl -X GET "https://api.vercel.com/v6/deployments" -H "Authorization: Bearer $1" | jq -r '.deployments[0].url') +fi + echo "=> found deployment url: ${DEPLOYMENT_URL}" yarn install export CYPRESS_BASE_URL="https://${DEPLOYMENT_URL}" -npx cypress run $3 \ No newline at end of file +npx cypress run $2 \ No newline at end of file From a4876bb5ce4c52324312b3009c91f0f2becad269 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mischa=20J=C3=B6rg?= Date: Sat, 24 Jun 2023 17:49:34 +0200 Subject: [PATCH 4/6] feat(vercel): set project ID as required --- README.md | 17 ++++++++++------- action.yml | 14 +++++++++++--- entrypoint.sh | 21 +++++++++++---------- 3 files changed, 32 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 8d2adf6..87130e1 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,8 @@ deployment. - [Vercel GitHub integration](https://vercel.com/docs/concepts/git/vercel-for-github). - [Vercel API token](https://vercel.com/account/tokens) which should be stored as an [encrypted secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets) -- If the project is in a team, you also need the team ID +- You need the project ID (which can be found in the "Project Settings" on vercel) +- If your project belongs to a team, you need the team ID as well Make sure that the API token has the right access scope and that your team id is correct. You can do this with the following check; the output should be a large @@ -18,13 +19,13 @@ json payload. # reference: https://vercel.com/docs/rest-api/endpoints#list-deployments export TOKEN=YOUR_VERCEL_API_TOKEN -# for personal projects -curl -X GET "https://api.vercel.com/v6/deployments" \ +export PROJECT_ID=YOUR_PROJECT_ID +curl -X GET "https://api.vercel.com/v6/deployments?projectId=${PROJECT_ID}" \ -H "Authorization: Bearer ${TOKEN}" -# for project in teams +# for team projects export TEAM_ID=YOUR_TEAM_ID -curl -X GET "https://api.vercel.com/v6/deployments?teamId=${TEAM_ID}" \ +curl -X GET "https://api.vercel.com/v6/deployments?projectId=${PROJECT_ID}&teamId=${TEAM_ID}" \ -H "Authorization: Bearer ${TOKEN}" ``` @@ -50,8 +51,10 @@ jobs: with: # required: vercel API token vercel-token: ${{ secrets.VERCEL_TOKEN }} - # required: vercel team name / slug - team: your-team-name + # required: project id + project-id: your-project-id + # required if the project is from a team + team-id: your-team-id # optional: parameters that are passed to 'npx cypress run ' options: "--browser chrome --spec cypress/e2e/base/*" ``` diff --git a/action.yml b/action.yml index 4716776..b97b584 100644 --- a/action.yml +++ b/action.yml @@ -7,16 +7,24 @@ inputs: vercel-token: description: "Vercel API token" required: true - team: - description: "Team name" + default: "" + project-id: + description: "Project ID" + required: true + default: "" + team-id: + description: "Team ID (required if the project is from a team)" required: false + default: "" options: description: "Cypress options" required: false + default: "" runs: using: "docker" image: "Dockerfile" args: - ${{ inputs.vercel-token }} + - ${{ inputs.project-id }} + - ${{ inputs.team-id }} - ${{ inputs.options }} - - ${{ inputs.team }} diff --git a/entrypoint.sh b/entrypoint.sh index baf4d5e..597e78b 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,19 +1,20 @@ #!/bin/sh -l -# reference: https://vercel.com/docs/rest-api/endpoints#list-deployments +# inputs arguments +# 1 -> api token +# 2 -> project id +# 3 -> (optional) team id +# 4 -> cypress options -# if a team ID is passed, we filter for deployments of this team -if [[ -z "$3" ]]; then - echo "=> checking url from latest deployment for team ${3}" - DEPLOYMENT_URL=$(curl -X GET "https://api.vercel.com/v6/deployments?teamId=$2" -H "Authorization: Bearer $1" | jq -r '.deployments[0].url') -else - echo "=> checking url from latest deployment" - DEPLOYMENT_URL=$(curl -X GET "https://api.vercel.com/v6/deployments" -H "Authorization: Bearer $1" | jq -r '.deployments[0].url') +QUERY="projectId=$2" + +if [[ -n "$3" ]]; then + QUERY="${QUERY}&teamId=${3}" fi +DEPLOYMENT_URL=$(curl -X GET "https://api.vercel.com/v6/deployments?${QUERY}" -H "Authorization: Bearer $1" | jq -r '.deployments[0].url') echo "=> found deployment url: ${DEPLOYMENT_URL}" yarn install - export CYPRESS_BASE_URL="https://${DEPLOYMENT_URL}" -npx cypress run $2 \ No newline at end of file +npx cypress run $4 \ No newline at end of file From 7679b4234d26bbd281662041c15eb91ab1fa1f9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mischa=20J=C3=B6rg?= Date: Fri, 1 Dec 2023 00:39:23 +0100 Subject: [PATCH 5/6] chore(cypress): update to latest version --- Dockerfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index b86f810..a2c7d4c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,5 @@ -FROM cypress/included:12.13.0 +# https://hub.docker.com/r/cypress/included/tags +FROM cypress/included:13.6.0 # https://docs.cypress.io/guides/continuous-integration/introduction#Machine-requirements RUN apt-get update && apt-get install -y curl jq @@ -7,4 +8,4 @@ RUN apt-get update && apt-get install -y curl jq COPY entrypoint.sh /entrypoint.sh # Code file to execute when the docker container starts up (`entrypoint.sh`) -ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file +ENTRYPOINT ["/entrypoint.sh"] From 7f2cb9f15b0166e4052859962327ca905f843061 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mischa=20J=C3=B6rg?= Date: Sat, 2 Dec 2023 15:45:11 +0100 Subject: [PATCH 6/6] fix(cypress): remove double brackets in entrypoint --- entrypoint.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 597e78b..173557d 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -8,7 +8,7 @@ QUERY="projectId=$2" -if [[ -n "$3" ]]; then +if [ -n "$3" ]; then QUERY="${QUERY}&teamId=${3}" fi @@ -17,4 +17,4 @@ echo "=> found deployment url: ${DEPLOYMENT_URL}" yarn install export CYPRESS_BASE_URL="https://${DEPLOYMENT_URL}" -npx cypress run $4 \ No newline at end of file +npx cypress run $4