Skip to content
Open
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
98 changes: 98 additions & 0 deletions .github/workflows/vercel-preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: Vercel Preview Deployment

on:
workflow_call:
inputs:
vercel-org-id:
description: "Vercel organisation ID"
type: string
required: true
vercel-project-id:
description: "Vercel project ID"
type: string
required: true
working-directory:
description: "Directory to run the Vercel deploy from"
type: string
required: false
default: "."
environment-name:
description: "GitHub Environment to deploy to"
type: string
required: false
default: "Preview"
secrets:
vercel-token:
description: "Vercel deployment token"
required: true

concurrency:
group: vercel-preview-${{ github.event.pull_request.number }}
cancel-in-progress: true

jobs:
deploy-preview:
name: Deploy Preview to Vercel
runs-on: ubuntu-latest
permissions:
contents: read
deployments: write
pull-requests: write
environment:
name: ${{ inputs.environment-name }}
url: ${{ steps.deploy.outputs.url }}
env:
VERCEL_ORG_ID: ${{ inputs.vercel-org-id }}
VERCEL_PROJECT_ID: ${{ inputs.vercel-project-id }}
VERCEL_TELEMETRY_DISABLED: 1
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd #v6.0.2
with:
persist-credentials: false

- name: Install Vercel CLI
run: npm install --global vercel@latest

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we pin this to a specific version rather than use @latest for supply chain reasons?


- name: Deploy to Vercel (preview)
id: deploy
working-directory: ${{ inputs.working-directory }}
env:
VERCEL_TOKEN: ${{ secrets.vercel-token }}
run: |
vercel deploy --yes --no-wait --token="$VERCEL_TOKEN" \
> deployment-url.txt 2> >(tee vercel-output.log >&2)
url="$(cat deployment-url.txt)"
inspect_url="$(grep -m1 -o 'https://vercel.com/[^[:space:]]*' vercel-output.log || true)"
echo "url=$url" >> "$GITHUB_OUTPUT"
echo "inspect_url=$inspect_url" >> "$GITHUB_OUTPUT"

# Posts (or updates in place) a single comment on the PR with the preview URL.
- name: Comment preview URL on PR
env:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
REPO: ${{ github.repository }}
DEPLOY_URL: ${{ steps.deploy.outputs.url }}
INSPECT_URL: ${{ steps.deploy.outputs.inspect_url }}
COMMIT_SHA: ${{ github.event.pull_request.head.sha }}
run: |
marker='<!-- vercel-preview -->'
body="$marker
### ⚡ Preview environment is deploying

Wait ~5 minutes for completion, or monitor progress using the Inspect URL.

**Preview URL:** ${DEPLOY_URL}
**Inspect:** ${INSPECT_URL}

_Deployed commit ${COMMIT_SHA}_"

comment_id="$(gh api "repos/${REPO}/issues/${PR_NUMBER}/comments" \
--jq "[.[] | select(.body | startswith(\"${marker}\"))][0].id")"

if [ -n "$comment_id" ] && [ "$comment_id" != "null" ]; then
gh api -X PATCH "repos/${REPO}/issues/comments/${comment_id}" -f body="$body"
else
gh api -X POST "repos/${REPO}/issues/${PR_NUMBER}/comments" -f body="$body"
fi
63 changes: 63 additions & 0 deletions .github/workflows/vercel-production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Vercel Production Deployment

on:
workflow_call:
inputs:
vercel-org-id:
description: "Vercel organisation ID"
type: string
required: true
vercel-project-id:
description: "Vercel project ID"
type: string
required: true
working-directory:
description: "Directory to run the Vercel deploy from"
type: string
required: false
default: "."
environment-name:
description: "GitHub Environment to deploy to"
type: string
required: false
default: "Production"
secrets:
vercel-token:
description: "Vercel deployment token"
required: true

concurrency:
group: vercel-production-${{ github.ref }}
cancel-in-progress: false

jobs:
deploy-production:
name: Deploy Production to Vercel
runs-on: ubuntu-latest
permissions:
contents: read
deployments: write
environment:
name: ${{ inputs.environment-name }}
url: ${{ steps.deploy.outputs.url }}
env:
VERCEL_ORG_ID: ${{ inputs.vercel-org-id }}
VERCEL_PROJECT_ID: ${{ inputs.vercel-project-id }}
VERCEL_TELEMETRY_DISABLED: 1
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd #v6.0.2
with:
persist-credentials: false

- name: Install Vercel CLI
run: npm install --global vercel@latest

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto here.


- name: Deploy to Vercel (production)
id: deploy
working-directory: ${{ inputs.working-directory }}
env:
VERCEL_TOKEN: ${{ secrets.vercel-token }}
run: |
url="$(vercel deploy --prod --yes --no-wait --token="$VERCEL_TOKEN")"
echo "url=$url" >> "$GITHUB_OUTPUT"
36 changes: 36 additions & 0 deletions docs/vercel-preview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Vercel Preview Deployment

Deploys a preview build to Vercel and posts (or updates) a single comment on the
pull request with the preview and inspect URLs. Intended to be called from a
`pull_request` triggered workflow.

#### **Inputs**
| Name | Required | Type | Default | Description |
|--------------------|----------|--------|----------|----------------------------------------|
| vercel-org-id | ✅ | string | | Vercel organisation ID |
| vercel-project-id | ✅ | string | | Vercel project ID |
| working-directory | ❌ | string | . | Directory to run the Vercel deploy from |
| environment-name | ❌ | string | Preview | GitHub Environment to deploy to |

#### **Secrets**
| Name | Required | Description |
|---------------|----------|--------------------------|
| vercel-token | ✅ | Vercel deployment token |

#### Example Usage

```yaml
on:
pull_request:
branches:
- main

jobs:
deploy-preview:
uses: aligent/workflows/.github/workflows/vercel-preview.yml@main
with:
vercel-org-id: ${{ vars.VERCEL_ORG_ID }}
vercel-project-id: ${{ vars.VERCEL_PROJECT_ID }}
secrets:
vercel-token: ${{ secrets.VERCEL_TOKEN }}
```
36 changes: 36 additions & 0 deletions docs/vercel-production.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Vercel Production Deployment

Deploys a production build to Vercel. Intended to be called from a `push` (or
`workflow_dispatch`) triggered workflow.

#### **Inputs**
| Name | Required | Type | Default | Description |
|--------------------|----------|--------|------------|----------------------------------------|
| vercel-org-id | ✅ | string | | Vercel organisation ID |
| vercel-project-id | ✅ | string | | Vercel project ID |
| working-directory | ❌ | string | . | Directory to run the Vercel deploy from |
| environment-name | ❌ | string | Production | GitHub Environment to deploy to |

#### **Secrets**
| Name | Required | Description |
|---------------|----------|--------------------------|
| vercel-token | ✅ | Vercel deployment token |

#### Example Usage

```yaml
on:
push:
branches:
- main
workflow_dispatch:

jobs:
deploy-production:
uses: aligent/workflows/.github/workflows/vercel-production.yml@main
with:
vercel-org-id: ${{ vars.VERCEL_ORG_ID }}
vercel-project-id: ${{ vars.VERCEL_PROJECT_ID }}
secrets:
vercel-token: ${{ secrets.VERCEL_TOKEN }}
```