|
| 1 | +name: Sync Markdown to Site Branch |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: write |
| 11 | + actions: write |
| 12 | + |
| 13 | +jobs: |
| 14 | + sync: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - name: Checkout master branch |
| 18 | + uses: actions/checkout@v4 |
| 19 | + with: |
| 20 | + ref: master |
| 21 | + fetch-depth: 0 |
| 22 | + |
| 23 | + - name: Set up Python |
| 24 | + uses: actions/setup-python@v5 |
| 25 | + with: |
| 26 | + python-version: '3.x' |
| 27 | + |
| 28 | + - name: Configure Git |
| 29 | + run: | |
| 30 | + git config user.name "github-actions[bot]" |
| 31 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 32 | +
|
| 33 | + - name: Sync markdown files to site branch |
| 34 | + run: | |
| 35 | + # Fetch all branches |
| 36 | + git fetch origin |
| 37 | +
|
| 38 | + # Check if site branch exists |
| 39 | + if git show-ref --verify --quiet refs/remotes/origin/site; then |
| 40 | + git checkout site |
| 41 | + git pull origin site |
| 42 | + else |
| 43 | + echo "Error: site branch does not exist. Please create it first." |
| 44 | + exit 1 |
| 45 | + fi |
| 46 | +
|
| 47 | + mkdir -p docs/specs |
| 48 | +
|
| 49 | + # Get the conversion script from site branch |
| 50 | + CONVERT_SCRIPT="scripts/convert_admonitions.py" |
| 51 | +
|
| 52 | + # Sync README.md from master root -> docs/index.md |
| 53 | + # Convert GitHub markdown to MkDocs format (links + admonitions) |
| 54 | + git show master:README.md | sed \ |
| 55 | + -e 's|\[Mechanical Specs\](mechanical/)|[Mechanical Specs](specs/mechanical.md)|g' \ |
| 56 | + -e 's|\[Electrical Specs\](electrical/)|[Electrical Specs](specs/electrical.md)|g' \ |
| 57 | + | python3 "$CONVERT_SCRIPT" > docs/index.md |
| 58 | +
|
| 59 | + # Sync LICENSE.md from master root -> docs/LICENSE.md |
| 60 | + git show master:LICENSE.md > docs/LICENSE.md 2>/dev/null || true |
| 61 | +
|
| 62 | + # Sync mechanical/README.md -> docs/specs/mechanical.md |
| 63 | + # Convert GitHub markdown links and admonitions to MkDocs format |
| 64 | + git show master:mechanical/README.md 2>/dev/null | sed \ |
| 65 | + -e 's|\[Electrical\](../electrical/)|[Electrical](electrical.md)|g' \ |
| 66 | + | python3 "$CONVERT_SCRIPT" > docs/specs/mechanical.md || true |
| 67 | +
|
| 68 | + # Sync electrical/README.md -> docs/specs/electrical.md |
| 69 | + # Convert GitHub markdown links and admonitions to MkDocs format |
| 70 | + git show master:electrical/README.md 2>/dev/null | sed \ |
| 71 | + -e 's|\[Mechanical\](../mechanical/)|[Mechanical](mechanical.md)|g' \ |
| 72 | + | python3 "$CONVERT_SCRIPT" > docs/specs/electrical.md || true |
| 73 | +
|
| 74 | + # Sync images from mechanical/ and electrical/ -> docs/specs/ |
| 75 | + for ext in png jpg jpeg gif svg webp; do |
| 76 | + for file in $(git ls-tree --name-only master:mechanical/ 2>/dev/null | grep -E "\.$ext$" || true); do |
| 77 | + git show "master:mechanical/$file" > "docs/specs/$file" |
| 78 | + done |
| 79 | + for file in $(git ls-tree --name-only master:electrical/ 2>/dev/null | grep -E "\.$ext$" || true); do |
| 80 | + git show "master:electrical/$file" > "docs/specs/$file" |
| 81 | + done |
| 82 | + done |
| 83 | +
|
| 84 | + # Stage all changes |
| 85 | + git add -A |
| 86 | +
|
| 87 | + # Commit and push if there are changes |
| 88 | + if git diff --staged --quiet; then |
| 89 | + echo "No changes to commit" |
| 90 | + echo "CHANGES_MADE=false" >> $GITHUB_ENV |
| 91 | + else |
| 92 | + git commit -m "Sync markdown files from master" |
| 93 | + git push origin site |
| 94 | + echo "CHANGES_MADE=true" >> $GITHUB_ENV |
| 95 | + fi |
| 96 | +
|
| 97 | + - name: Trigger deploy workflow |
| 98 | + if: env.CHANGES_MADE == 'true' |
| 99 | + run: | |
| 100 | + gh workflow run deploy.yml --ref site |
| 101 | + env: |
| 102 | + GH_TOKEN: ${{ github.token }} |
0 commit comments