Skip to content

Commit a275c25

Browse files
authored
Merge pull request #169 from argos-ci/preview-deployment-vercel
feat: add Vercel preview deployment
2 parents a1ae92d + 88350c1 commit a275c25

1 file changed

Lines changed: 98 additions & 51 deletions

File tree

docs/guides/run-on-preview-deployment.mdx

Lines changed: 98 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -5,53 +5,118 @@ title: Run on Preview Deployments
55

66
# Run on Preview Deployments
77

8-
Seamlessly test preview deployments with Argos: Automate visual testing on platforms like Vercel, Cloudflare, and Netlify via GitHub Actions.
8+
Catch visual regressions **before merging** by running automated tests on every preview deployment.
99

10-
## Configure a GitHub Action
10+
Argos integrates with GitHub Actions and connects seamlessly with providers like **Vercel, Netlify, and Cloudflare**.
1111

12-
For Argos to work with your deployment previews, your deployment service must be integrated with GitHub to create deployments. This setup allows Argos to trigger tests on successful deployment previews.
12+
With this setup:
1313

14-
### GitHub Workflow Configuration
14+
- Each deployment preview is tested automatically
15+
- Regressions are surfaced directly in your pull requests
16+
- Your production baseline stays reliable and up to date
1517

16-
Here's how to configure a GitHub Action to trigger tests with Argos on deployment previews. Create a workflow file in `.github/workflows` directory like so:
18+
## Setup with Vercel repository dispatch events
1719

18-
```yml
20+
Vercel can notify GitHub on every deployment via a [`repository_dispatch` event](https://vercel.com/docs/git/vercel-for-github#repository-dispatch-events).
21+
22+
Argos can use this payload to run visual tests against the preview URL.
23+
24+
```yaml title=".github/workflows/ci.yml"
25+
name: Playwright + Argos Tests
26+
27+
on:
28+
repository_dispatch:
29+
types:
30+
- "vercel.deployment.success"
31+
32+
permissions:
33+
contents: read
34+
# Required to access pull request metadata for Argos with GITHUB_TOKEN
35+
pull-requests: read
36+
37+
jobs:
38+
run-e2es:
39+
runs-on: ubuntu-latest
40+
steps:
41+
- uses: actions/checkout@v4
42+
43+
- uses: actions/setup-node@v4
44+
45+
- name: Install dependencies
46+
run: npm ci && npx playwright install --with-deps
47+
48+
- name: Print context for debugging optional
49+
run: |
50+
echo "URL: ${{ github.event.client_payload.deployment.url || 'none' }}"
51+
52+
- name: Run Playwright tests with Argos reporter
53+
run: npx playwright test
54+
env:
55+
# URL of the preview deployment used by your test as the base URL.
56+
BASE_URL: ${{ github.event.client_payload.deployment.url }}
57+
# Provided by GitHub used by Argos to link builds to branches and pull requests
58+
# Optional, if not provided Argos will not link builds to PRs
59+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
60+
```
61+
62+
## Setup with GitHub deployment status events
63+
64+
If your hosting provider emits GitHub Deployments events Vercel, Netlify, Cloudflare, you can trigger tests from the [`deployment_status` event](https://docs.github.com/en/webhooks/webhook-events-and-payloads#deployment_status).
65+
66+
The event carries the preview URL when a deployment becomes successful.
67+
68+
```yaml title=".github/workflows/ci.yml"
1969
name: Playwright + Argos Tests
2070
2171
on:
2272
deployment_status:
73+
74+
permissions:
75+
contents: read
76+
# Required to access pull request metadata for Argos with GITHUB_TOKEN
77+
pull-requests: read
78+
2379
jobs:
2480
run-e2es:
2581
# Run tests only if the deployment is successful
2682
if: github.event_name == 'deployment_status' && github.event.deployment_status.state == 'success'
83+
2784
runs-on: ubuntu-latest
85+
2886
steps:
2987
- uses: actions/checkout@v4
30-
- uses: actions/setup-node@v3
88+
89+
- uses: actions/setup-node@v4
90+
3191
- name: Install dependencies
3292
run: npm ci && npx playwright install --with-deps
33-
- name: Run tests
93+
94+
- name: Print context for debugging optional
95+
run: |
96+
echo "URL: ${{ github.event.deployment_status.environment_url || 'none' }}"
97+
echo "Production: ${{ github.event.deployment_status.environment == 'Production' || false }}"
98+
99+
- name: Run Playwright tests with Argos reporter recommended
34100
run: npx playwright test
35101
env:
36-
# Use this environment variable as `baseUrl` in your playwright.config.ts
37-
BASE_URL: ${{ github.event.deployment_status.environment_url }}
38-
# Argos uses GITHUB_TOKEN to collect branch and pull request information
102+
# URL of the preview deployment used by your test as the base URL.
103+
BASE_URL: ${{ github.event.client_payload.deployment.url }}
104+
# Set only for production deployments to ensure stable baselines usually `main`.
105+
ARGOS_BRANCH: ${{ github.event.client_payload.deployment.meta.production && 'main' || '' }}
106+
# Provided by GitHub used by Argos to link builds to branches and pull requests
107+
# Optional, if not provided Argos will not link builds to PRs
39108
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40-
# Set the branch when your deployment runs on "Production" environment.
41-
ARGOS_BRANCH: ${{ github.event.deployment_status.environment == 'Production' && 'main' || '' }}
42109
```
43110
44-
**Environment Variables Explained:**
111+
## Disable the Vercel Toolbar
45112
46-
- `BASE_URL`: Set to your deployment URL, for running E2E tests on the actual preview.
47-
- `GITHUB_TOKEN`: Used by Argos for accessing branch and PR info. [Provided by default by GitHub](https://docs.github.com/en/actions/security-guides/automatic-token-authentication).
48-
- `ARGOS_BRANCH`: Needed when deploying to "Production". Argos requires you to manually specify the branch in this case.
113+
By default, Vercel may inject a toolbar overlay into preview deployments. This can interfere with automated screenshots.
49114
50-
### Disable Vercel Toolbar
115+
To avoid false diffs, disable the toolbar in your tests by sending the [`x-vercel-skip-toolbar` header](https://vercel.com/docs/vercel-toolbar/managing-toolbar#disable-toolbar-for-automation) with every request.
51116

52-
The Vercel Toolbar might appear in your screenshots. Here's [how to disable it](https://vercel.com/docs/workflow-collaboration/vercel-toolbar#disable-toolbar-for-session) for cleaner test visuals:
117+
### Playwright
53118

54-
**For Playwright:**
119+
Add the header in your `playwright.config.ts` so all test requests skip the toolbar:
55120

56121
```ts title="playwright.config.ts"
57122
import { defineConfig } from "@playwright/test";
@@ -65,48 +130,30 @@ export default defineConfig({
65130
});
66131
```
67132

68-
**For Cypress:**
133+
### Cypress
134+
135+
Inject the header for all network requests in your test suite:
69136

70-
```ts title="support/index.js"
137+
```ts title="support/index.ts"
71138
beforeEach(() => {
72139
cy.intercept(`${Cypress.config("baseUrl")}**`, (req) => {
73140
req.headers["x-vercel-skip-toolbar"] = "1";
74141
});
75142
});
76143
```
77144

