Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ci check that auto comments preview link #6128

Merged
merged 48 commits into from
Oct 15, 2024
Merged
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
93e0764
add yaml for preview link
mirnawong1 Sep 19, 2024
1e3e67a
add 120 secs
mirnawong1 Sep 19, 2024
6baf517
test
mirnawong1 Sep 19, 2024
b6416c0
test
mirnawong1 Sep 19, 2024
8b9be8c
test
mirnawong1 Sep 19, 2024
1178945
test
mirnawong1 Sep 19, 2024
5e402e2
test
mirnawong1 Sep 19, 2024
c8634a3
test
mirnawong1 Sep 19, 2024
c6a5cb9
test
mirnawong1 Sep 19, 2024
4ebcda4
update yaml
mirnawong1 Sep 19, 2024
2a2df9a
add
mirnawong1 Sep 20, 2024
b7fc7e2
add
mirnawong1 Sep 20, 2024
b050146
add
mirnawong1 Sep 20, 2024
94d82f4
add
mirnawong1 Sep 20, 2024
bf9a57a
add
mirnawong1 Sep 20, 2024
99f4176
add
mirnawong1 Sep 20, 2024
d59c34b
add
mirnawong1 Sep 20, 2024
0320862
add
mirnawong1 Sep 20, 2024
7301eab
add
mirnawong1 Sep 24, 2024
88bb8e5
add
mirnawong1 Sep 24, 2024
da41198
add
mirnawong1 Sep 24, 2024
906cb2b
add
mirnawong1 Sep 24, 2024
889a438
Merge branch 'current' into mwong-add-preview-link
mirnawong1 Sep 24, 2024
9eb8d03
add
mirnawong1 Sep 25, 2024
e073651
add
mirnawong1 Sep 25, 2024
7d62b07
add
mirnawong1 Sep 25, 2024
6a9e9bb
add
mirnawong1 Sep 25, 2024
cc05bcf
add
mirnawong1 Sep 25, 2024
59069e1
add
mirnawong1 Sep 25, 2024
37ad7de
add
mirnawong1 Sep 25, 2024
bc8474d
add
mirnawong1 Sep 25, 2024
964fc6d
add
mirnawong1 Sep 25, 2024
9618c96
add
mirnawong1 Sep 25, 2024
d3bbee0
add
mirnawong1 Sep 25, 2024
48ed9db
add
mirnawong1 Sep 25, 2024
8c6c617
add
mirnawong1 Sep 25, 2024
0e407fa
add
mirnawong1 Sep 25, 2024
7734934
Merge branch 'current' into mwong-add-preview-link
mirnawong1 Sep 25, 2024
de24bc4
Merge branch 'current' into mwong-add-preview-link
mirnawong1 Sep 26, 2024
d689a19
Merge branch 'current' into mwong-add-preview-link
mirnawong1 Sep 26, 2024
20484c4
Merge branch 'current' into mwong-add-preview-link
mirnawong1 Sep 27, 2024
cd03900
Merge branch 'current' into mwong-add-preview-link
mirnawong1 Sep 27, 2024
61a077b
Merge branch 'current' into mwong-add-preview-link
mirnawong1 Oct 4, 2024
e0596c7
update
mirnawong1 Oct 4, 2024
34b2ddb
add line
mirnawong1 Oct 4, 2024
3174310
Merge branch 'current' into mwong-add-preview-link
mirnawong1 Oct 4, 2024
de48728
Merge branch 'current' into mwong-add-preview-link
mirnawong1 Oct 15, 2024
6616308
Merge branch 'current' into mwong-add-preview-link
mirnawong1 Oct 15, 2024
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
169 changes: 169 additions & 0 deletions .github/workflows/preview-link.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
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: write
pull-requests: write

