Skip to content
Merged
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
33 changes: 16 additions & 17 deletions .github/workflows/update-wiki.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,12 @@ on:
branches:
- main
paths:
- 'docs/**'
pull_request:
types: [closed]
paths:
- 'docs/**'
# Allow manual runs for diagnostics and one-off pushes
workflow_dispatch: {}
- docs/**

permissions:
contents: write
workflow_dispatch: {}

jobs:
update-wiki:
# Only run for push events, or for pull_request closed events where the PR was merged.
if: ${{ github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.merged == true) }}
runs-on: ubuntu-latest
steps:
- name: Debug: print event info
Expand Down Expand Up @@ -49,18 +40,26 @@ jobs:
with:
fetch-depth: 0

- name: Echo docs trigger
run: echo "Update Wiki workflow triggered for docs changes"

- 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 "WARNING: DEPLOY_WIKI_TOKEN is not set; the workflow will not be able to push to the wiki."
echo "Set the DEPLOY_WIKI_TOKEN secret or provide GITHUB_TOKEN permissions."
exit 1
fi

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'

- name: Install dependencies (if any)
run: |
if [ -f package.json ]; then npm ci; fi

- name: Run wiki init and push
env:
# Use a deploy PAT stored in repository secrets (create secret DEPLOY_WIKI_TOKEN)
GITHUB_TOKEN: ${{ secrets.DEPLOY_WIKI_TOKEN }}
run: |
node scripts/init-wiki.js --docs docs/wiki
node scripts/init-wiki.js --docs docs
Empty file added .gitignore
Empty file.
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "coderoot-ai",
"version": "0.0.0",
"description": "CodeRoot.ai repository",
"type": "module",
"license": "SEE LICENSE IN LICENSE.md",
"scripts": {
"init-wiki:dry": "node scripts/init-wiki.js --dry-run"
}
}
16 changes: 15 additions & 1 deletion scripts/init-wiki.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,21 @@ async function main() {
console.log('Remote:', opts.remote);
if (opts.dryRun) console.log('Dry run: no git clone/commit/push will be executed');

const isCI = process.env.GITHUB_ACTIONS === 'true' || process.env.CI === 'true';

// If running in CI, ensure we have a token to authenticate pushes. Prefer DEPLOY_WIKI_TOKEN but fall back to GITHUB_TOKEN.
if (isCI && !opts.dryRun) {
if (!process.env.DEPLOY_WIKI_TOKEN && !process.env.GITHUB_TOKEN) {
console.error('ERROR: No authentication token available in CI.');
console.error('Set repository secret DEPLOY_WIKI_TOKEN (a PAT with Contents: write) or ensure GITHUB_TOKEN is available.');
process.exit(20);
}
// If DEPLOY_WIKI_TOKEN is provided, prefer it by setting GITHUB_TOKEN for downstream code that reads it.
if (process.env.DEPLOY_WIKI_TOKEN) {
process.env.GITHUB_TOKEN = process.env.DEPLOY_WIKI_TOKEN;
}
}

if (!fs.existsSync(docsDir)) {
console.error('Docs wiki folder not found at', docsDir);
process.exitCode = 2;
Expand All @@ -105,7 +120,6 @@ async function main() {
}

// If running in CI with a GITHUB_TOKEN available, inject it into an https wiki URL so git can authenticate.
const isCI = process.env.GITHUB_ACTIONS === 'true' || process.env.CI === 'true';
let maskedWikiUrl = wikiUrl;
if (wikiUrl && isCI && process.env.GITHUB_TOKEN) {
try {
Expand Down