Skip to content
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
10 changes: 7 additions & 3 deletions .github/workflows/vercel-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ on:
description: "Vercel deployment token"
required: true

# Scoped per project so a repo deploying several Vercel projects from one PR
# gets an independent group per project instead of the jobs cancelling each other.
concurrency:
group: vercel-preview-${{ github.event.pull_request.number }}
group: vercel-preview-${{ github.event.pull_request.number }}-${{ inputs.vercel-project-id }}
cancel-in-progress: true

jobs:
Expand Down Expand Up @@ -73,6 +75,8 @@ jobs:
echo "inspect_url=$inspect_url" >> "$GITHUB_OUTPUT"

# Posts (or updates in place) a single comment on the PR with the preview URL.
# The marker is scoped per project so each Vercel project keeps its own
# comment rather than overwriting another project's.
- name: Comment preview URL on PR
env:
GH_TOKEN: ${{ github.token }}
Expand All @@ -82,7 +86,7 @@ jobs:
INSPECT_URL: ${{ steps.deploy.outputs.inspect_url }}
COMMIT_SHA: ${{ github.event.pull_request.head.sha }}
run: |
marker='<!-- vercel-preview -->'
marker="<!-- vercel-preview:${VERCEL_PROJECT_ID} -->"
body="$marker
### ⚡ Preview environment is deploying

Expand All @@ -91,7 +95,7 @@ jobs:
**Preview URL:** ${DEPLOY_URL}
**Inspect:** ${INSPECT_URL}

_Deployed commit ${COMMIT_SHA}_"
_Project ${VERCEL_PROJECT_ID}, deployed commit ${COMMIT_SHA}_"

comment_id="$(gh api "repos/${REPO}/issues/${PR_NUMBER}/comments" \
--jq "[.[] | select(.body | startswith(\"${marker}\"))][0].id")"
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/vercel-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ on:
description: "Vercel deployment token"
required: true

# Scoped per project so a repo deploying several Vercel projects from one push
# gets an independent group per project instead of the jobs queueing behind each other.
concurrency:
group: vercel-production-${{ github.ref }}
group: vercel-production-${{ github.ref }}-${{ inputs.vercel-project-id }}
cancel-in-progress: false

jobs:
Expand Down
35 changes: 35 additions & 0 deletions docs/vercel-preview.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ pull request with the preview and inspect URLs. Intended to be called from a
|---------------|----------|--------------------------|
| vercel-token | ✅ | Vercel deployment token |

#### Concurrency

Runs are grouped by pull request **and** `vercel-project-id`, with
`cancel-in-progress: true`. A new commit supersedes the in-flight preview for
that project, while previews for other projects are left alone.

#### Example Usage

```yaml
Expand All @@ -34,3 +40,32 @@ jobs:
secrets:
vercel-token: ${{ secrets.VERCEL_TOKEN }}
```

#### Deploying more than one Vercel project

Call the workflow once per project. Give each call a distinct
`environment-name`, otherwise every job writes its deployment status and URL to
the same GitHub Environment and the last one to finish wins.

```yaml
jobs:
deploy-storefront-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 }}
environment-name: Preview
secrets:
vercel-token: ${{ secrets.VERCEL_TOKEN }}

deploy-admin-preview:
uses: aligent/workflows/.github/workflows/vercel-preview.yml@main
with:
vercel-org-id: ${{ vars.VERCEL_ORG_ID }}
vercel-project-id: ${{ vars.VERCEL_ADMIN_PROJECT_ID }}
environment-name: Preview - admin
secrets:
vercel-token: ${{ secrets.VERCEL_TOKEN }}
```

Each project gets its own PR comment, keyed on the project ID.
33 changes: 33 additions & 0 deletions docs/vercel-production.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ Deploys a production build to Vercel. Intended to be called from a `push` (or
|---------------|----------|--------------------------|
| vercel-token | ✅ | Vercel deployment token |

#### Concurrency

Runs are grouped by ref **and** `vercel-project-id`, with
`cancel-in-progress: false`. Deploys for the same project queue in order, while
deploys for different projects run in parallel.

#### Example Usage

```yaml
Expand All @@ -34,3 +40,30 @@ jobs:
secrets:
vercel-token: ${{ secrets.VERCEL_TOKEN }}
```

#### Deploying more than one Vercel project

Call the workflow once per project. Give each call a distinct
`environment-name`, otherwise every job writes its deployment status and URL to
the same GitHub Environment and the last one to finish wins.

```yaml
jobs:
deploy-storefront-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 }}
environment-name: Production
secrets:
vercel-token: ${{ secrets.VERCEL_TOKEN }}

deploy-admin-production:
uses: aligent/workflows/.github/workflows/vercel-production.yml@main
with:
vercel-org-id: ${{ vars.VERCEL_ORG_ID }}
vercel-project-id: ${{ vars.VERCEL_ADMIN_PROJECT_ID }}
environment-name: Production - admin
secrets:
vercel-token: ${{ secrets.VERCEL_TOKEN }}
```