From aab34098292006f7c1cb34f03ed87c49f7de6453 Mon Sep 17 00:00:00 2001 From: Hannah Hunter Date: Thu, 15 Jun 2023 14:50:52 -0400 Subject: [PATCH 01/10] update dapr publish command Signed-off-by: Hannah Hunter Signed-off-by: Aaron Crawfis --- .../building-blocks/pubsub/pubsub-cloudevents.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md b/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md index 251d3f234c1..51d442f8a71 100644 --- a/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md +++ b/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md @@ -92,7 +92,7 @@ You can add additional fields to a custom CloudEvent that are not part of the of Publish a CloudEvent to the `orders` topic: ```bash -dapr publish --publish-app-id orderprocessing --pubsub order-pub-sub --topic orders --data '{"specversion" : "1.0", "type" : "com.dapr.cloudevent.sent", "source" : "testcloudeventspubsub", "subject" : "Cloud Events Test", "id" : "someCloudEventId", "time" : "2021-08-02T09:00:00Z", "datacontenttype" : "application/cloudevents+json", "data" : {"orderId": "100"}}' +dapr publish --publish-app-id orderprocessing --pubsub order-pub-sub --topic orders --data '{\"orderId\": \"100\"}' ``` {{% /codetab %}} From f046f3a04a35e55799bd0dbea7649c8f44ce96aa Mon Sep 17 00:00:00 2001 From: Aaron Crawfis Date: Fri, 16 Jun 2023 13:57:54 -0700 Subject: [PATCH 02/10] Split workflow into two steps Signed-off-by: Aaron Crawfis --- .github/workflows/website-root.yml | 78 ++++++++++++++++++++++-------- 1 file changed, 58 insertions(+), 20 deletions(-) diff --git a/.github/workflows/website-root.yml b/.github/workflows/website-root.yml index 0265713f715..9086adde63f 100644 --- a/.github/workflows/website-root.yml +++ b/.github/workflows/website-root.yml @@ -1,6 +1,7 @@ -name: Azure Static Web App Root +name: Dapr Root Website on: + workflow_dispatch: push: branches: - v1.11 @@ -10,34 +11,71 @@ on: - v1.11 jobs: - build_and_deploy_job: - if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed') + build: + name: Build Hugo Website + if: github.event.action != 'closed' runs-on: ubuntu-latest - name: Build and Deploy Job + env: + SWA_BASE: 'proud-bay-0e9e0e81e' + HUGO_ENV: production steps: - - uses: actions/checkout@v3 + - name: Checkout docs repo + uses: actions/checkout@v3 with: - submodules: recursive - fetch-depth: 0 + submodules: true + - name: Setup Node + uses: actions/setup-node@v2 + with: + node-version: '14' + - name: Setup Hugo + uses: peaceiris/actions-hugo@v2.5.0 + with: + hugo-version: 0.102.3 + extended: true - name: Setup Docsy - run: cd daprdocs && git submodule update --init --recursive && sudo npm install -D --save autoprefixer && sudo npm install -D --save postcss-cli - - name: Build And Deploy - id: builddeploy + run: | + cd daprdocs + git submodule update --init --recursive + sudo npm install -D --save autoprefixer + sudo npm install -D --save postcss-cli + - name: Build Hugo Website + run: | + cd daprdocs + git config --global --add safe.directory /github/workspace + if [ $GITHUB_EVENT_NAME == 'pull_request' ]; then + STAGING_URL="https://${SWA_BASE}-${{github.event.number}}.westus2.azurestaticapps.net/" + fi + hugo ${STAGING_URL+-b "$STAGING_URL"} + - name: Upload Hugo artifacts + uses: actions/upload-artifact@v3 + with: + name: hugo_build + path: ./docs/public/ + if-no-files-found: error + + deploy: + name: Deploy website + needs: ['build'] + if: github.event.action != 'closed' + runs-on: ubuntu-latest + steps: + - name: Download Hugo artifacts + uses: actions/download-artifact@v3 + with: + name: hugo_build + path: site/ + - name: Deploy staging site uses: Azure/static-web-apps-deploy@v1 - env: - HUGO_ENV: production - HUGO_VERSION: "0.100.2" with: azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_PROUD_BAY_0E9E0E81E }} - skip_deploy_on_missing_secrets: true - repo_token: ${{ secrets.GITHUB_TOKEN }} # Used for Github integrations (i.e. PR comments) + repo_token: ${{ secrets.GITHUB_TOKEN }} action: "upload" - app_location: "/daprdocs" - app_build_command: "git config --global --add safe.directory /github/workspace && hugo" - output_location: "public" - skip_api_build: true + app_location: "site/" + api_location: "site/" + output_location: "" + skip_app_build: true - close_pull_request_job: + close_staging_site: if: github.event_name == 'pull_request' && github.event.action == 'closed' runs-on: ubuntu-latest name: Close Pull Request Job From 72ca8d0771859d6f6cc6b25871f20e9557f96f5f Mon Sep 17 00:00:00 2001 From: Aaron Crawfis Date: Fri, 16 Jun 2023 15:12:33 -0700 Subject: [PATCH 03/10] Update upload path Signed-off-by: Aaron Crawfis --- .github/workflows/website-root.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/website-root.yml b/.github/workflows/website-root.yml index 9086adde63f..1368257fc38 100644 --- a/.github/workflows/website-root.yml +++ b/.github/workflows/website-root.yml @@ -50,7 +50,7 @@ jobs: uses: actions/upload-artifact@v3 with: name: hugo_build - path: ./docs/public/ + path: ./daprdocs/public/ if-no-files-found: error deploy: From 0bcf6a824afa8411f169d11d381075c31be2fc5d Mon Sep 17 00:00:00 2001 From: Aaron Crawfis Date: Fri, 16 Jun 2023 15:15:57 -0700 Subject: [PATCH 04/10] Add concurrency check Signed-off-by: Aaron Crawfis --- .github/workflows/website-root.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/website-root.yml b/.github/workflows/website-root.yml index 1368257fc38..7627c03dc17 100644 --- a/.github/workflows/website-root.yml +++ b/.github/workflows/website-root.yml @@ -10,6 +10,11 @@ on: branches: - v1.11 +concurrency: + # Cancel the previously triggered build for only PR build. + group: website-${{ github.event.pull_request.number || github.sha }} + cancel-in-progress: true + jobs: build: name: Build Hugo Website From 3e81d6eb7167e66ec6fde4e9072e33f77e0b7dca Mon Sep 17 00:00:00 2001 From: Aaron Crawfis Date: Fri, 16 Jun 2023 15:22:39 -0700 Subject: [PATCH 05/10] Add Algolia workflow script and step Signed-off-by: Aaron Crawfis --- .github/scripts/algolia.py | 111 +++++++++++++++++++++++++++++ .github/workflows/website-root.yml | 27 +++++++ 2 files changed, 138 insertions(+) create mode 100644 .github/scripts/algolia.py diff --git a/.github/scripts/algolia.py b/.github/scripts/algolia.py new file mode 100644 index 00000000000..35aefc0a268 --- /dev/null +++ b/.github/scripts/algolia.py @@ -0,0 +1,111 @@ +import os +from re import S +import sys +import json +from bs4 import BeautifulSoup +from algoliasearch.search_client import SearchClient + +url = "docs.dapr.io" +if len(sys.argv) > 1: + starting_directory = os.path.join(os.getcwd(), str(sys.argv[1])) +else: + starting_directory = os.getcwd() + +ALGOLIA_APP_ID = os.getenv('ALGOLIA_APP_ID') +ALGOLIA_API_KEY = os.getenv('ALGOLIA_API_WRITE_KEY') +ALGOLIA_INDEX_NAME = os.getenv('ALGOLIA_INDEX_NAME') + +client = SearchClient.create(ALGOLIA_APP_ID, ALGOLIA_API_KEY) +index = client.init_index(ALGOLIA_INDEX_NAME) + +excluded_files = [ + "404.html", +] + +rankings = { + "Getting started": 0, + "Concepts": 100, + "Developing applications": 200, + "Operations": 300, + "Reference": 400, + "Contributing": 500, + "Home": 600 +} + +def scan_directory(directory: str, pages: list): + for file in os.listdir(directory): + path = os.path.join(directory, file) + if os.path.isfile(path): + if file.endswith(".html") and file not in excluded_files: + if '' not in open(path).read(): + print(f'Indexing: {path}') + pages.append(path) + else: + print(f'Skipping hidden page: {path}') + else: + scan_directory(path, pages) + +def parse_file(path: str): + data = {} + data["hierarchy"] = {} + data["rank"] = 999 + data["subrank"] = 99 + data["type"] = "lvl2" + data["lvl0"] = "" + data["lvl1"] = "" + data["lvl2"] = "" + data["lvl3"] = "" + text = "" + subrank = 0 + with open(path, "r", errors='ignore') as file: + content = file.read() + soup = BeautifulSoup(content, "html.parser") + for meta in soup.find_all("meta"): + if meta.get("name") == "description": + data["lvl2"] = meta.get("content") + data["hierarchy"]["lvl1"] = meta.get("content") + elif meta.get("property") == "og:title": + data["lvl0"] = meta.get("content") + data["hierarchy"]["lvl0"] = meta.get("content") + data["hierarchy"]["lvl2"] = meta.get("content") + elif meta.get("property") == "og:url": + data["url"] = meta.get("content") + data["path"] = meta.get("content").split(url)[1] + data["objectID"] = meta.get("content").split(url)[1] + breadcrumbs = soup.find_all("li", class_="breadcrumb-item") + try: + subrank = len(breadcrumbs) + data["subrank"] = subrank + except: + subrank = 99 + data["subrank"] = 99 + for bc in breadcrumbs: + section = bc.text.strip() + data["lvl1"] = section + data["hierarchy"]["lvl0"] = section + try: + data["rank"] = rankings[section] + subrank + except: + print(f"Rank not found for section {section}") + data["rank"] = 998 + break + for p in soup.find_all("p"): + if p.text != "": + text = text + p.text + data["text"] = text + return data + +def index_payload(payload): + res = index.replace_all_objects(payload) + res.wait() + + +if __name__ == "__main__": + pages = [] + payload = [] + scan_directory(starting_directory, pages) + for page in pages: + data = parse_file(page) + if "objectID" in data: + payload.append(data) + index_payload(payload) diff --git a/.github/workflows/website-root.yml b/.github/workflows/website-root.yml index 7627c03dc17..b014280c7ec 100644 --- a/.github/workflows/website-root.yml +++ b/.github/workflows/website-root.yml @@ -91,3 +91,30 @@ jobs: with: azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_PROUD_BAY_0E9E0E81E }} action: "close" + + algolia_index: + name: Index site for Algolia + ## Temporarily disable indexing on only push events for testing + #if: github.event_name == 'push' + needs: ['build', 'deploy'] + runs-on: ubuntu-latest + env: + ALGOLIA_APP_ID: ${{ secrets.ALGOLIA_API_APPID }} + ALGOLIA_API_WRITE_KEY: ${{ secrets.ALGOLIA_API_WRITE_KEY }} + ALGOLIA_INDEX_NAME: daprdocs + steps: + - name: Checkout docs repo + uses: actions/checkout@v2 + with: + submodules: false + - name: Download Hugo artifacts + uses: actions/download-artifact@v3 + with: + name: hugo_build + path: site/ + - name: Install Python packages + run: | + pip install --upgrade bs4 + pip install --upgrade 'algoliasearch>=2.0,<3.0' + - name: Index site + run: python ./.github/scripts/algolia.py ./site From a1d6b5c07bfa82fe3f767dff4f7d6b24cec84221 Mon Sep 17 00:00:00 2001 From: Aaron Crawfis Date: Fri, 16 Jun 2023 15:26:47 -0700 Subject: [PATCH 06/10] Update Algolia box to v3 Signed-off-by: Aaron Crawfis --- daprdocs/layouts/partials/hooks/body-end.html | 20 +++++++------------ daprdocs/layouts/partials/hooks/head-end.html | 2 +- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/daprdocs/layouts/partials/hooks/body-end.html b/daprdocs/layouts/partials/hooks/body-end.html index 695cf863809..79cbc117cd9 100644 --- a/daprdocs/layouts/partials/hooks/body-end.html +++ b/daprdocs/layouts/partials/hooks/body-end.html @@ -1,19 +1,13 @@ + + {{ with .Site.Params.algolia_docsearch }} - - + {{ end }} - - \ No newline at end of file diff --git a/daprdocs/layouts/partials/hooks/head-end.html b/daprdocs/layouts/partials/hooks/head-end.html index 804fe38e9ec..03e91efa215 100644 --- a/daprdocs/layouts/partials/hooks/head-end.html +++ b/daprdocs/layouts/partials/hooks/head-end.html @@ -1,3 +1,3 @@ {{ with .Site.Params.algolia_docsearch }} - + {{ end }} \ No newline at end of file From 013893fe73d38b7c0fe92df99fd47a3fb780743d Mon Sep 17 00:00:00 2001 From: Aaron Crawfis Date: Fri, 16 Jun 2023 15:40:43 -0700 Subject: [PATCH 07/10] Fix secret name Signed-off-by: Aaron Crawfis --- .github/workflows/website-root.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/website-root.yml b/.github/workflows/website-root.yml index b014280c7ec..e8a37672b7c 100644 --- a/.github/workflows/website-root.yml +++ b/.github/workflows/website-root.yml @@ -99,7 +99,7 @@ jobs: needs: ['build', 'deploy'] runs-on: ubuntu-latest env: - ALGOLIA_APP_ID: ${{ secrets.ALGOLIA_API_APPID }} + ALGOLIA_APP_ID: ${{ secrets.ALGOLIA_APP_ID }} ALGOLIA_API_WRITE_KEY: ${{ secrets.ALGOLIA_API_WRITE_KEY }} ALGOLIA_INDEX_NAME: daprdocs steps: From 4dd0687fd9634800180fc3364fb5df581fda1116 Mon Sep 17 00:00:00 2001 From: Aaron Crawfis Date: Fri, 16 Jun 2023 16:16:27 -0700 Subject: [PATCH 08/10] Override default search bar in Docsy v3 Signed-off-by: Aaron Crawfis --- .github/scripts/algolia.py | 9 ++++++- daprdocs/layouts/partials/search-input.html | 30 +++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 daprdocs/layouts/partials/search-input.html diff --git a/.github/scripts/algolia.py b/.github/scripts/algolia.py index 35aefc0a268..5071ea58006 100644 --- a/.github/scripts/algolia.py +++ b/.github/scripts/algolia.py @@ -22,6 +22,10 @@ "404.html", ] +exluded_directories = [ + "zh-hans", +] + rankings = { "Getting started": 0, "Concepts": 100, @@ -33,11 +37,14 @@ } def scan_directory(directory: str, pages: list): + if os.path.basename(directory) in exluded_directories: + print(f'Skipping directory: {directory}') + return for file in os.listdir(directory): path = os.path.join(directory, file) if os.path.isfile(path): if file.endswith(".html") and file not in excluded_files: - if '' not in open(path).read(): + if '' not in open(path, encoding="utf8").read(): print(f'Indexing: {path}') pages.append(path) else: diff --git a/daprdocs/layouts/partials/search-input.html b/daprdocs/layouts/partials/search-input.html new file mode 100644 index 00000000000..22e90024773 --- /dev/null +++ b/daprdocs/layouts/partials/search-input.html @@ -0,0 +1,30 @@ +{{ if .Site.Params.gcs_engine_id -}} + +{{ else if .Site.Params.algolia_docsearch -}} +
+{{ else if .Site.Params.offlineSearch -}} +{{ $offlineSearchIndex := resources.Get "json/offline-search-index.json" | resources.ExecuteAsTemplate "offline-search-index.json" . -}} +{{ if hugo.IsProduction -}} +{{/* Use `md5` as finger print hash function to shorten file name to avoid `file name too long` error. */ -}} +{{ $offlineSearchIndex = $offlineSearchIndex | fingerprint "md5" -}} +{{ end -}} +{{ $offlineSearchLink := $offlineSearchIndex.RelPermalink -}} + + +{{ end -}} From e08bbaf47bf7b9d5466c6869e2a539f744edd423 Mon Sep 17 00:00:00 2001 From: Aaron Crawfis Date: Fri, 16 Jun 2023 16:26:45 -0700 Subject: [PATCH 09/10] Remove temporary comment Signed-off-by: Aaron Crawfis --- .github/workflows/website-root.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/website-root.yml b/.github/workflows/website-root.yml index e8a37672b7c..ea1c33c0b5c 100644 --- a/.github/workflows/website-root.yml +++ b/.github/workflows/website-root.yml @@ -94,8 +94,7 @@ jobs: algolia_index: name: Index site for Algolia - ## Temporarily disable indexing on only push events for testing - #if: github.event_name == 'push' + if: github.event_name == 'push' needs: ['build', 'deploy'] runs-on: ubuntu-latest env: From 1f298497a0bab3b8db7ecd712a7db254a51dd4c8 Mon Sep 17 00:00:00 2001 From: Aaron Crawfis Date: Fri, 16 Jun 2023 18:00:43 -0700 Subject: [PATCH 10/10] Consolidate build and deploy Signed-off-by: Aaron Crawfis --- .github/workflows/website-root.yml | 36 ++++++++++-------------------- 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/.github/workflows/website-root.yml b/.github/workflows/website-root.yml index ea1c33c0b5c..ed8c3b491f1 100644 --- a/.github/workflows/website-root.yml +++ b/.github/workflows/website-root.yml @@ -1,4 +1,4 @@ -name: Dapr Root Website +name: Azure Static Web App Root on: workflow_dispatch: @@ -16,7 +16,7 @@ concurrency: cancel-in-progress: true jobs: - build: + build_and_deploy_job: name: Build Hugo Website if: github.event.action != 'closed' runs-on: ubuntu-latest @@ -51,34 +51,22 @@ jobs: STAGING_URL="https://${SWA_BASE}-${{github.event.number}}.westus2.azurestaticapps.net/" fi hugo ${STAGING_URL+-b "$STAGING_URL"} - - name: Upload Hugo artifacts - uses: actions/upload-artifact@v3 - with: - name: hugo_build - path: ./daprdocs/public/ - if-no-files-found: error - - deploy: - name: Deploy website - needs: ['build'] - if: github.event.action != 'closed' - runs-on: ubuntu-latest - steps: - - name: Download Hugo artifacts - uses: actions/download-artifact@v3 - with: - name: hugo_build - path: site/ - - name: Deploy staging site + - name: Deploy docs site uses: Azure/static-web-apps-deploy@v1 with: azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_PROUD_BAY_0E9E0E81E }} repo_token: ${{ secrets.GITHUB_TOKEN }} action: "upload" - app_location: "site/" - api_location: "site/" + app_location: "daprdocs/public/" + api_location: "daprdocs/public/" output_location: "" skip_app_build: true + - name: Upload Hugo artifacts + uses: actions/upload-artifact@v3 + with: + name: hugo_build + path: ./daprdocs/public/ + if-no-files-found: error close_staging_site: if: github.event_name == 'pull_request' && github.event.action == 'closed' @@ -95,7 +83,7 @@ jobs: algolia_index: name: Index site for Algolia if: github.event_name == 'push' - needs: ['build', 'deploy'] + needs: ['build_and_deploy_job'] runs-on: ubuntu-latest env: ALGOLIA_APP_ID: ${{ secrets.ALGOLIA_APP_ID }}