feat(action): add Markdown to HTML publishing workflow
- Introduce a GitHub Action to convert Markdown files to HTML using Pandoc - Configure steps for repository checkout, git setup, and branch management - Include scripts for Markdown conversion, Pandoc installation, and git setup - Automate the publishing of HTML output to a specified branch
This commit is contained in:
85
action.yml
Normal file
85
action.yml
Normal file
@@ -0,0 +1,85 @@
|
||||
name: "Markdown → HTML Publisher"
|
||||
description: >
|
||||
Converts all *.md files in the given path (recursively) to HTML via Pandoc
|
||||
and commits the result into the specified branch as an orphan branch,
|
||||
replacing the entire branch content and removing history.
|
||||
|
||||
inputs:
|
||||
path:
|
||||
description: "Directory to scan for Markdown files (default: $GITHUB_WORKSPACE)"
|
||||
required: false
|
||||
branch:
|
||||
description: "Target branch that will receive the generated HTML"
|
||||
required: false
|
||||
default: pages
|
||||
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
# 0) Checkout repository with full history so we can delete/reset branches
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
# 1) Configure git author (uses default values if none supplied)
|
||||
- name: Setup git author
|
||||
shell: bash
|
||||
run: |
|
||||
bash "${{ github.action_path }}/scripts/setup-git.sh"
|
||||
|
||||
# 2) Install or ensure pandoc is present
|
||||
- name: Install pandoc
|
||||
shell: bash
|
||||
run: |
|
||||
bash "${{ github.action_path }}/scripts/install-pandoc.sh"
|
||||
|
||||
# 3) Convert Markdown files to HTML into a temporary directory
|
||||
- name: Convert Markdown tree
|
||||
shell: bash
|
||||
run: |
|
||||
SRC_DIR="${{ inputs.path }}"
|
||||
[[ -z "$SRC_DIR" ]] && SRC_DIR="$GITHUB_WORKSPACE"
|
||||
TMP_DIR="$(mktemp -d)"
|
||||
bash "${{ github.action_path }}/scripts/convert-md-tree.sh" "$SRC_DIR" "$TMP_DIR"
|
||||
echo "TMP_DIR=$TMP_DIR" >> "$GITHUB_ENV"
|
||||
|
||||
# 4) Delete target branch (if it exists) and create new orphan branch
|
||||
- name: Recreate orphan target branch
|
||||
shell: bash
|
||||
run: |
|
||||
TARGET_BRANCH="${{ inputs.branch }}"
|
||||
[[ -z "$TARGET_BRANCH" ]] && TARGET_BRANCH="pages"
|
||||
|
||||
if git show-ref --quiet "refs/heads/$TARGET_BRANCH"; then
|
||||
git branch -D "$TARGET_BRANCH"
|
||||
fi
|
||||
|
||||
git switch --orphan "$TARGET_BRANCH"
|
||||
git rm -rf . || true
|
||||
|
||||
echo "TARGET_BRANCH=$TARGET_BRANCH" >> "$GITHUB_ENV"
|
||||
|
||||
# 5) Replace contents of the branch with generated HTML
|
||||
- name: Replace branch contents
|
||||
shell: bash
|
||||
run: |
|
||||
shopt -s dotglob
|
||||
rm -rf ./* || true
|
||||
cp -r "$TMP_DIR"/. .
|
||||
rm -rf "$TMP_DIR"
|
||||
|
||||
# 6) Commit and push changes if there are any
|
||||
- name: Commit and push changes
|
||||
shell: bash
|
||||
run: |
|
||||
TARGET_BRANCH="${TARGET_BRANCH:-${{ inputs.branch }}}"
|
||||
[[ -z "$TARGET_BRANCH" ]] && TARGET_BRANCH="pages"
|
||||
if git status --porcelain | grep -q .
|
||||
then
|
||||
git add .
|
||||
git commit -m "Automatic HTML publish: $(date -u +'%Y-%m-%d %H:%M:%S UTC')"
|
||||
git push --force origin "$TARGET_BRANCH"
|
||||
else
|
||||
echo "ℹ️ No changes to commit."
|
||||
fi
|
Reference in New Issue
Block a user