78-
### Opting Out of `GITHUB_TOKEN`
79-
80-
If you prefer not to use `GITHUB_TOKEN` due to security concerns, be aware of the following limitations:
145+
## Running without GITHUB_TOKEN
81146

82-
- Deployments will be linked to the branch name rather than specific PR info.
83-
- No direct PR link will be available in Argos.
147+
You can run Argos tests without exposing `GITHUB_TOKEN`. This is useful if you want to limit token scope in deployment workflows.
84148

85-
To mitigate these limitations, it's important to designate your main production environment (e.g., "Production" in Vercel) as the "reference branch" in your project's Argos settings.
149+
However, some features will not be available:
86150

87-
![Screenshot showing how to configure "Production" as the reference branch in Argos project settings](./run-on-preview-deployment/configure-reference-branch.png)
151+
- Builds are only associated with a branch (no pull request metadata).
152+
- No pull request link will appear in Argos.
88153

89-
To configure without GITHUB_TOKEN:
154+
:::note
90155

91-
```yml
92-
name: Playwright + Argos Tests
93-
94-
on:
95-
deployment_status:
96-
jobs:
97-
run-e2es:
98-
# Run tests only if the deployment is successful
99-
if: github.event_name == 'deployment_status' && github.event.deployment_status.state == 'success'
100-
runs-on: ubuntu-latest
101-
steps:
102-
- uses: actions/checkout@v4
103-
- name: Install dependencies
104-
run: npm ci && npx playwright install --with-deps
105-
- name: Run tests
106-
run: npx playwright test
107-
env:
108-
# Use this environment variable as `baseUrl` in your plawright.config.ts
109-
BASE_URL: ${{ github.event.deployment_status.environment_url }}
110-
```
156+
Argos SDKs warn if `GITHUB_TOKEN` is missing. To silence this, set
157+
`DISABLE_GITHUB_TOKEN_WARNING=true`.
111158

112-
Argos SDKs show a warning when a `GITHUB_TOKEN` is not set. You can suppress this warning by setting the `DISABLE_GITHUB_TOKEN_WARNING` environment variable to true.
159+
:::

0 commit comments

Comments
 (0)