Skip to content
This repository was archived by the owner on Apr 26, 2026. It is now read-only.

Patch/GitHub workflow wiki update (#10) #15

Patch/GitHub workflow wiki update (#10)

Patch/GitHub workflow wiki update (#10) #15

Workflow file for this run

name: Update GitHub Wiki

Check failure on line 1 in .github/workflows/update-wiki.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/update-wiki.yml

Invalid workflow file

(Line: 78, Col: 13): The identifier 'list_changed' may not be used more than once within the same scope., (Line: 85, Col: 13): The identifier 'docs_files' may not be used more than once within the same scope.
on:
push:
branches: [ main ]
paths: [ 'docs/wiki/**' ]
workflow_dispatch: {}
jobs:
publish-wiki:
runs-on: ubuntu-latest
permissions:
contents: write
issues: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
# Allow the checked-out repository to use the workflow's token for push/fetch
persist-credentials: true
- name: Print event info
run: |
echo "GITHUB_EVENT_NAME=$GITHUB_EVENT_NAME"
echo "GITHUB_REF=$GITHUB_REF"
echo "GITHUB_SHA=$GITHUB_SHA"
echo "Event payload path: $GITHUB_EVENT_PATH"
if [ -f "$GITHUB_EVENT_PATH" ]; then echo "--- event payload ---"; cat "$GITHUB_EVENT_PATH"; echo "--- end payload ---"; fi
- name: List changed files (best-effort)
id: list_changed
run: |
git fetch --no-tags --prune --depth=5 origin "${{ github.ref }}" || true
echo "Files changed in this commit/PR:"
git --no-pager show --name-only --pretty="" "${{ github.sha }}" || git ls-files | sed -n '1,200p'
- name: Extract docs markdown files
id: docs_files
run: |
files=$(git --no-pager show --name-only --pretty="" "${{ github.sha }}" || git ls-files)
docs_md=$(echo "$files" | grep -iE '^docs/.*\.md$' || true)
if [ -z "$docs_md" ]; then
echo "docs_files=[]" >> "$GITHUB_OUTPUT"
else
# convert lines to JSON array using jq
arr=$(echo "$docs_md" | jq -R -s -c 'split("\n")[:-1]')
echo "docs_files=$arr" >> "$GITHUB_OUTPUT"
fi
- name: Add changed files to job summary
if: always()
run: |
echo "### Changed files" >> "$GITHUB_STEP_SUMMARY"
git --no-pager show --name-only --pretty="" "${{ github.sha }}" >> "$GITHUB_STEP_SUMMARY" || git ls-files | sed -n '1,200p' >> "$GITHUB_STEP_SUMMARY"
- name: Prepare token (optional DEPLOY_WIKI_TOKEN)
id: prepare_token
run: |
# Prefer an explicit PAT in DEPLOY_WIKI_TOKEN, otherwise fall back to the built-in GITHUB_TOKEN
if [ -n "${{ secrets.DEPLOY_WIKI_TOKEN }}" ]; then
echo "token_type=deploy" >> "$GITHUB_OUTPUT"
echo "token=${{ secrets.DEPLOY_WIKI_TOKEN }}" >> "$GITHUB_OUTPUT"
else
echo "token_type=github" >> "$GITHUB_OUTPUT"
echo "token=${{ secrets.GITHUB_TOKEN }}" >> "$GITHUB_OUTPUT"
fi
- name: Print event info
run: |
echo "GITHUB_EVENT_NAME=$GITHUB_EVENT_NAME"
echo "GITHUB_REF=$GITHUB_REF"
echo "GITHUB_SHA=$GITHUB_SHA"
echo "Event payload path: $GITHUB_EVENT_PATH"
if [ -f "$GITHUB_EVENT_PATH" ]; then echo "--- event payload ---"; cat "$GITHUB_EVENT_PATH"; echo "--- end payload ---"; fi
- name: List changed files (best-effort)
id: list_changed
run: |
git fetch --no-tags --prune --depth=5 origin "${{ github.ref }}" || true
echo "Files changed in this commit/PR:"
git --no-pager show --name-only --pretty="" "${{ github.sha }}" || git ls-files | sed -n '1,200p'
- name: Extract docs markdown files
id: docs_files
run: |
files=$(git --no-pager show --name-only --pretty="" "${{ github.sha }}" || git ls-files)
docs_md=$(echo "$files" | grep -iE '^docs/.*\.md$' || true)
if [ -z "$docs_md" ]; then
echo "docs_files=[]" >> "$GITHUB_OUTPUT"
else
# convert lines to JSON array using jq
arr=$(echo "$docs_md" | jq -R -s -c 'split("\n")[:-1]')
echo "docs_files=$arr" >> "$GITHUB_OUTPUT"
fi
- name: Add changed files to job summary
if: always()
run: |
echo "### Changed files" >> "$GITHUB_STEP_SUMMARY"
git --no-pager show --name-only --pretty="" "${{ github.sha }}" >> "$GITHUB_STEP_SUMMARY" || git ls-files | sed -n '1,200p' >> "$GITHUB_STEP_SUMMARY"
- name: Fail early if DEPLOY_WIKI_TOKEN is missing
env:
DEPLOY_WIKI_TOKEN: ${{ secrets.DEPLOY_WIKI_TOKEN }}
run: |
if [ -z "$DEPLOY_WIKI_TOKEN" ]; then
echo "ERROR: DEPLOY_WIKI_TOKEN is not set; the workflow will not be able to push to the wiki."
echo "Create a repository secret named DEPLOY_WIKI_TOKEN containing a PAT with 'Contents: write' or use GITHUB_TOKEN with write permissions."
exit 1
fi
- name: Echo docs trigger
run: echo "Update GitHub Wiki workflow triggered for docs/wiki changes"
- name: Select token
id: select_token
run: |
if [ -n "${{ secrets.DEPLOY_WIKI_TOKEN }}" ]; then
echo "token=${{ secrets.DEPLOY_WIKI_TOKEN }}" >> "$GITHUB_OUTPUT"
echo "source=DEPLOY_WIKI_TOKEN" >> "$GITHUB_OUTPUT"
else
echo "token=${{ secrets.GITHUB_TOKEN }}" >> "$GITHUB_OUTPUT"
echo "source=GITHUB_TOKEN" >> "$GITHUB_OUTPUT"
fi
echo "Using token from: ${{ steps.select_token.outputs.source }}"
- name: Publish docs/wiki to GitHub Wiki
env:
GITHUB_TOKEN: ${{ steps.select_token.outputs.token }}
REPO: ${{ github.repository }}
run: |
set -e
if [ ! -d docs/wiki ]; then
echo "docs/wiki not found"; exit 0
fi
TMP_DIR="$(mktemp -d)"
WIKI_URL="https://x-access-token:${GITHUB_TOKEN}@github.com/${REPO}.wiki.git"
echo "Cloning wiki repo"
git clone "$WIKI_URL" "$TMP_DIR"
echo "Cleaning wiki repo (preserving .git)"
find "$TMP_DIR" -mindepth 1 -maxdepth 1 ! -name '.git' -exec rm -rf {} +
echo "Copying markdown from docs/wiki"
rsync -a --prune-empty-dirs --include='*/' --include='*.md' --exclude='*' docs/wiki/ "$TMP_DIR"/
cd "$TMP_DIR"
git config user.name "${GITHUB_ACTOR:-github-actions}"
git config user.email "${GITHUB_ACTOR:-github-actions}@users.noreply.github.com"
if [ -n "$(git status --porcelain)" ]; then
git add -A
git commit -m "Publish docs/wiki to GitHub Wiki"
git push origin HEAD:master || git push origin HEAD:main || git push
echo "Published changes to GitHub Wiki"
else
echo "No changes to publish."
fi
- name: Comment on PR with changed docs files
if: github.event_name == 'pull_request' && steps.docs_files.outputs.docs_files != '[]'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCS_FILES: ${{ steps.docs_files.outputs.docs_files }}
run: |
# Extract PR number and head SHA from the event payload at runtime
pr_number=$(jq -r '.pull_request.number // empty' "$GITHUB_EVENT_PATH")
head_sha=$(jq -r '.pull_request.head.sha // empty' "$GITHUB_EVENT_PATH")
if [ -z "$pr_number" ] || [ -z "$head_sha" ]; then
echo "No PR number or head SHA found in event payload; skipping comment."
exit 0
fi
owner=$(echo "$GITHUB_REPOSITORY" | cut -d'/' -f1)
repo=$(echo "$GITHUB_REPOSITORY" | cut -d'/' -f2)
files_json="$DOCS_FILES"
body="### Docs files changed\n\n"
# Build markdown links that point to the file at the PR head SHA
body+=$(echo "$files_json" | jq -r --arg repo "$owner/$repo" --arg sha "$head_sha" '.[] | "- [\(. )](https://github.com/" + $repo + "/blob/" + $sha + "/" + .)')
payload=$(jq -n --arg body "$body" '{body: $body}')
curl -s -S -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github+json" \
-d "$payload" "https://api.github.com/repos/$owner/$repo/issues/$pr_number/comments"
- name: Post final publish comment
env:
GITHUB_TOKEN: ${{ steps.select_token.outputs.token }}
DOCS_FILES: ${{ steps.docs_files.outputs.docs_files }}
run: |
owner=$(echo "$GITHUB_REPOSITORY" | cut -d'/' -f1)
repo=$(echo "$GITHUB_REPOSITORY" | cut -d'/' -f2)
run_url="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"
timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
message="### Docs published to GitHub Wiki\n\nhttps://github.com/$owner/$repo/wiki\n\nPublished at: $timestamp\nRun: $run_url"
pr_number=$(jq -r '.pull_request.number // empty' "$GITHUB_EVENT_PATH")
if [ -n "$pr_number" ]; then
payload=$(jq -n --arg body "$message" '{body: $body}')
curl -s -S -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github+json" \
-d "$payload" "https://api.github.com/repos/$owner/$repo/issues/$pr_number/comments"
else
echo "$message"
fi