This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Vercel deployment preview link generator | |
on: | |
pull_request: | |
types: [opened, synchronize] | |
paths: | |
- 'website/docs/docs/**' | |
- 'website/docs/best-practices/**' | |
- 'website/docs/guides/**' | |
- 'website/docs/faqs/**' | |
- 'website/docs/reference/**' | |
permissions: | |
contents: read | |
pull-requests: write | |
jobs: | |
comment-deployment-link: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Wait for Vercel deployment | |
run: | | |
echo "Waiting for Vercel deployment to complete..." | |
sleep 300 # Adjust based on deployment time | |
- name: Install GitHub CLI and jq | |
run: | | |
sudo apt-get install jq -y | |
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg | |
sudo apt-get install gh -y | |
- name: Get Vercel deployment URL from GitHub Check | |
id: vercel_url | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
CHECK_RUNS=$(gh api repos/${{ github.repository }}/commits/${{ github.sha }}/check-runs) | |
VERCEL_URL=$(echo $CHECK_RUNS | jq -r '.check_runs[] | select(.name=="Vercel") | .details_url') | |
echo "::set-output name=deployment_url::${VERCEL_URL}" | |
- name: Get changed files | |
id: files | |
run: | | |
CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep 'website/docs/docs/') | |
echo "::set-output name=changed_files::${CHANGED_FILES}" | |
- name: Generate file preview links | |
id: links | |
run: | | |
DEPLOYMENT_URL="${{ steps.vercel_url.outputs.deployment_url }}" | |
CHANGED_FILES="${{ steps.files.outputs.changed_files }}" | |
# Strip the 'website/docs/docs/' portion and append the rest to the URL | |
LINKS=$(echo "$CHANGED_FILES" | sed 's#website/docs/docs/##; s/.md$//' | awk -v url="$DEPLOYMENT_URL" '{print "- [" $0 "](" url "/docs/" $0 ")"}') | |
echo "::set-output name=links::${LINKS}" | |
- name: Post comment with deployment link | |
uses: peter-evans/[email protected] | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
issue-number: ${{ github.event.pull_request.number }} | |
body: | | |
🚀 Deployment available: ${{ steps.vercel_url.outputs.deployment_url }} | |
Here are the direct links to the updated files: | |
${{ steps.links.outputs.links }} |