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: Install GitHub CLI and jq | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y jq | |
sudo apt-get install -y gh | |
- name: Wait for Vercel deployment | |
id: vercel_deploy | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
CHECK_RUN_ID="" | |
ATTEMPTS=0 | |
MAX_ATTEMPTS=30 # Adjust as needed | |
SLEEP_TIME=10 # Adjust as needed | |
while [ $ATTEMPTS -lt $MAX_ATTEMPTS ]; do | |
CHECK_RUNS=$(gh api repos/${{ github.repository }}/commits/${{ github.sha }}/check-runs) | |
VERCEL_CHECK=$(echo $CHECK_RUNS | jq '.check_runs[] | select(.name=="Vercel")') | |
if [ -n "$VERCEL_CHECK" ]; then | |
STATUS=$(echo $VERCEL_CHECK | jq -r '.status') | |
CONCLUSION=$(echo $VERCEL_CHECK | jq -r '.conclusion') | |
if [ "$STATUS" == "completed" ]; then | |
if [ "$CONCLUSION" == "success" ]; then | |
echo "Vercel deployment completed successfully." | |
VERCEL_URL=$(echo $VERCEL_CHECK | jq -r '.details_url') | |
echo "deployment_url=$VERCEL_URL" >> $GITHUB_OUTPUT | |
break | |
else | |
echo "Vercel deployment failed." | |
exit 1 | |
fi | |
else | |
echo "Vercel deployment status: $STATUS. Waiting..." | |
fi | |
else | |
echo "Vercel check not found. Waiting..." | |
fi | |
ATTEMPTS=$((ATTEMPTS + 1)) | |
sleep $SLEEP_TIME | |
done | |
if [ $ATTEMPTS -eq $MAX_ATTEMPTS ]; then | |
echo "Vercel deployment did not complete within expected time." | |
exit 1 | |
fi | |
- 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 "changed_files=$CHANGED_FILES" >> $GITHUB_OUTPUT | |
- name: Generate file preview links | |
id: links | |
run: | | |
DEPLOYMENT_URL="${{ steps.vercel_deploy.outputs.deployment_url }}" | |
CHANGED_FILES="${{ steps.files.outputs.changed_files }}" | |
LINKS=$(echo "$CHANGED_FILES" | sed 's#website/docs/docs/##; s/.md$//' | awk -v url="$DEPLOYMENT_URL" '{print "- [" $0 "](" url "/docs/" $0 ")"}') | |
echo "links=$LINKS" >> $GITHUB_OUTPUT | |
- name: Post comment with deployment link | |
uses: peter-evans/create-or-update-comment@v4 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
issue-number: ${{ github.event.pull_request.number }} | |
body: | | |
🚀 Deployment available: ${{ steps.vercel_deploy.outputs.deployment_url }} | |
Here are the direct links to the updated files: | |
${{ steps.links.outputs.links }} |