From 93e07646882de2b6b0c9b5a626a47d7498cc13d8 Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Thu, 19 Sep 2024 12:36:10 +0100 Subject: [PATCH 01/38] add yaml for preview link --- .github/workflows/preview-link.yml | 38 ++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .github/workflows/preview-link.yml diff --git a/.github/workflows/preview-link.yml b/.github/workflows/preview-link.yml new file mode 100644 index 00000000000..1505329c220 --- /dev/null +++ b/.github/workflows/preview-link.yml @@ -0,0 +1,38 @@ +name: Vercel deployment preview link generator + +on: + pull_request: + types: [opened, synchronize] + +jobs: + comment-deployment-link: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Get vercel deployment URL + id: vercel + run: | + # Fetch the Vercel URL using API or extract from a known pattern + DEPLOYMENT_URL="https://docs-getdbt-${{ github.sha }}-dbt-labs.vercel.app" + echo "::set-output name=deployment_url::${DEPLOYMENT_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: Post comment with deployment link + uses: peter-evans/create-or-update-comment@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + issue-number: ${{ github.event.pull_request.number }} + body: | + šŸš€ Deployment available: ${{ steps.vercel.outputs.deployment_url }} + Here are the direct links to the updated files: + + ${{ steps.files.outputs.changed_files }} + + You can review the changes directly in the deployed environment! From 1e3e67a0c9757dc9f80c1837201115c791c7ad6c Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Thu, 19 Sep 2024 12:41:51 +0100 Subject: [PATCH 02/38] add 120 secs --- .github/workflows/preview-link.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/preview-link.yml b/.github/workflows/preview-link.yml index 1505329c220..9cb08a45bd0 100644 --- a/.github/workflows/preview-link.yml +++ b/.github/workflows/preview-link.yml @@ -7,14 +7,19 @@ on: jobs: comment-deployment-link: runs-on: ubuntu-latest + steps: + - name: Wait for Vercel deployment + run: | + echo "Waiting for Vercel deployment to complete..." + sleep 120 # Adjust this based on your deployment time + - name: Checkout code uses: actions/checkout@v3 - name: Get vercel deployment URL id: vercel run: | - # Fetch the Vercel URL using API or extract from a known pattern DEPLOYMENT_URL="https://docs-getdbt-${{ github.sha }}-dbt-labs.vercel.app" echo "::set-output name=deployment_url::${DEPLOYMENT_URL}" From 6baf51791d26c2bd23ca2a978acb165d02e73f09 Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Thu, 19 Sep 2024 12:47:42 +0100 Subject: [PATCH 03/38] test --- .github/workflows/preview-link.yml | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/.github/workflows/preview-link.yml b/.github/workflows/preview-link.yml index 9cb08a45bd0..a109a772f93 100644 --- a/.github/workflows/preview-link.yml +++ b/.github/workflows/preview-link.yml @@ -9,19 +9,13 @@ jobs: runs-on: ubuntu-latest steps: - - name: Wait for Vercel deployment - run: | - echo "Waiting for Vercel deployment to complete..." - sleep 120 # Adjust this based on your deployment time - - name: Checkout code uses: actions/checkout@v3 - - name: Get vercel deployment URL - id: vercel + - name: Wait for Vercel deployment run: | - DEPLOYMENT_URL="https://docs-getdbt-${{ github.sha }}-dbt-labs.vercel.app" - echo "::set-output name=deployment_url::${DEPLOYMENT_URL}" + echo "Waiting for Vercel deployment to complete..." + sleep 300 # Adjust this based on deployment speed - name: Get changed files id: files @@ -29,6 +23,15 @@ jobs: 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 deployment link + id: vercel + run: | + DEPLOYMENT_URL="https://docs-getdbt-${{ github.sha }}-dbt-labs.vercel.app" + CHANGED_FILES=${{ steps.files.outputs.changed_files }} + # Formatting links for each changed file + LINKS=$(echo "$CHANGED_FILES" | awk -v url="$DEPLOYMENT_URL" '{print url "/" $0}') + echo "::set-output name=links::${LINKS}" + - name: Post comment with deployment link uses: peter-evans/create-or-update-comment@v1 with: @@ -37,7 +40,5 @@ jobs: body: | šŸš€ Deployment available: ${{ steps.vercel.outputs.deployment_url }} Here are the direct links to the updated files: - - ${{ steps.files.outputs.changed_files }} - - You can review the changes directly in the deployed environment! + + ${{ steps.vercel.outputs.links }} From b6416c0d4c1388d7cd3d8cd0a6be7de0a568b09c Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Thu, 19 Sep 2024 12:56:33 +0100 Subject: [PATCH 04/38] test --- .github/workflows/preview-link.yml | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/.github/workflows/preview-link.yml b/.github/workflows/preview-link.yml index a109a772f93..fcd1c456241 100644 --- a/.github/workflows/preview-link.yml +++ b/.github/workflows/preview-link.yml @@ -15,7 +15,14 @@ jobs: - name: Wait for Vercel deployment run: | echo "Waiting for Vercel deployment to complete..." - sleep 300 # Adjust this based on deployment speed + sleep 500 # Adjust based on deployment time + + - name: Get Vercel deployment URL + id: vercel_url + run: | + # If the Vercel deployment URL is available via API, capture it here + DEPLOYMENT_URL="https://docs-getdbt-${{ github.sha }}-dbt-labs.vercel.app" + echo "::set-output name=deployment_url::${DEPLOYMENT_URL}" - name: Get changed files id: files @@ -23,22 +30,21 @@ jobs: 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 deployment link - id: vercel + - name: Generate file preview links + id: links run: | - DEPLOYMENT_URL="https://docs-getdbt-${{ github.sha }}-dbt-labs.vercel.app" - CHANGED_FILES=${{ steps.files.outputs.changed_files }} - # Formatting links for each changed file - LINKS=$(echo "$CHANGED_FILES" | awk -v url="$DEPLOYMENT_URL" '{print url "/" $0}') + DEPLOYMENT_URL="${{ steps.vercel_url.outputs.deployment_url }}" + CHANGED_FILES="${{ steps.files.outputs.changed_files }}" + LINKS=$(echo "$CHANGED_FILES" | awk -v url="$DEPLOYMENT_URL" '{print "- [" $0 "](" url "/" $0 ")"}') echo "::set-output name=links::${LINKS}" - name: Post comment with deployment link - uses: peter-evans/create-or-update-comment@v1 + uses: peter-evans/create-or-update-comment@v4.0.0 with: token: ${{ secrets.GITHUB_TOKEN }} issue-number: ${{ github.event.pull_request.number }} body: | - šŸš€ Deployment available: ${{ steps.vercel.outputs.deployment_url }} + šŸš€ Deployment available: ${{ steps.vercel_url.outputs.deployment_url }} Here are the direct links to the updated files: - ${{ steps.vercel.outputs.links }} + ${{ steps.links.outputs.links }} From 8b9be8cccb12257f2639d9fed1a5604b1d5f2867 Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Thu, 19 Sep 2024 13:10:22 +0100 Subject: [PATCH 05/38] test --- .github/workflows/preview-link.yml | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/.github/workflows/preview-link.yml b/.github/workflows/preview-link.yml index fcd1c456241..f5414a0fdc9 100644 --- a/.github/workflows/preview-link.yml +++ b/.github/workflows/preview-link.yml @@ -3,6 +3,17 @@ 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: @@ -10,12 +21,14 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Wait for Vercel deployment run: | echo "Waiting for Vercel deployment to complete..." - sleep 500 # Adjust based on deployment time + sleep 300 # Adjust based on deployment time - name: Get Vercel deployment URL id: vercel_url From 117894528ebd55e3ff544c418ddebe3e27b483f2 Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Thu, 19 Sep 2024 13:21:19 +0100 Subject: [PATCH 06/38] test --- .github/workflows/preview-link.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/preview-link.yml b/.github/workflows/preview-link.yml index f5414a0fdc9..03199457f67 100644 --- a/.github/workflows/preview-link.yml +++ b/.github/workflows/preview-link.yml @@ -47,8 +47,9 @@ jobs: id: links run: | DEPLOYMENT_URL="${{ steps.vercel_url.outputs.deployment_url }}" - CHANGED_FILES="${{ steps.files.outputs.changed_files }}" - LINKS=$(echo "$CHANGED_FILES" | awk -v url="$DEPLOYMENT_URL" '{print "- [" $0 "](" url "/" $0 ")"}') + 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 From 5e402e2f3b4094957bbeadf11075e29b3d0a5099 Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Thu, 19 Sep 2024 13:41:57 +0100 Subject: [PATCH 07/38] test --- .github/workflows/preview-link.yml | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/.github/workflows/preview-link.yml b/.github/workflows/preview-link.yml index 03199457f67..a367acc52ff 100644 --- a/.github/workflows/preview-link.yml +++ b/.github/workflows/preview-link.yml @@ -14,7 +14,6 @@ permissions: contents: read pull-requests: write - jobs: comment-deployment-link: runs-on: ubuntu-latest @@ -23,19 +22,25 @@ jobs: - name: Checkout code uses: actions/checkout@v4 with: - fetch-depth: 0 + fetch-depth: 0 - name: Wait for Vercel deployment run: | echo "Waiting for Vercel deployment to complete..." sleep 300 # Adjust based on deployment time - - name: Get Vercel deployment URL + - 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 run: | - # If the Vercel deployment URL is available via API, capture it here - DEPLOYMENT_URL="https://docs-getdbt-${{ github.sha }}-dbt-labs.vercel.app" - echo "::set-output name=deployment_url::${DEPLOYMENT_URL}" + 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 From c8634a37a6d57bb1bb6f9591f4b9a7e3b9f333cc Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Thu, 19 Sep 2024 13:50:58 +0100 Subject: [PATCH 08/38] test --- .github/workflows/preview-link.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/preview-link.yml b/.github/workflows/preview-link.yml index a367acc52ff..b0945bda492 100644 --- a/.github/workflows/preview-link.yml +++ b/.github/workflows/preview-link.yml @@ -37,6 +37,8 @@ jobs: - name: Get Vercel deployment URL from GitHub Check id: vercel_url + env: + VALE_GITHUB_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') From c6a5cb9aa470f886181dbd5d3ca4fa18a4d5ad19 Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Thu, 19 Sep 2024 14:02:49 +0100 Subject: [PATCH 09/38] test --- .github/workflows/preview-link.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/preview-link.yml b/.github/workflows/preview-link.yml index b0945bda492..84905f41861 100644 --- a/.github/workflows/preview-link.yml +++ b/.github/workflows/preview-link.yml @@ -38,7 +38,7 @@ jobs: - name: Get Vercel deployment URL from GitHub Check id: vercel_url env: - VALE_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + 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') From 4ebcda47d2a130258275917b01921d48bddb967b Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Thu, 19 Sep 2024 16:11:42 +0100 Subject: [PATCH 10/38] update yaml --- .github/workflows/preview-link.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/preview-link.yml b/.github/workflows/preview-link.yml index 84905f41861..faa339aa214 100644 --- a/.github/workflows/preview-link.yml +++ b/.github/workflows/preview-link.yml @@ -38,10 +38,14 @@ jobs: - name: Get Vercel deployment URL from GitHub Check id: vercel_url env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} # GitHub token for authentication 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') + if [ -z "$VERCEL_URL" ]; then + echo "Vercel URL not found, defaulting to GitHub URL." + VERCEL_URL="https://github.com" + fi echo "::set-output name=deployment_url::${VERCEL_URL}" - name: Get changed files @@ -55,7 +59,7 @@ jobs: 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 + # Remove 'website/docs/docs/' and '.md' extension from the filenames 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}" From 2a2df9a98564fe6ce52c629667d8fe55a69f6cef Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Fri, 20 Sep 2024 16:29:46 +0100 Subject: [PATCH 11/38] add --- .github/workflows/preview-link.yml | 70 +++++++++++++++++++----------- 1 file changed, 45 insertions(+), 25 deletions(-) diff --git a/.github/workflows/preview-link.yml b/.github/workflows/preview-link.yml index faa339aa214..de21f3aab7e 100644 --- a/.github/workflows/preview-link.yml +++ b/.github/workflows/preview-link.yml @@ -24,52 +24,72 @@ jobs: 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 + sudo apt-get update + sudo apt-get install -y jq + sudo apt-get install -y gh - - name: Get Vercel deployment URL from GitHub Check - id: vercel_url + - name: Wait for Vercel deployment + id: vercel_deploy env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} # GitHub token for authentication + 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') - if [ -z "$VERCEL_URL" ]; then - echo "Vercel URL not found, defaulting to GitHub URL." - VERCEL_URL="https://github.com" + 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 - 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}" + echo "changed_files=$CHANGED_FILES" >> $GITHUB_OUTPUT - name: Generate file preview links id: links run: | - DEPLOYMENT_URL="${{ steps.vercel_url.outputs.deployment_url }}" - CHANGED_FILES="${{ steps.files.outputs.changed_files }}" - # Remove 'website/docs/docs/' and '.md' extension from the filenames + 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 "::set-output name=links::${LINKS}" + echo "links=$LINKS" >> $GITHUB_OUTPUT - name: Post comment with deployment link - uses: peter-evans/create-or-update-comment@v4.0.0 + 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_url.outputs.deployment_url }} + šŸš€ Deployment available: ${{ steps.vercel_deploy.outputs.deployment_url }} Here are the direct links to the updated files: - + ${{ steps.links.outputs.links }} From b7fc7e2edd7ac3ac730e6083c27912d9d7e01b88 Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Fri, 20 Sep 2024 16:56:34 +0100 Subject: [PATCH 12/38] add --- .github/workflows/preview-link.yml | 79 +++++++++++++++++------------- 1 file changed, 45 insertions(+), 34 deletions(-) diff --git a/.github/workflows/preview-link.yml b/.github/workflows/preview-link.yml index de21f3aab7e..dcc35bbbd3d 100644 --- a/.github/workflows/preview-link.yml +++ b/.github/workflows/preview-link.yml @@ -24,48 +24,52 @@ jobs: with: fetch-depth: 0 - - name: Install GitHub CLI and jq + - name: Install necessary tools run: | sudo apt-get update - sudo apt-get install -y jq - sudo apt-get install -y gh + sudo apt-get install -y jq curl - - name: Wait for Vercel deployment - id: vercel_deploy - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Generate Vercel deployment URL + id: vercel_url run: | - CHECK_RUN_ID="" - ATTEMPTS=0 + # 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 (optional) + 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=30 # Adjust as needed SLEEP_TIME=10 # Adjust as needed + ATTEMPTS=0 + 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 + 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 "Vercel check not found. Waiting..." + echo "Deployment not yet accessible (status code: $STATUS_CODE). Waiting..." + sleep $SLEEP_TIME + ATTEMPTS=$((ATTEMPTS + 1)) fi - ATTEMPTS=$((ATTEMPTS + 1)) - sleep $SLEEP_TIME done + if [ $ATTEMPTS -eq $MAX_ATTEMPTS ]; then - echo "Vercel deployment did not complete within expected time." + echo "Deployment did not become accessible within the expected time." exit 1 fi @@ -78,9 +82,16 @@ jobs: - name: Generate file preview links id: links run: | - DEPLOYMENT_URL="${{ steps.vercel_deploy.outputs.deployment_url }}" + DEPLOYMENT_URL="${{ steps.vercel_url.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 ")"}') + + if [ -z "$CHANGED_FILES" ]; then + echo "No changed files found in the specified directories." + LINKS="- No documentation files were changed." + else + LINKS=$(echo "$CHANGED_FILES" | sed 's#website/docs/docs/##; s/.md$//' | awk -v url="$DEPLOYMENT_URL" '{print "- [" $0 "](" url "/docs/" $0 ")"}') + fi + echo "links=$LINKS" >> $GITHUB_OUTPUT - name: Post comment with deployment link @@ -89,7 +100,7 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} issue-number: ${{ github.event.pull_request.number }} body: | - šŸš€ Deployment available: ${{ steps.vercel_deploy.outputs.deployment_url }} + šŸš€ **Deployment available:** ${{ steps.vercel_url.outputs.deployment_url }} Here are the direct links to the updated files: ${{ steps.links.outputs.links }} From b050146a2014793baf6e1fd863fae9993ee05832 Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Fri, 20 Sep 2024 17:07:03 +0100 Subject: [PATCH 13/38] add --- .github/workflows/preview-link.yml | 42 +++++++++++++++++------- website/docs/docs/build/saved-queries.md | 2 ++ 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/.github/workflows/preview-link.yml b/.github/workflows/preview-link.yml index dcc35bbbd3d..ef49f24e3ea 100644 --- a/.github/workflows/preview-link.yml +++ b/.github/workflows/preview-link.yml @@ -46,14 +46,14 @@ jobs: echo "deployment_url=$DEPLOYMENT_URL" >> $GITHUB_OUTPUT - - name: Wait for deployment to be accessible (optional) + - 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=30 # Adjust as needed - SLEEP_TIME=10 # Adjust as needed + MAX_ATTEMPTS=60 # Adjust as needed (e.g., wait up to 10 minutes) + SLEEP_TIME=10 # Check every 10 seconds ATTEMPTS=0 while [ $ATTEMPTS -lt $MAX_ATTEMPTS ]; do @@ -76,8 +76,20 @@ jobs: - 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 + # Get the list of changed files in the specified directories + 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) + echo "Changed files:" + echo "$CHANGED_FILES" + + # Check if any files were changed + if [ -z "$CHANGED_FILES" ]; then + echo "No documentation files were changed." + echo "changed_files=" >> $GITHUB_OUTPUT + else + # Convert line-separated files to space-separated for easier handling + CHANGED_FILES="$(echo "$CHANGED_FILES" | tr '\n' ' ')" + echo "changed_files=$CHANGED_FILES" >> $GITHUB_OUTPUT + fi - name: Generate file preview links id: links @@ -86,13 +98,23 @@ jobs: CHANGED_FILES="${{ steps.files.outputs.changed_files }}" if [ -z "$CHANGED_FILES" ]; then - echo "No changed files found in the specified directories." + echo "No documentation files were changed." LINKS="- No documentation files were changed." else - LINKS=$(echo "$CHANGED_FILES" | sed 's#website/docs/docs/##; s/.md$//' | awk -v url="$DEPLOYMENT_URL" '{print "- [" $0 "](" url "/docs/" $0 ")"}') + LINKS="" + for FILE in $CHANGED_FILES; do + # Remove 'website/docs/' prefix and '.md' extension + FILE_PATH="${FILE#website/docs/}" + FILE_PATH="${FILE_PATH%.md}" + # Replace spaces and special characters with hyphens in URL path + URL_PATH=$(echo "$FILE_PATH" | sed 's/ /-/g; s/[^a-zA-Z0-9\-\/]//g' | tr '[:upper:]' '[:lower:]') + FULL_URL="$DEPLOYMENT_URL/$URL_PATH" + LINKS="$LINKS\n- [$FULL_URL]($FULL_URL)" + done fi - echo "links=$LINKS" >> $GITHUB_OUTPUT + # Output the links + echo -e "links=$LINKS" >> $GITHUB_OUTPUT - name: Post comment with deployment link uses: peter-evans/create-or-update-comment@v4 @@ -100,7 +122,5 @@ jobs: 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: - + šŸš€ Deployment available! Here are the direct links to the updated files: ${{ steps.links.outputs.links }} diff --git a/website/docs/docs/build/saved-queries.md b/website/docs/docs/build/saved-queries.md index e9beffca15f..518f9008b7a 100644 --- a/website/docs/docs/build/saved-queries.md +++ b/website/docs/docs/build/saved-queries.md @@ -6,6 +6,8 @@ sidebar_label: "Saved queries" tags: [Metrics, Semantic Layer] --- +# Test for preview link change + Saved queries are a way to save commonly used queries in MetricFlow. You can group metrics, dimensions, and filters that are logically related into a saved query. Saved queries are nodes and visible in the dbt . Saved queries serve as the foundational building block, allowing you to [configure exports](#configure-exports) in your saved query configuration. Exports takes this functionality a step further by enabling you to [schedule and write saved queries](/docs/use-dbt-semantic-layer/exports) directly within your data platform using [dbt Cloud's job scheduler](/docs/deploy/job-scheduler). From 94d82f4d305e7feba68d5dfb8eccdcfadf3c66bd Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Fri, 20 Sep 2024 17:11:04 +0100 Subject: [PATCH 14/38] add --- .github/workflows/preview-link.yml | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/.github/workflows/preview-link.yml b/.github/workflows/preview-link.yml index ef49f24e3ea..4781a576547 100644 --- a/.github/workflows/preview-link.yml +++ b/.github/workflows/preview-link.yml @@ -98,23 +98,14 @@ jobs: CHANGED_FILES="${{ steps.files.outputs.changed_files }}" if [ -z "$CHANGED_FILES" ]; then - echo "No documentation files were changed." + echo "No changed files found in the specified directories." LINKS="- No documentation files were changed." else - LINKS="" - for FILE in $CHANGED_FILES; do - # Remove 'website/docs/' prefix and '.md' extension - FILE_PATH="${FILE#website/docs/}" - FILE_PATH="${FILE_PATH%.md}" - # Replace spaces and special characters with hyphens in URL path - URL_PATH=$(echo "$FILE_PATH" | sed 's/ /-/g; s/[^a-zA-Z0-9\-\/]//g' | tr '[:upper:]' '[:lower:]') - FULL_URL="$DEPLOYMENT_URL/$URL_PATH" - LINKS="$LINKS\n- [$FULL_URL]($FULL_URL)" - done + LINKS=$(echo "$CHANGED_FILES" | sed 's#website/docs/docs/##; s/.md$//' | awk -v url="$DEPLOYMENT_URL" '{print "- [" $0 "](" url "/docs/" $0 ")"}') fi - # Output the links - echo -e "links=$LINKS" >> $GITHUB_OUTPUT + echo "links=$LINKS" >> $GITHUB_OUTPUT + - name: Post comment with deployment link uses: peter-evans/create-or-update-comment@v4 From bf9a57a4434028e163e47963ba0f11f12be606b9 Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Fri, 20 Sep 2024 17:12:06 +0100 Subject: [PATCH 15/38] add --- website/docs/docs/build/saved-queries.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/website/docs/docs/build/saved-queries.md b/website/docs/docs/build/saved-queries.md index 518f9008b7a..e9beffca15f 100644 --- a/website/docs/docs/build/saved-queries.md +++ b/website/docs/docs/build/saved-queries.md @@ -6,8 +6,6 @@ sidebar_label: "Saved queries" tags: [Metrics, Semantic Layer] --- -# Test for preview link change - Saved queries are a way to save commonly used queries in MetricFlow. You can group metrics, dimensions, and filters that are logically related into a saved query. Saved queries are nodes and visible in the dbt . Saved queries serve as the foundational building block, allowing you to [configure exports](#configure-exports) in your saved query configuration. Exports takes this functionality a step further by enabling you to [schedule and write saved queries](/docs/use-dbt-semantic-layer/exports) directly within your data platform using [dbt Cloud's job scheduler](/docs/deploy/job-scheduler). From 99f41768693cf2eddfc573ef7ea21882f9f7ec7a Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Fri, 20 Sep 2024 17:28:45 +0100 Subject: [PATCH 16/38] add --- .github/workflows/preview-link.yml | 31 +++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/.github/workflows/preview-link.yml b/.github/workflows/preview-link.yml index 4781a576547..714464cf9ee 100644 --- a/.github/workflows/preview-link.yml +++ b/.github/workflows/preview-link.yml @@ -101,17 +101,34 @@ jobs: echo "No changed files found in the specified directories." LINKS="- No documentation files were changed." else - LINKS=$(echo "$CHANGED_FILES" | sed 's#website/docs/docs/##; s/.md$//' | awk -v url="$DEPLOYMENT_URL" '{print "- [" $0 "](" url "/docs/" $0 ")"}') + LINKS="" + for FILE in $CHANGED_FILES; do + # Remove 'website/docs/' prefix and '.md' extension + FILE_PATH="${FILE#website/docs/}" + FILE_PATH="${FILE_PATH%.md}" + # Replace spaces and special characters with hyphens in URL path + URL_PATH=$(echo "$FILE_PATH" | sed 's/ /-/g; s/[^a-zA-Z0-9\-_\/]//g' | tr '[:upper:]' '[:lower:]') + FULL_URL="$DEPLOYMENT_URL/$URL_PATH" + LINKS="$LINKS\n- [$FULL_URL]($FULL_URL)" + done fi - echo "links=$LINKS" >> $GITHUB_OUTPUT - + # Output the links + echo -e "links=$LINKS" >> $GITHUB_OUTPUT - name: Post comment with deployment link - uses: peter-evans/create-or-update-comment@v4 + uses: actions/github-script@v6 with: - token: ${{ secrets.GITHUB_TOKEN }} - issue-number: ${{ github.event.pull_request.number }} - body: | + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const { github, context } = require('@actions/github'); + const issue_number = context.payload.pull_request.number; + const body = ` šŸš€ Deployment available! Here are the direct links to the updated files: ${{ steps.links.outputs.links }} + `; + await github.rest.issues.createComment({ + ...context.repo, + issue_number, + body: body + }); From d59c34b6e11c39b6b0d5f0ef379fae7c90e4e601 Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Fri, 20 Sep 2024 17:31:10 +0100 Subject: [PATCH 17/38] add --- .github/workflows/preview-link.yml | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/.github/workflows/preview-link.yml b/.github/workflows/preview-link.yml index 714464cf9ee..4353f20f080 100644 --- a/.github/workflows/preview-link.yml +++ b/.github/workflows/preview-link.yml @@ -101,20 +101,10 @@ jobs: echo "No changed files found in the specified directories." LINKS="- No documentation files were changed." else - LINKS="" - for FILE in $CHANGED_FILES; do - # Remove 'website/docs/' prefix and '.md' extension - FILE_PATH="${FILE#website/docs/}" - FILE_PATH="${FILE_PATH%.md}" - # Replace spaces and special characters with hyphens in URL path - URL_PATH=$(echo "$FILE_PATH" | sed 's/ /-/g; s/[^a-zA-Z0-9\-_\/]//g' | tr '[:upper:]' '[:lower:]') - FULL_URL="$DEPLOYMENT_URL/$URL_PATH" - LINKS="$LINKS\n- [$FULL_URL]($FULL_URL)" - done + LINKS=$(echo "$CHANGED_FILES" | sed 's#website/docs/docs/##; s/.md$//' | awk -v url="$DEPLOYMENT_URL" '{print "- [" $0 "](" url "/docs/" $0 ")"}') fi - # Output the links - echo -e "links=$LINKS" >> $GITHUB_OUTPUT + echo "links=$LINKS" >> $GITHUB_OUTPUT - name: Post comment with deployment link uses: actions/github-script@v6 From 0320862d909272441eee5c1d5acf84d1259a0c75 Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Fri, 20 Sep 2024 17:33:15 +0100 Subject: [PATCH 18/38] add --- .github/workflows/preview-link.yml | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/.github/workflows/preview-link.yml b/.github/workflows/preview-link.yml index 4353f20f080..733c243ec85 100644 --- a/.github/workflows/preview-link.yml +++ b/.github/workflows/preview-link.yml @@ -107,18 +107,11 @@ jobs: echo "links=$LINKS" >> $GITHUB_OUTPUT - name: Post comment with deployment link - uses: actions/github-script@v6 + uses: peter-evans/create-or-update-comment@v4 with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - const { github, context } = require('@actions/github'); - const issue_number = context.payload.pull_request.number; - const body = ` + token: ${{ secrets.GITHUB_TOKEN }} + issue-number: ${{ github.event.pull_request.number }} + body: | + šŸš€ Deployment available! Here are the direct links to the updated files: ${{ steps.links.outputs.links }} - `; - await github.rest.issues.createComment({ - ...context.repo, - issue_number, - body: body - }); From 7301eab23eae0cace82c8d8d1b7b3dc02adf118c Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Tue, 24 Sep 2024 14:25:42 +0100 Subject: [PATCH 19/38] add --- .github/workflows/preview-link.yml | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/.github/workflows/preview-link.yml b/.github/workflows/preview-link.yml index 733c243ec85..317791f3b95 100644 --- a/.github/workflows/preview-link.yml +++ b/.github/workflows/preview-link.yml @@ -101,10 +101,25 @@ jobs: echo "No changed files found in the specified directories." LINKS="- No documentation files were changed." else - LINKS=$(echo "$CHANGED_FILES" | sed 's#website/docs/docs/##; s/.md$//' | awk -v url="$DEPLOYMENT_URL" '{print "- [" $0 "](" url "/docs/" $0 ")"}') + 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/}" + # Keep the .md extension as per your desired output + # FILE_PATH="${FILE_PATH%.md}" + + # Construct the full URL + FULL_URL="$DEPLOYMENT_URL/$FILE_PATH" + LINKS="$LINKS\n- $FULL_URL" + done fi - echo "links=$LINKS" >> $GITHUB_OUTPUT + # Properly set the multi-line output + echo "links<> $GITHUB_OUTPUT + echo -e "$LINKS" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT - name: Post comment with deployment link uses: peter-evans/create-or-update-comment@v4 From 88bb8e5dc6c45349495b27dba8347efc88cedc65 Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Tue, 24 Sep 2024 14:33:29 +0100 Subject: [PATCH 20/38] add --- .github/workflows/preview-link.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/preview-link.yml b/.github/workflows/preview-link.yml index 317791f3b95..84f7d187ac7 100644 --- a/.github/workflows/preview-link.yml +++ b/.github/workflows/preview-link.yml @@ -107,8 +107,8 @@ jobs: for FILE in $CHANGED_FILES; do # Remove 'website/docs/' prefix FILE_PATH="${FILE#website/docs/}" - # Keep the .md extension as per your desired output - # FILE_PATH="${FILE_PATH%.md}" + # Remove the .md extension as per your desired output + FILE_PATH="${FILE_PATH%.md}" # Construct the full URL FULL_URL="$DEPLOYMENT_URL/$FILE_PATH" From da41198e4009fd93bdc263cfe9d2dfa23d9c53c9 Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Tue, 24 Sep 2024 14:59:03 +0100 Subject: [PATCH 21/38] add --- .github/workflows/preview-link.yml | 72 +++++++++++++++++++++--------- 1 file changed, 51 insertions(+), 21 deletions(-) diff --git a/.github/workflows/preview-link.yml b/.github/workflows/preview-link.yml index 84f7d187ac7..32c6445c05e 100644 --- a/.github/workflows/preview-link.yml +++ b/.github/workflows/preview-link.yml @@ -13,6 +13,7 @@ on: permissions: contents: read pull-requests: write + checks: read # Added permission to read checks jobs: comment-deployment-link: @@ -46,30 +47,54 @@ jobs: echo "deployment_url=$DEPLOYMENT_URL" >> $GITHUB_OUTPUT - - name: Wait for deployment to be accessible - id: wait_for_deployment + - name: Wait for Vercel deployment check to complete + id: wait_for_vercel + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - DEPLOYMENT_URL="${{ steps.vercel_url.outputs.deployment_url }}" - echo "Waiting for deployment at $DEPLOYMENT_URL to become accessible..." + # Set variables + COMMIT_SHA="${{ github.event.pull_request.head.sha }}" + REPO="${{ github.repository }}" + + echo "Waiting for Vercel deployment check to complete..." - MAX_ATTEMPTS=60 # Adjust as needed (e.g., wait up to 10 minutes) + MAX_ATTEMPTS=60 # Adjust as needed 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 + # Get the check runs for the commit + CHECK_RUNS=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \ + "https://api.github.com/repos/$REPO/commits/$COMMIT_SHA/check-runs") + + # Filter for the Vercel check run + VERCEL_CHECK=$(echo "$CHECK_RUNS" | jq -r '.check_runs[] | select(.name == "Vercel")') + + if [ -n "$VERCEL_CHECK" ]; then + STATUS=$(echo "$VERCEL_CHECK" | jq -r '.status') + CONCLUSION=$(echo "$VERCEL_CHECK" | jq -r '.conclusion') + + echo "Vercel check status: $STATUS" + + if [ "$STATUS" == "completed" ]; then + if [ "$CONCLUSION" == "success" ]; then + echo "Vercel deployment check completed successfully." + break + else + echo "Vercel deployment check failed." + exit 1 + fi + fi else - echo "Deployment not yet accessible (status code: $STATUS_CODE). Waiting..." - sleep $SLEEP_TIME - ATTEMPTS=$((ATTEMPTS + 1)) + echo "Vercel check not found. Waiting..." fi + + sleep $SLEEP_TIME + ATTEMPTS=$((ATTEMPTS + 1)) done if [ $ATTEMPTS -eq $MAX_ATTEMPTS ]; then - echo "Deployment did not become accessible within the expected time." + echo "Vercel deployment check did not complete within expected time." exit 1 fi @@ -107,7 +132,7 @@ jobs: for FILE in $CHANGED_FILES; do # Remove 'website/docs/' prefix FILE_PATH="${FILE#website/docs/}" - # Remove the .md extension as per your desired output + # Remove the .md extension FILE_PATH="${FILE_PATH%.md}" # Construct the full URL @@ -122,11 +147,16 @@ jobs: echo "EOF" >> $GITHUB_OUTPUT - name: Post comment with deployment link - uses: peter-evans/create-or-update-comment@v4 + uses: actions/github-script@v6 with: - token: ${{ secrets.GITHUB_TOKEN }} - issue-number: ${{ github.event.pull_request.number }} - body: | - - šŸš€ Deployment available! Here are the direct links to the updated files: - ${{ steps.links.outputs.links }} + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const { github, context } = require('@actions/github'); + const issue_number = context.payload.pull_request.number; + const links = `\n${{ steps.links.outputs.links }}`; + const body = `\nšŸš€ Deployment available! Here are the direct links to the updated files:${links}`; + await github.rest.issues.createComment({ + ...context.repo, + issue_number, + body: body + }); From 906cb2b78a5f7297528cc6bd89b1d4eb928c3796 Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Tue, 24 Sep 2024 15:04:33 +0100 Subject: [PATCH 22/38] add --- .github/workflows/preview-link.yml | 72 +++++++++--------------------- 1 file changed, 21 insertions(+), 51 deletions(-) diff --git a/.github/workflows/preview-link.yml b/.github/workflows/preview-link.yml index 32c6445c05e..84f7d187ac7 100644 --- a/.github/workflows/preview-link.yml +++ b/.github/workflows/preview-link.yml @@ -13,7 +13,6 @@ on: permissions: contents: read pull-requests: write - checks: read # Added permission to read checks jobs: comment-deployment-link: @@ -47,54 +46,30 @@ jobs: echo "deployment_url=$DEPLOYMENT_URL" >> $GITHUB_OUTPUT - - name: Wait for Vercel deployment check to complete - id: wait_for_vercel - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Wait for deployment to be accessible + id: wait_for_deployment run: | - # Set variables - COMMIT_SHA="${{ github.event.pull_request.head.sha }}" - REPO="${{ github.repository }}" - - echo "Waiting for Vercel deployment check to complete..." + DEPLOYMENT_URL="${{ steps.vercel_url.outputs.deployment_url }}" + echo "Waiting for deployment at $DEPLOYMENT_URL to become accessible..." - MAX_ATTEMPTS=60 # Adjust as needed + MAX_ATTEMPTS=60 # Adjust as needed (e.g., wait up to 10 minutes) SLEEP_TIME=10 # Check every 10 seconds ATTEMPTS=0 while [ $ATTEMPTS -lt $MAX_ATTEMPTS ]; do - # Get the check runs for the commit - CHECK_RUNS=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \ - "https://api.github.com/repos/$REPO/commits/$COMMIT_SHA/check-runs") - - # Filter for the Vercel check run - VERCEL_CHECK=$(echo "$CHECK_RUNS" | jq -r '.check_runs[] | select(.name == "Vercel")') - - if [ -n "$VERCEL_CHECK" ]; then - STATUS=$(echo "$VERCEL_CHECK" | jq -r '.status') - CONCLUSION=$(echo "$VERCEL_CHECK" | jq -r '.conclusion') - - echo "Vercel check status: $STATUS" - - if [ "$STATUS" == "completed" ]; then - if [ "$CONCLUSION" == "success" ]; then - echo "Vercel deployment check completed successfully." - break - else - echo "Vercel deployment check failed." - exit 1 - fi - fi + 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 "Vercel check not found. Waiting..." + echo "Deployment not yet accessible (status code: $STATUS_CODE). Waiting..." + sleep $SLEEP_TIME + ATTEMPTS=$((ATTEMPTS + 1)) fi - - sleep $SLEEP_TIME - ATTEMPTS=$((ATTEMPTS + 1)) done if [ $ATTEMPTS -eq $MAX_ATTEMPTS ]; then - echo "Vercel deployment check did not complete within expected time." + echo "Deployment did not become accessible within the expected time." exit 1 fi @@ -132,7 +107,7 @@ jobs: for FILE in $CHANGED_FILES; do # Remove 'website/docs/' prefix FILE_PATH="${FILE#website/docs/}" - # Remove the .md extension + # Remove the .md extension as per your desired output FILE_PATH="${FILE_PATH%.md}" # Construct the full URL @@ -147,16 +122,11 @@ jobs: echo "EOF" >> $GITHUB_OUTPUT - name: Post comment with deployment link - uses: actions/github-script@v6 + uses: peter-evans/create-or-update-comment@v4 with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - const { github, context } = require('@actions/github'); - const issue_number = context.payload.pull_request.number; - const links = `\n${{ steps.links.outputs.links }}`; - const body = `\nšŸš€ Deployment available! Here are the direct links to the updated files:${links}`; - await github.rest.issues.createComment({ - ...context.repo, - issue_number, - body: body - }); + token: ${{ secrets.GITHUB_TOKEN }} + issue-number: ${{ github.event.pull_request.number }} + body: | + + šŸš€ Deployment available! Here are the direct links to the updated files: + ${{ steps.links.outputs.links }} From 9eb8d033bdab7eb58486a2a5da8e6290a42ae0c6 Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Wed, 25 Sep 2024 15:10:15 +0100 Subject: [PATCH 23/38] add --- .github/workflows/preview-link.yml | 59 +++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 9 deletions(-) diff --git a/.github/workflows/preview-link.yml b/.github/workflows/preview-link.yml index 84f7d187ac7..2c33a41c169 100644 --- a/.github/workflows/preview-link.yml +++ b/.github/workflows/preview-link.yml @@ -13,6 +13,7 @@ on: permissions: contents: read pull-requests: write + checks: write # Added permission for creating check runs jobs: comment-deployment-link: @@ -112,7 +113,7 @@ jobs: # Construct the full URL FULL_URL="$DEPLOYMENT_URL/$FILE_PATH" - LINKS="$LINKS\n- $FULL_URL" + LINKS="$LINKS\n- [$FILE_PATH]($FULL_URL)" done fi @@ -121,12 +122,52 @@ jobs: echo -e "$LINKS" >> $GITHUB_OUTPUT echo "EOF" >> $GITHUB_OUTPUT - - name: Post comment with deployment link - uses: peter-evans/create-or-update-comment@v4 + - name: Post deployment links in a check run + uses: actions/github-script@v6 with: - token: ${{ secrets.GITHUB_TOKEN }} - issue-number: ${{ github.event.pull_request.number }} - body: | - - šŸš€ Deployment available! Here are the direct links to the updated files: - ${{ steps.links.outputs.links }} + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const deploymentUrl = `šŸš€ Deployment available at: [${{ steps.vercel_url.outputs.deployment_url }}](${{ steps.vercel_url.outputs.deployment_url }})`; + + const links = `Here are the direct links to the updated files:\n${{ steps.links.outputs.links }}`; + + const summary = `${deploymentUrl}\n\n${links}`; + + // Check if a check run already exists + const checkRuns = await github.checks.listForRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: context.payload.pull_request.head.sha, + }); + + const existingCheckRun = checkRuns.data.check_runs.find( + (run) => run.name === 'Vercel Deployment Preview' + ); + + if (existingCheckRun) { + // Update the existing check run + await github.checks.update({ + owner: context.repo.owner, + repo: context.repo.repo, + check_run_id: existingCheckRun.id, + output: { + title: 'Vercel Deployment Preview', + summary: summary, + }, + conclusion: 'success', + }); + } else { + // Create a new check run + await github.checks.create({ + owner: context.repo.owner, + repo: context.repo.repo, + name: 'Vercel Deployment Preview', + head_sha: context.payload.pull_request.head.sha, + status: 'completed', + conclusion: 'success', + output: { + title: 'Vercel Deployment Preview', + summary: summary, + }, + }); + } From e073651171e638e20e4776466b007fcb1fce19b9 Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Wed, 25 Sep 2024 15:15:28 +0100 Subject: [PATCH 24/38] add --- .github/workflows/preview-link.yml | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/.github/workflows/preview-link.yml b/.github/workflows/preview-link.yml index 2c33a41c169..f0123233b01 100644 --- a/.github/workflows/preview-link.yml +++ b/.github/workflows/preview-link.yml @@ -128,25 +128,25 @@ jobs: github-token: ${{ secrets.GITHUB_TOKEN }} script: | const deploymentUrl = `šŸš€ Deployment available at: [${{ steps.vercel_url.outputs.deployment_url }}](${{ steps.vercel_url.outputs.deployment_url }})`; - + const links = `Here are the direct links to the updated files:\n${{ steps.links.outputs.links }}`; - + const summary = `${deploymentUrl}\n\n${links}`; - - // Check if a check run already exists - const checkRuns = await github.checks.listForRef({ + + // Access octokit.rest instead of github + const checkRuns = await octokit.rest.checks.listForRef({ owner: context.repo.owner, repo: context.repo.repo, ref: context.payload.pull_request.head.sha, }); - + const existingCheckRun = checkRuns.data.check_runs.find( (run) => run.name === 'Vercel Deployment Preview' ); - + if (existingCheckRun) { // Update the existing check run - await github.checks.update({ + await octokit.rest.checks.update({ owner: context.repo.owner, repo: context.repo.repo, check_run_id: existingCheckRun.id, @@ -158,7 +158,7 @@ jobs: }); } else { // Create a new check run - await github.checks.create({ + await octokit.rest.checks.create({ owner: context.repo.owner, repo: context.repo.repo, name: 'Vercel Deployment Preview', @@ -171,3 +171,4 @@ jobs: }, }); } + \ No newline at end of file From 7d62b078d781858599ed0150f272141306b717f1 Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Wed, 25 Sep 2024 15:47:07 +0100 Subject: [PATCH 25/38] add --- .github/workflows/preview-link.yml | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/.github/workflows/preview-link.yml b/.github/workflows/preview-link.yml index f0123233b01..1fc877fa8e1 100644 --- a/.github/workflows/preview-link.yml +++ b/.github/workflows/preview-link.yml @@ -13,7 +13,7 @@ on: permissions: contents: read pull-requests: write - checks: write # Added permission for creating check runs + checks: write # Ensure this permission is set jobs: comment-deployment-link: @@ -128,25 +128,25 @@ jobs: github-token: ${{ secrets.GITHUB_TOKEN }} script: | const deploymentUrl = `šŸš€ Deployment available at: [${{ steps.vercel_url.outputs.deployment_url }}](${{ steps.vercel_url.outputs.deployment_url }})`; - + const links = `Here are the direct links to the updated files:\n${{ steps.links.outputs.links }}`; - + const summary = `${deploymentUrl}\n\n${links}`; - - // Access octokit.rest instead of github - const checkRuns = await octokit.rest.checks.listForRef({ + + // Access github.rest instead of octokit + const checkRuns = await github.rest.checks.listForRef({ owner: context.repo.owner, repo: context.repo.repo, ref: context.payload.pull_request.head.sha, }); - + const existingCheckRun = checkRuns.data.check_runs.find( (run) => run.name === 'Vercel Deployment Preview' ); - + if (existingCheckRun) { // Update the existing check run - await octokit.rest.checks.update({ + await github.rest.checks.update({ owner: context.repo.owner, repo: context.repo.repo, check_run_id: existingCheckRun.id, @@ -158,7 +158,7 @@ jobs: }); } else { // Create a new check run - await octokit.rest.checks.create({ + await github.rest.checks.create({ owner: context.repo.owner, repo: context.repo.repo, name: 'Vercel Deployment Preview', @@ -171,4 +171,3 @@ jobs: }, }); } - \ No newline at end of file From 6a9e9bbeb3306ea107314218ac63b43ac12b238c Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Wed, 25 Sep 2024 16:03:28 +0100 Subject: [PATCH 26/38] add --- .github/workflows/preview-link.yml | 80 +++++++++--------------------- 1 file changed, 24 insertions(+), 56 deletions(-) diff --git a/.github/workflows/preview-link.yml b/.github/workflows/preview-link.yml index 1fc877fa8e1..7102fa35da7 100644 --- a/.github/workflows/preview-link.yml +++ b/.github/workflows/preview-link.yml @@ -11,12 +11,11 @@ on: - 'website/docs/reference/**' permissions: - contents: read + contents: write pull-requests: write - checks: write # Ensure this permission is set jobs: - comment-deployment-link: + update-pr-description: runs-on: ubuntu-latest steps: @@ -53,7 +52,7 @@ jobs: DEPLOYMENT_URL="${{ steps.vercel_url.outputs.deployment_url }}" echo "Waiting for deployment at $DEPLOYMENT_URL to become accessible..." - MAX_ATTEMPTS=60 # Adjust as needed (e.g., wait up to 10 minutes) + MAX_ATTEMPTS=60 # Wait up to 10 minutes SLEEP_TIME=10 # Check every 10 seconds ATTEMPTS=0 @@ -104,17 +103,18 @@ jobs: else LINKS="" # Convert CHANGED_FILES back to newline-separated for processing - CHANGED_FILES=$(echo "$CHANGED_FILES" | tr ' ' '\n') - for FILE in $CHANGED_FILES; do + echo "$CHANGED_FILES" | tr ' ' '\n' > files.txt + while IFS= read -r FILE; do # Remove 'website/docs/' prefix FILE_PATH="${FILE#website/docs/}" - # Remove the .md extension as per your desired output + # Remove the .md extension FILE_PATH="${FILE_PATH%.md}" # Construct the full URL FULL_URL="$DEPLOYMENT_URL/$FILE_PATH" LINKS="$LINKS\n- [$FILE_PATH]($FULL_URL)" - done + done < files.txt + rm files.txt fi # Properly set the multi-line output @@ -122,52 +122,20 @@ jobs: echo -e "$LINKS" >> $GITHUB_OUTPUT echo "EOF" >> $GITHUB_OUTPUT - - name: Post deployment links in a check run - uses: actions/github-script@v6 + - name: Update PR description with deployment links + uses: peter-evans/pull-request-description@v2 with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - const deploymentUrl = `šŸš€ Deployment available at: [${{ steps.vercel_url.outputs.deployment_url }}](${{ steps.vercel_url.outputs.deployment_url }})`; - - const links = `Here are the direct links to the updated files:\n${{ steps.links.outputs.links }}`; - - const summary = `${deploymentUrl}\n\n${links}`; - - // Access github.rest instead of octokit - const checkRuns = await github.rest.checks.listForRef({ - owner: context.repo.owner, - repo: context.repo.repo, - ref: context.payload.pull_request.head.sha, - }); - - const existingCheckRun = checkRuns.data.check_runs.find( - (run) => run.name === 'Vercel Deployment Preview' - ); - - if (existingCheckRun) { - // Update the existing check run - await github.rest.checks.update({ - owner: context.repo.owner, - repo: context.repo.repo, - check_run_id: existingCheckRun.id, - output: { - title: 'Vercel Deployment Preview', - summary: summary, - }, - conclusion: 'success', - }); - } else { - // Create a new check run - await github.rest.checks.create({ - owner: context.repo.owner, - repo: context.repo.repo, - name: 'Vercel Deployment Preview', - head_sha: context.payload.pull_request.head.sha, - status: 'completed', - conclusion: 'success', - output: { - title: 'Vercel Deployment Preview', - summary: summary, - }, - }); - } + token: ${{ secrets.GITHUB_TOKEN }} + prepend: | + + + šŸš€ **Deployment Preview Available!** + + **Deployment URL:** [${{ steps.vercel_url.outputs.deployment_url }}](${{ steps.vercel_url.outputs.deployment_url }}) + + **Direct links to the updated files:** + ${{ steps.links.outputs.links }} + + --- + + retain-cycles: 1 From cc05bcfda028d5fff782f35cedcc200a350ea786 Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Wed, 25 Sep 2024 16:10:35 +0100 Subject: [PATCH 27/38] add --- .github/workflows/preview-link.yml | 55 +++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/.github/workflows/preview-link.yml b/.github/workflows/preview-link.yml index 7102fa35da7..38f97a65773 100644 --- a/.github/workflows/preview-link.yml +++ b/.github/workflows/preview-link.yml @@ -21,8 +21,6 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 - with: - fetch-depth: 0 - name: Install necessary tools run: | @@ -35,11 +33,8 @@ jobs: # 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') + # Convert to lowercase and sanitize branch name + BRANCH_NAME_SANITIZED=$(echo "$BRANCH_NAME" | tr '[:upper:]' '[: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" @@ -77,7 +72,7 @@ jobs: id: files run: | # Get the list of changed files in the specified directories - 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) + 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) echo "Changed files:" echo "$CHANGED_FILES" @@ -123,19 +118,45 @@ jobs: echo "EOF" >> $GITHUB_OUTPUT - name: Update PR description with deployment links - uses: peter-evans/pull-request-description@v2 + uses: actions/github-script@v6 with: - token: ${{ secrets.GITHUB_TOKEN }} - prepend: | - + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const prNumber = context.issue.number; - šŸš€ **Deployment Preview Available!** + // Fetch the current PR description + const { data: pullRequest } = await github.rest.pulls.get({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: prNumber, + }); - **Deployment URL:** [${{ steps.vercel_url.outputs.deployment_url }}](${{ steps.vercel_url.outputs.deployment_url }}) + let body = pullRequest.body || ''; + + // Define the markers + const startMarker = ''; + const endMarker = ''; + // Build the deployment content + const deploymentContent = `${startMarker} + šŸš€ **Deployment Preview Available!** + **Deployment URL:** [${{ steps.vercel_url.outputs.deployment_url }}](${{ steps.vercel_url.outputs.deployment_url }}) **Direct links to the updated files:** ${{ steps.links.outputs.links }} - --- - - retain-cycles: 1 + ${endMarker}`; + + // Remove existing deployment content between markers + const regex = new RegExp(`${startMarker}[\\s\\S]*?${endMarker}`, 'g'); + body = body.replace(regex, '').trim(); + + // Prepend the new deployment content + body = `${deploymentContent}\n\n${body}`; + + // Update the PR description + await github.rest.pulls.update({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: prNumber, + body: body, + }); From 59069e14602bf8d16fc9f4a7a7bba4933fd7d958 Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Wed, 25 Sep 2024 16:14:12 +0100 Subject: [PATCH 28/38] add --- .github/workflows/preview-link.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/preview-link.yml b/.github/workflows/preview-link.yml index 38f97a65773..9c54ca61555 100644 --- a/.github/workflows/preview-link.yml +++ b/.github/workflows/preview-link.yml @@ -139,8 +139,8 @@ jobs: // Build the deployment content const deploymentContent = `${startMarker} - šŸš€ **Deployment Preview Available!** - **Deployment URL:** [${{ steps.vercel_url.outputs.deployment_url }}](${{ steps.vercel_url.outputs.deployment_url }}) + šŸš€ **Deployment preview available!** + **Deployment URLs:** [${{ steps.links.outputs.links }}](${{ steps.links.outputs.links }}) **Direct links to the updated files:** ${{ steps.links.outputs.links }} --- From 37ad7decdeb1238f1175fd013d5d11f6857a2307 Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Wed, 25 Sep 2024 16:19:06 +0100 Subject: [PATCH 29/38] add --- .github/workflows/preview-link.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/preview-link.yml b/.github/workflows/preview-link.yml index 9c54ca61555..6d3803a2026 100644 --- a/.github/workflows/preview-link.yml +++ b/.github/workflows/preview-link.yml @@ -140,9 +140,9 @@ jobs: // Build the deployment content const deploymentContent = `${startMarker} šŸš€ **Deployment preview available!** - **Deployment URLs:** [${{ steps.links.outputs.links }}](${{ steps.links.outputs.links }}) + **Deployment URL:** [${inputs.deployment_url}](${inputs.deployment_url}) **Direct links to the updated files:** - ${{ steps.links.outputs.links }} + ${inputs.links} --- ${endMarker}`; @@ -160,3 +160,5 @@ jobs: pull_number: prNumber, body: body, }); + deployment_url: ${{ steps.vercel_url.outputs.deployment_url }} + links: ${{ steps.links.outputs.links }} From bc8474dba87bbc31a39fbdb1f5bee6f86b377b98 Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Wed, 25 Sep 2024 16:30:42 +0100 Subject: [PATCH 30/38] add --- .github/workflows/preview-link.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/preview-link.yml b/.github/workflows/preview-link.yml index 6d3803a2026..c44604407e0 100644 --- a/.github/workflows/preview-link.yml +++ b/.github/workflows/preview-link.yml @@ -121,6 +121,8 @@ jobs: uses: actions/github-script@v6 with: github-token: ${{ secrets.GITHUB_TOKEN }} + deployment_url: ${{ steps.vercel_url.outputs.deployment_url }} + links: ${{ steps.links.outputs.links }} script: | const prNumber = context.issue.number; @@ -160,5 +162,3 @@ jobs: pull_number: prNumber, body: body, }); - deployment_url: ${{ steps.vercel_url.outputs.deployment_url }} - links: ${{ steps.links.outputs.links }} From 964fc6d884131256c4b1e283404947d1cd585b1a Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Wed, 25 Sep 2024 16:34:02 +0100 Subject: [PATCH 31/38] add --- .github/workflows/preview-link.yml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/.github/workflows/preview-link.yml b/.github/workflows/preview-link.yml index c44604407e0..04c97f4bdae 100644 --- a/.github/workflows/preview-link.yml +++ b/.github/workflows/preview-link.yml @@ -121,8 +121,6 @@ jobs: uses: actions/github-script@v6 with: github-token: ${{ secrets.GITHUB_TOKEN }} - deployment_url: ${{ steps.vercel_url.outputs.deployment_url }} - links: ${{ steps.links.outputs.links }} script: | const prNumber = context.issue.number; @@ -139,12 +137,17 @@ jobs: const startMarker = ''; const endMarker = ''; + // Get the deployment URL and links from environment variables + const deploymentUrl = process.env.DEPLOYMENT_URL; + const links = process.env.LINKS; + // Build the deployment content const deploymentContent = `${startMarker} šŸš€ **Deployment preview available!** - **Deployment URL:** [${inputs.deployment_url}](${inputs.deployment_url}) + **Deployment URL:** [${deploymentUrl}](${deploymentUrl}) + **Direct links to the updated files:** - ${inputs.links} + ${links} --- ${endMarker}`; @@ -162,3 +165,6 @@ jobs: pull_number: prNumber, body: body, }); + env: + DEPLOYMENT_URL: ${{ steps.vercel_url.outputs.deployment_url }} + LINKS: ${{ steps.links.outputs.links }} From 9618c965d57a60803988b9b8b052bf5c876529f4 Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Wed, 25 Sep 2024 16:38:59 +0100 Subject: [PATCH 32/38] add --- .github/workflows/preview-link.yml | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/.github/workflows/preview-link.yml b/.github/workflows/preview-link.yml index 04c97f4bdae..c11253676e6 100644 --- a/.github/workflows/preview-link.yml +++ b/.github/workflows/preview-link.yml @@ -21,6 +21,8 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Install necessary tools run: | @@ -33,8 +35,11 @@ jobs: # Get the branch name BRANCH_NAME="${{ github.head_ref }}" - # Convert to lowercase and sanitize branch name - BRANCH_NAME_SANITIZED=$(echo "$BRANCH_NAME" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]/-/g') + # 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" @@ -72,7 +77,7 @@ jobs: id: files run: | # Get the list of changed files in the specified directories - 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) + 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) echo "Changed files:" echo "$CHANGED_FILES" @@ -94,12 +99,12 @@ jobs: if [ -z "$CHANGED_FILES" ]; then echo "No changed files found in the specified directories." - LINKS="- No documentation files were changed." + LINKS="No documentation files were changed." else LINKS="" # Convert CHANGED_FILES back to newline-separated for processing - echo "$CHANGED_FILES" | tr ' ' '\n' > files.txt - while IFS= read -r FILE; do + 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 @@ -107,9 +112,8 @@ jobs: # Construct the full URL FULL_URL="$DEPLOYMENT_URL/$FILE_PATH" - LINKS="$LINKS\n- [$FILE_PATH]($FULL_URL)" - done < files.txt - rm files.txt + LINKS="$LINKS\n$FULL_URL" + done fi # Properly set the multi-line output @@ -143,10 +147,7 @@ jobs: // Build the deployment content const deploymentContent = `${startMarker} - šŸš€ **Deployment preview available!** - **Deployment URL:** [${deploymentUrl}](${deploymentUrl}) - - **Direct links to the updated files:** + šŸš€ Deployment available! Here are the direct links to the updated files: ${links} --- ${endMarker}`; From d3bbee0c1928636c068f989f549f90b302bea7d1 Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Wed, 25 Sep 2024 16:43:54 +0100 Subject: [PATCH 33/38] add --- .github/workflows/preview-link.yml | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/.github/workflows/preview-link.yml b/.github/workflows/preview-link.yml index c11253676e6..5561d1a916d 100644 --- a/.github/workflows/preview-link.yml +++ b/.github/workflows/preview-link.yml @@ -112,7 +112,7 @@ jobs: # Construct the full URL FULL_URL="$DEPLOYMENT_URL/$FILE_PATH" - LINKS="$LINKS\n$FULL_URL" + LINKS="$LINKS\n- $FULL_URL" done fi @@ -145,12 +145,16 @@ jobs: const deploymentUrl = process.env.DEPLOYMENT_URL; const links = process.env.LINKS; - // Build the deployment content - const deploymentContent = `${startMarker} - šŸš€ Deployment available! Here are the direct links to the updated files: - ${links} - --- - ${endMarker}`; + // 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'); From 48ed9db426bdd3f6f0bb66d5c659bb8578726408 Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Wed, 25 Sep 2024 16:58:21 +0100 Subject: [PATCH 34/38] add --- .github/workflows/preview-link.yml | 46 +++++++----------------------- 1 file changed, 11 insertions(+), 35 deletions(-) diff --git a/.github/workflows/preview-link.yml b/.github/workflows/preview-link.yml index 5561d1a916d..2eed7fdf284 100644 --- a/.github/workflows/preview-link.yml +++ b/.github/workflows/preview-link.yml @@ -4,11 +4,7 @@ on: pull_request: types: [opened, synchronize] paths: - - 'website/docs/docs/**' - - 'website/docs/best-practices/**' - - 'website/docs/guides/**' - - 'website/docs/faqs/**' - - 'website/docs/reference/**' + - 'website/docs/**' permissions: contents: write @@ -49,29 +45,8 @@ jobs: - 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 + echo "Waiting for 5 minutes to allow the deployment to complete..." + sleep 300 # Wait for 300 seconds (5 minutes) - name: Get changed files id: files @@ -112,7 +87,7 @@ jobs: # Construct the full URL FULL_URL="$DEPLOYMENT_URL/$FILE_PATH" - LINKS="$LINKS\n- $FULL_URL" + LINKS="$LINKS\n$FULL_URL" done fi @@ -148,11 +123,12 @@ jobs: // 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'); @@ -160,8 +136,8 @@ jobs: const regex = new RegExp(`${startMarker}[\\s\\S]*?${endMarker}`, 'g'); body = body.replace(regex, '').trim(); - // Prepend the new deployment content - body = `${deploymentContent}\n\n${body}`; + // Append the new deployment content + body = `${body}\n\n${deploymentContent}`; // Update the PR description await github.rest.pulls.update({ @@ -170,6 +146,6 @@ jobs: pull_number: prNumber, body: body, }); - env: - DEPLOYMENT_URL: ${{ steps.vercel_url.outputs.deployment_url }} - LINKS: ${{ steps.links.outputs.links }} + env: + DEPLOYMENT_URL: ${{ steps.vercel_url.outputs.deployment_url }} + LINKS: ${{ steps.links.outputs.links }} From 8c6c6171b225ae544808517547adc0406bcbcdbd Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Wed, 25 Sep 2024 16:58:58 +0100 Subject: [PATCH 35/38] add --- .github/workflows/preview-link.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/preview-link.yml b/.github/workflows/preview-link.yml index 2eed7fdf284..5b28c19757d 100644 --- a/.github/workflows/preview-link.yml +++ b/.github/workflows/preview-link.yml @@ -4,7 +4,11 @@ on: pull_request: types: [opened, synchronize] paths: - - 'website/docs/**' + - 'website/docs/docs/**' + - 'website/docs/best-practices/**' + - 'website/docs/guides/**' + - 'website/docs/faqs/**' + - 'website/docs/reference/**' permissions: contents: write From 0e407fac77b85fc41ca5cbf2d16a21bca0635c86 Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Wed, 25 Sep 2024 17:07:25 +0100 Subject: [PATCH 36/38] add --- .github/workflows/preview-link.yml | 36 +++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/.github/workflows/preview-link.yml b/.github/workflows/preview-link.yml index 5b28c19757d..8ea9a99aab8 100644 --- a/.github/workflows/preview-link.yml +++ b/.github/workflows/preview-link.yml @@ -49,8 +49,29 @@ jobs: - name: Wait for deployment to be accessible id: wait_for_deployment run: | - echo "Waiting for 5 minutes to allow the deployment to complete..." - sleep 300 # Wait for 300 seconds (5 minutes) + 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 @@ -91,7 +112,7 @@ jobs: # Construct the full URL FULL_URL="$DEPLOYMENT_URL/$FILE_PATH" - LINKS="$LINKS\n$FULL_URL" + LINKS="$LINKS\n- $FULL_URL" done fi @@ -127,12 +148,11 @@ jobs: // 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'); @@ -150,6 +170,6 @@ jobs: pull_number: prNumber, body: body, }); - env: - DEPLOYMENT_URL: ${{ steps.vercel_url.outputs.deployment_url }} - LINKS: ${{ steps.links.outputs.links }} + env: + DEPLOYMENT_URL: ${{ steps.vercel_url.outputs.deployment_url }} + LINKS: ${{ steps.links.outputs.links }} From e0596c7367a896521590cbeaa47ee98357b4d642 Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Fri, 4 Oct 2024 15:59:09 +0100 Subject: [PATCH 37/38] update --- .github/workflows/preview-link.yml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/preview-link.yml b/.github/workflows/preview-link.yml index 8ea9a99aab8..8c5bb7d6dea 100644 --- a/.github/workflows/preview-link.yml +++ b/.github/workflows/preview-link.yml @@ -76,18 +76,12 @@ jobs: - name: Get changed files id: files run: | - # Get the list of changed files in the specified directories 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) - echo "Changed files:" - echo "$CHANGED_FILES" - - # Check if any files were changed if [ -z "$CHANGED_FILES" ]; then echo "No documentation files were changed." echo "changed_files=" >> $GITHUB_OUTPUT else - # Convert line-separated files to space-separated for easier handling - CHANGED_FILES="$(echo "$CHANGED_FILES" | tr '\n' ' ')" + CHANGED_FILES=$(echo "$CHANGED_FILES" | tr '\n' ' ') echo "changed_files=$CHANGED_FILES" >> $GITHUB_OUTPUT fi From 34b2ddb947d2ce2ce8be09b1170ad0c1f7438eb3 Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Fri, 4 Oct 2024 16:05:31 +0100 Subject: [PATCH 38/38] add line --- .github/workflows/preview-link.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/preview-link.yml b/.github/workflows/preview-link.yml index 8c5bb7d6dea..f128f44b8cd 100644 --- a/.github/workflows/preview-link.yml +++ b/.github/workflows/preview-link.yml @@ -142,11 +142,11 @@ jobs: // 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');