From a1e88188f0cdd99c6ec523a0befb082c1a36a730 Mon Sep 17 00:00:00 2001 From: ztefanie Date: Wed, 26 Feb 2025 09:34:20 +0100 Subject: [PATCH] chore(element-tempaltes): Add github action fro bumping element template docs links --- .../BUMP_ELEMENT_TEMPLATE_DOCS_LINKS.yml | 66 +++++++++++++++++++ ...collect_all_element_template_docs_links.sh | 47 +++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 .github/workflows/BUMP_ELEMENT_TEMPLATE_DOCS_LINKS.yml create mode 100755 .github/workflows/scripts/collect_all_element_template_docs_links.sh diff --git a/.github/workflows/BUMP_ELEMENT_TEMPLATE_DOCS_LINKS.yml b/.github/workflows/BUMP_ELEMENT_TEMPLATE_DOCS_LINKS.yml new file mode 100644 index 0000000000..da4e060dbb --- /dev/null +++ b/.github/workflows/BUMP_ELEMENT_TEMPLATE_DOCS_LINKS.yml @@ -0,0 +1,66 @@ +name: bump_element_template_docs_links + +on: + workflow_dispatch: + pull_request: + types: [ opened, synchronize, reopened ] #TODO remove, just for testing + schedule: + - cron: "0 3 1 * *" # Runs monthly on the 1st at 03:00 UTC + +jobs: + bump_element_template_docs_links: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Collect connector template links + run: | + chmod +x ./.github/workflows/scripts/collect_all_element_template_docs_links.sh + ./.github/workflows/scripts/collect_all_element_template_docs_links.sh + shell: bash + + - name: Clone camunda-docs repository + run: | + git clone https://github.com/camunda/camunda-docs.git + cd camunda-docs + git config --global user.name "github-actions[bot]" + git config --global user.email "github-actions[bot]@users.noreply.github.com" + + - name: Compare files + id: check_diff + run: | + cd camunda-docs + if diff -q connectors-element-template-links.txt ../connector-element-template-links.txt > /dev/null; then + echo "No changes to commit." + echo "NO_CHANGES=true" >> $GITHUB_ENV + else + echo "Changes detected." + echo "NO_CHANGES=false" >> $GITHUB_ENV + fi + + - name: Exit if no changes + if: env.NO_CHANGES == 'true' + run: echo "No changes detected, exiting successfully." + + - name: Create branch, commit, and push changes + if: env.NO_CHANGES == 'false' + run: | + cd camunda-docs + BRANCH_NAME="update-connector-links-$(date +'%m-%Y')" + git checkout -b "$BRANCH_NAME" + mv ../connector-element-template-links.txt connectors-element-template-links.txt + git add connectors-element-template-links.txt + git commit -m "Update connector element template links for $(date +'%B %Y')" + git push origin "$BRANCH_NAME" + + - name: Open a pull request in camunda-docs + if: env.NO_CHANGES == 'false' + uses: peter-evans/create-pull-request@v6 + with: + token: ${{ secrets.CAMUNDA_DOCS_PAT }} + repository: camunda/camunda-docs + branch: update-connector-links-$(date +'%m-%Y') + title: "Update Connector Element Template Links - $(date +'%B %Y')" + body: "This PR updates the connector element template links for $(date +'%B %Y')." + base: main diff --git a/.github/workflows/scripts/collect_all_element_template_docs_links.sh b/.github/workflows/scripts/collect_all_element_template_docs_links.sh new file mode 100755 index 0000000000..d1417b7a9f --- /dev/null +++ b/.github/workflows/scripts/collect_all_element_template_docs_links.sh @@ -0,0 +1,47 @@ +#!/bin/bash +set -e + +DOCUSAURUS_BASE_URL="https://docs.camunda.io/" +GITHUB_FILE_URL="https://raw.githubusercontent.com/camunda/camunda-docs/d50f0a316cc629c43b2038d1a814a70dbac17add/connectors-element-template-links.txt" +DOCS_REPO_LINK_FILE="connector-element-template-links-download.txt" +CURRENT_LINK_FILE="connector-element-template-links-current.txt" +NEW_LINK_FILE="connectors-element-template-links.txt" + +# Clear files +: > "$DOCS_REPO_LINK_FILE" +: > "$CURRENT_LINK_FILE" +: > "$NEW_LINK_FILE" + +echo "Downloading existing links file from docs repo..." +curl -sL "$GITHUB_FILE_URL" | grep "^$DOCUSAURUS_BASE_URL" > "$DOCS_REPO_LINK_FILE" + + +echo "Extracting links from connectors repo..." + +extract_links_from_file() { + local file_path="$1" + grep -oE "\"$DOCUSAURUS_BASE_URL[^\"]+\"" "$file_path" | sed -E "s|\"||g; s|[\\/]$||g" +} + +# Find all JSON files in "element-templates" directories, extract documentation links, +find . -type d -name "element-templates" | while read -r dir; do + find "$dir" -type f -name "*.json" | while read -r file; do + extract_links_from_file "$file" + done +done | sort -u >> "$CURRENT_LINK_FILE" # Sort & remove duplicates before writing + + +echo "Merging links from docs file and new file..." +cat "$CURRENT_LINK_FILE" "$DOCS_REPO_LINK_FILE" | sort -u > "$NEW_LINK_FILE" + +echo -e "# This file contains links from connectors element templates to the documentation +# This file is used to check that we don't accidentally break these links\n\n$(cat "$NEW_LINK_FILE")" > "$NEW_LINK_FILE" + +rm $DOCS_REPO_LINK_FILE +rm $CURRENT_LINK_FILE + +echo "Script completed successfully." +exit 0 + + +