jobs:
update-pr-description:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install necessary tools
run: |
sudo apt-get update
sudo apt-get install -y jq curl
- name: Generate Vercel deployment URL
id: vercel_url
run: |
# Get the branch name
BRANCH_NAME="${{ github.head_ref }}"
# Convert to lowercase
BRANCH_NAME_LOWER=$(echo "$BRANCH_NAME" | tr '[:upper:]' '[:lower:]')
# Replace non-alphanumeric characters with hyphens
BRANCH_NAME_SANITIZED=$(echo "$BRANCH_NAME_LOWER" | sed 's/[^a-z0-9]/-/g')
# Construct the deployment URL
DEPLOYMENT_URL="https://docs-getdbt-com-git-${BRANCH_NAME_SANITIZED}-dbt-labs.vercel.app"
echo "deployment_url=$DEPLOYMENT_URL" >> $GITHUB_OUTPUT
- name: Wait for deployment to be accessible
id: wait_for_deployment
run: |
DEPLOYMENT_URL="${{ steps.vercel_url.outputs.deployment_url }}"
echo "Waiting for deployment at $DEPLOYMENT_URL to become accessible..."
MAX_ATTEMPTS=60 # Wait up to 10 minutes
SLEEP_TIME=10 # Check every 10 seconds
ATTEMPTS=0
while [ $ATTEMPTS -lt $MAX_ATTEMPTS ]; do
STATUS_CODE=$(curl -s -o /dev/null -w "%{http_code}" "$DEPLOYMENT_URL")
if [ "$STATUS_CODE" -eq 200 ]; then
echo "Deployment is accessible."
break
else
echo "Deployment not yet accessible (status code: $STATUS_CODE). Waiting..."
sleep $SLEEP_TIME
ATTEMPTS=$((ATTEMPTS + 1))
fi
done
if [ $ATTEMPTS -eq $MAX_ATTEMPTS ]; then
echo "Deployment did not become accessible within the 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 -E '^website/docs/(docs|best-practices|guides|faqs|reference)/.*\.md$' || true)
if [ -z "$CHANGED_FILES" ]; then
echo "No documentation files were changed."
echo "changed_files=" >> $GITHUB_OUTPUT
else
CHANGED_FILES=$(echo "$CHANGED_FILES" | tr '\n' ' ')
echo "changed_files=$CHANGED_FILES" >> $GITHUB_OUTPUT
fi
- name: Generate file preview links
id: links
run: |
DEPLOYMENT_URL="${{ steps.vercel_url.outputs.deployment_url }}"
CHANGED_FILES="${{ steps.files.outputs.changed_files }}"
if [ -z "$CHANGED_FILES" ]; then
echo "No changed files found in the specified directories."
LINKS="No documentation files were changed."
else
LINKS=""
# Convert CHANGED_FILES back to newline-separated for processing
CHANGED_FILES=$(echo "$CHANGED_FILES" | tr ' ' '\n')
for FILE in $CHANGED_FILES; do
# Remove 'website/docs/' prefix
FILE_PATH="${FILE#website/docs/}"
# Remove the .md extension
FILE_PATH="${FILE_PATH%.md}"
# Construct the full URL
FULL_URL="$DEPLOYMENT_URL/$FILE_PATH"
LINKS="$LINKS\n- $FULL_URL"
done
fi
# Properly set the multi-line output
echo "links<<EOF" >> $GITHUB_OUTPUT
echo -e "$LINKS" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Update PR description with deployment links
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const prNumber = context.issue.number;
// Fetch the current PR description
const { data: pullRequest } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
});
let body = pullRequest.body || '';
// Define the markers
const startMarker = '<!-- vercel-deployment-preview -->';
const endMarker = '<!-- end-vercel-deployment-preview -->';
// Get the deployment URL and links from environment variables
const deploymentUrl = process.env.DEPLOYMENT_URL;
const links = process.env.LINKS;
// Build the deployment content without leading whitespace
const deploymentContent = [
`${startMarker}`,
'---',
'🚀 Deployment available! Here are the direct links to the updated files:',
'',
`${links}`,
'',
`${endMarker}`
].join('\n');
// Remove existing deployment content between markers
const regex = new RegExp(`${startMarker}[\\s\\S]*?${endMarker}`, 'g');
body = body.replace(regex, '').trim();
// Append the new deployment content
body = `${body}\n\n${deploymentContent}`;
// Update the PR description
await github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
body: body,
});
env:
DEPLOYMENT_URL: ${{ steps.vercel_url.outputs.deployment_url }}
LINKS: ${{ steps.links.outputs.links }}
Loading