From 5e8b88a3f88bac1ef6bd67ed29774a99ac883bf5 Mon Sep 17 00:00:00 2001 From: Radek Scheibinger Date: Fri, 8 Nov 2024 13:59:30 +0100 Subject: [PATCH] feat: Prepend banner and remove lock --- .changeset/forty-hats-exercise.md | 6 +++ actions/md-confluence-sync/action.yml | 13 ++++++ actions/md-confluence-sync/mark-sync.sh | 60 ++++++++++++++++++++----- 3 files changed, 68 insertions(+), 11 deletions(-) create mode 100644 .changeset/forty-hats-exercise.md diff --git a/.changeset/forty-hats-exercise.md b/.changeset/forty-hats-exercise.md new file mode 100644 index 00000000..70f26d2f --- /dev/null +++ b/.changeset/forty-hats-exercise.md @@ -0,0 +1,6 @@ +--- +"md-confluence-sync": minor +--- + +Prepend Disclaimer banner to prevent manual edits. Remove lock from the article, +so they can be labeled for deletion diff --git a/actions/md-confluence-sync/action.yml b/actions/md-confluence-sync/action.yml index bafa63fa..dc21d440 100644 --- a/actions/md-confluence-sync/action.yml +++ b/actions/md-confluence-sync/action.yml @@ -60,6 +60,18 @@ runs: run: | go install github.com/kovetskiy/mark@11.1.0 + - name: Get default branch + id: get_default_branch + uses: actions/github-script@v6 + with: + script: | + const repo = await github.repos.get({ + owner: context.repo.owner, + repo: context.repo.repo + }); + return repo.data.default_branch; + result-encoding: string + - name: Sync docs env: FILES: ${{ inputs.files }} @@ -70,5 +82,6 @@ runs: PARENT: ${{ inputs.parent }} MARK_DEBUG: ${{ inputs.debug }} MARK_DRY_RUN: ${{ inputs.dry-run }} + DEFAULT_BRANCH: ${{ steps.get_default_branch.outputs.result }} shell: bash run: ${{ github.action_path }}/mark-sync.sh diff --git a/actions/md-confluence-sync/mark-sync.sh b/actions/md-confluence-sync/mark-sync.sh index 26013e28..7de9aa09 100755 --- a/actions/md-confluence-sync/mark-sync.sh +++ b/actions/md-confluence-sync/mark-sync.sh @@ -36,14 +36,52 @@ if [[ -z "${PARENT:-}" ]]; then exit 1 fi -# Mermaid diagrams are rendered locally and inlined into the HTML artifact as PNGs. -mark -f "$FILES" \ - --edit-lock \ - --title-from-h1 \ - -u "$USER" \ - -p "$TOKEN" \ - -b "$BASE_URL" \ - --space "$SPACE" \ - --parents "$PARENT" \ - --mermaid-provider mermaid-go \ - --ci +if [[ -z "${DEFAULT_BRANCH:-}" ]]; then + echo "DEFAULT_BRANCH is not set. Exiting." + exit 1 +fi + + + +# Prepends disclaimer banner +function prepend_disclaimer_banner() { + # Enable recursive globbing + shopt -s globstar + + # Loop over each file matching the glob expression + for file in $FILES; do + edit_url="https://github.com/$GITHUB_REPOSITORY/blob/$DEFAULT_BRANCH/$file" + # The syntax for disclaimer banner is based on this https://github.com/kovetskiy/mark?tab=readme-ov-file#insert-colored-text-box + disclaimer_banner=" + +:disclaimer-box:note:Caution:This page is managed in github! Do not edit here! [Edit in Github](${edit_url}): +" + + # Prepend the text block to the file using a temporary file + { echo "$disclaimer_banner"; cat "$file"; } > temp_file && mv temp_file "$file" + done + + # Disable globstar after we're done (optional) + shopt -u globstar +} + +function publish_to_confluence() { + # Mermaid diagrams are rendered locally and inlined into the HTML artifact as PNGs. + mark -f "$FILES" \ + --title-from-h1 \ + -u "$USER" \ + -p "$TOKEN" \ + -b "$BASE_URL" \ + --space "$SPACE" \ + --parents "$PARENT" \ + --mermaid-provider mermaid-go \ + --ci +} + +prepend_disclaimer_banner +publish_to_confluence \ No newline at end of file