Skip to content

Edit the Vercel preview workflow #6838

Edit the Vercel preview workflow

Edit the Vercel preview workflow #6838

Workflow file for this run

---
name: Deploy Vercel Preview
permissions:
# Required in order to comment on PRs with a deployment link
pull-requests: write
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
on:
pull_request:
paths:
- 'docs/**'
- .github/workflows/vercel-preview.yaml
types: [opened, reopened, synchronize]
workflow_dispatch:
jobs:
deploy-vercel-preview:
name: Deploy Vercel preview
runs-on: ubuntu-latest
environment: vercel
steps:
- name: Extract branch name
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: extract_branch
- uses: actions/checkout@v4
with:
repository: 'gravitational/docs'
- name: Configure Submodules
env:
BRANCH: ${{ steps.extract_branch.outputs.branch }}
# Edit config.json and .gitmodules so there is a single submodule
# pointing to the version of the docs to deploy to the preview site.
run: |
git rm content/*
git submodule add --force -b "${BRANCH}" https://github.com/gravitational/teleport content/preview
echo "{\"versions\": [{\"name\": \"preview\", \"branch\": \"preview\", \"deprecated\": false, \"latest\": true}]}" > config.json
git submodule update --init --remote --progress
- name: Install Vercel CLI
run: yarn global add vercel@latest
- name: Pull Vercel Environment Information
run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}
- name: Build Project Artifacts
run: vercel build --token=${{ secrets.VERCEL_TOKEN }}
- name: Deploy Project Artifacts to Vercel
id: deploy
run: |
vercel deploy --archive=tgz --prebuilt --token=${{ secrets.VERCEL_TOKEN }} > deployment-url.txt
preview_url="$(cat deployment-url.txt)"
echo "PREVIEW_URL=$preview_url" >> $GITHUB_OUTPUT
- uses: actions/github-script@v7
env:
PREVIEW_URL: ${{ steps.deploy.outputs.PREVIEW_URL }}
with:
script: |
const previewUrl = process.env.PREVIEW_URL
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `🤖 Vercel preview here: ${previewUrl}/docs`
})