Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rewrite #74

Merged
merged 6 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 0 additions & 67 deletions .github/workflows/codeql-analysis.yml

This file was deleted.

20 changes: 6 additions & 14 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,13 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
fetch-depth: 0
node-version: lts/*

- name: npm-cache
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ env.cache-name }}-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-${{ env.cache-name }}
${{ runner.os }}-node

- name: install
run: npm ci
- name: Install dependencies
run: npm install -g pnpm && pnpm install

- name: test
run: npm run test:ci:coverage
run: pnpm test
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
trailingComma: 'es5'
tabWidth: 2
printWidth: 120
tabs: true
semi: true
singleQuote: true
7 changes: 0 additions & 7 deletions .prettierrc.js

This file was deleted.

114 changes: 90 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,72 +12,138 @@ The github secret `${{ secrets.GITHUB_TOKEN }}`

### `environment`

Optional — The name of the environment that was deployed to (e.g., staging or production)
Optional — The name of the environment that was deployed to (e.g., Preview, staging or production). Defaults to 'Preview'.

### `max_timeout`
### `deployment_creator_name`

Optional — The amount of time to spend waiting on Vercel. Defaults to `60` seconds
Optional — The name of the user who created the deployment. Defaults to 'vercel[bot]'.

### `vercel_protection_bypass_secret`

Optional — Vercel protection bypass for automation.

### `allow_inactive`

Optional - Use the most recent inactive deployment (previously deployed preview) associated with the pull request if
no new deployment is available. Defaults to `false`.
Optional — Use the most recent inactive deployment (previously deployed preview) associated with the pull request if no new deployment is available.

### `check_interval`
### `path`

Optional - How often (in seconds) should we make the HTTP request checking to see if the deployment is available? Defaults to `2` seconds.
Optional — The relative path to run the health check on, useful if you want to check a specific route. Defaults to ''.

### `vercel_password`
### `max_attempts`

Optional - The [password](https://vercel.com/docs/concepts/projects/overview#password-protection) for the deployment
Optional The number of retry attempts for each stage (1. lookup PR, 2. find deployment, 3. lookup deployment status, 4. health check) to do before failing. Defaults to '20'.

### `vercel_protection_bypass_header`
### `retry_interval`

Optional - The [header](https://vercel.com/docs/security/deployment-protection/methods-to-bypass-deployment-protection/protection-bypass-automation) to bypass protection for automation
Optional The number of seconds to wait between retry attempts. Defaults to '30'.

### `path`
### `max_timeout` (Deprecated)

Optional — The max time to run the action. This input is deprecated and will be removed in a future release. Please use `max_attempts` & `retry_interval` instead.

### `check_interval` (Deprecated)

Optional — How often (in seconds) should we make the HTTP request checking to see if the deployment is available? This input is deprecated and will be removed in a future release. Please use `max_attempts` & `retry_interval` instead.

### `vercel_password` (Deprecated)

Optional - The URL that tests should run against (eg. `path: "https://vercel.com"`).
Optional — Vercel password protection secret. This input is deprecated and will be removed in a future release. Please use `vercel_protection_bypass_secret` instead.

### `vercel_protection_bypass_header` (Deprecated)

Optional — Vercel protection bypass for automation. This input is deprecated and will be removed in a future release. Please use `vercel_protection_bypass_secret` instead.

## Outputs

### `url`

The vercel deploy preview url that was deployed.

### `vercel_jwt`

If accessing a password protected site, the JWT from the login event. This can be passed on to e2e tests, for instance.
### `vercel_jwt` (Deprecated)
This is no longer available. If accessing a password protected site, the JWT from the login event. This can be passed on to e2e tests, for instance.

## Example usage

Basic Usage

```yaml
steps:
- name: Waiting for 200 from the Vercel Preview
uses: patrickedqvist/wait-for-vercel-preview@v1.3.1
id: waitFor200
- name: Health check vercel deployment
uses: patrickedqvist/wait-for-vercel-preview@v2
id: healthCheck
with:
token: ${{ secrets.GITHUB_TOKEN }}
max_timeout: 60
max_attempts: 20
# access preview url
- run: echo ${{steps.waitFor200.outputs.url}}
- run: echo ${{steps.healthCheck.outputs.url}}
```

## Building

The Action is bundled via [ncc](https://github.com/vercel/ncc). See [this discussion](https://github.com/actions/hello-world-javascript-action/issues/12) for more information.

```sh
npm run build
pnpm run build
# outputs the build to dist/index.js
```

## Tests

Unit tests with [Jest](https://jestjs.io/) and [Mock Service Worker](https://mswjs.io/)
Unit tests with [Vitest](https://vitest.dev/) and [Mock Service Worker](https://mswjs.io/)

```
npm test
pnpm test
```

## Upgrading from Version 1.x to Version 2.x

For users transitioning from Version 1.x to Version 2.0, we've made several improvements and changes to enhance your experience. This section will guide you through the key differences and help you make a smooth transition.

### Key Changes:

1. Deprecated Inputs: Several inputs have been deprecated and will be removed in future releases:
- `max_timeout`: Use `max_attempts` & `retry_interval` instead.
- `check_interval`: Use `max_attempts` & `retry_interval` instead.
- `vercel_password`: Use `vercel_protection_bypass_secret` instead.
- `vercel_protection_bypass_header`: Use `vercel_protection_bypass_secret` instead.

2. New Inputs:
- `max_attempts`: The number of retry attempts for each stage.
- `retry_interval`: The number of seconds to wait between retry attempts.
- `vercel_protection_bypass_secret`: Vercel protection bypass for automation.
- `allow_inactive`: Use the most recent inactive deployment if no new deployment is available.
- `path`: The relative path to run the health check on.
- `deployment_creator_name`: The name of the user who created the deployment. Defaults to 'vercel[bot]'.

3. Removed Outputs:
- `vercel_jwt`: This output is no longer available.

4. Environment Naming: The `environment` input now defaults to 'Preview' instead of 'Production'.

5. Clarified logging. It now clearly seperates the differente steps in "stages". Where stage one is looking up the PR, stage two is finding the deployment, stage three is looking up the deployment status and stage four is the health check.

Upgrade Process:

1. Update your workflow YAML file to use the new input names and remove deprecated ones.
2. Adjust your retry logic using `max_attempts` and `retry_interval` instead of `max_timeout` and `check_interval`.
3. If you were using `vercel_password` or `vercel_protection_bypass_header`, switch to `vercel_protection_bypass_secret`.
4. Remove any references to the `vercel_jwt` output in your workflow.
5. Review the new inputs to see if they can benefit your workflow.

Example of updated usage:

```yaml
steps:
- name: Health check vercel deployment
uses: patrickedqvist/wait-for-vercel-preview@v2
id: healthCheck
with:
token: ${{ secrets.GITHUB_TOKEN }}
max_attempts: 20
retry_interval: 30
# access preview url
- run: echo ${{steps.healthCheck.outputs.url}}
```

If you encounter any issues during or after the upgrade, please refer to the full documentation or open an issue on the GitHub repository.
Loading