Skip to content

Merge pull request #21 from GitbookIO/fix/gitbook-docs-yaml-and-publi… #5

Merge pull request #21 from GitbookIO/fix/gitbook-docs-yaml-and-publi…

Merge pull request #21 from GitbookIO/fix/gitbook-docs-yaml-and-publi… #5

Workflow file for this run

name: Publish combined skill to public-docs
on:
push:
branches: [main]
paths:
- "skills/**"
- "scripts/build-skill.js"
permissions:
contents: read
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout gitbook-skills
uses: actions/checkout@v4
- name: Build gitbook skill
run: node scripts/build-skill.js
- name: Checkout public-docs
uses: actions/checkout@v4
with:
repository: GitbookIO/public-docs
token: ${{ secrets.PUBLIC_DOCS_PAT }}
path: public-docs
fetch-depth: 0
- name: Sync branch and apply changes
id: sync
working-directory: public-docs
env:
GITHUB_SHA: ${{ github.sha }}
run: |
set -euo pipefail
git config user.name "gitbook-skills-bot"
git config user.email "actions@github.com"
git fetch origin main
git checkout -B sync/gitbook-skill origin/main
rm -rf documentation/skill
mkdir -p documentation/skill
cp ../dist/skill.md documentation/skill/README.md
cp ../dist/skill/*.md documentation/skill/
cp ../dist/skill-manifest.json documentation/skill-manifest.json
(cd documentation && node ../../scripts/update-summary.js)
rm -f documentation/skill-manifest.json
git add documentation/skill/ documentation/SUMMARY.md
if git diff --cached --quiet; then
echo "No changes to publish"
echo "changed=false" >> "$GITHUB_OUTPUT"
exit 0
fi
git commit -m "Sync gitbook skill.md from gitbook-skills@${GITHUB_SHA:0:7}"
git push --force origin sync/gitbook-skill
echo "changed=true" >> "$GITHUB_OUTPUT"
- name: Open PR if needed
if: steps.sync.outputs.changed == 'true'
working-directory: public-docs
env:
GH_TOKEN: ${{ secrets.PUBLIC_DOCS_PAT }}
GITHUB_SHA: ${{ github.sha }}
run: |
set -uo pipefail
output=$(gh pr create --repo GitbookIO/public-docs \
--head sync/gitbook-skill \
--base main \
--title "Sync gitbook skill.md from gitbook-skills" \
--body "Auto-generated from https://github.com/GitbookIO/gitbook-skills/commit/${GITHUB_SHA}. This PR is kept up to date automatically — new merges to gitbook-skills main will overwrite it until it's merged." 2>&1)
status=$?
echo "$output"
if [ "$status" -ne 0 ]; then
if echo "$output" | grep -qi "already exists"; then
echo "PR already open on sync/gitbook-skill, updated in place by the force-push above"
else
exit "$status"
fi
fi