Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: Prepend banner and remove lock #701

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/forty-hats-exercise.md
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions actions/md-confluence-sync/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ runs:
run: |
go install github.com/kovetskiy/[email protected]
- name: Get default branch
id: get_default_branch
uses: actions/github-script@v6
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
uses: actions/github-script@v6
uses: actions/github-script@v7

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 }}
Expand All @@ -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
60 changes: 49 additions & 11 deletions actions/md-confluence-sync/mark-sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo "DEFAULT_BRANCH is not set. Exiting."
echo "::error::DEFAULT_BRANCH is not set. Exiting."

Not crucial but it makes the error obvious in the run logs (highlighted red).

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="<!-- Macro: :disclaimer-box:([^:]+):([^:]*):(.+):
Template: ac:box
Icon: true
Name: \${1}
Title: \${2}
Body: \${3} -->

: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
Loading