forked from cisco-en-programmability/catalystcenter-ansible
-
Notifications
You must be signed in to change notification settings - Fork 0
94 lines (76 loc) · 2.92 KB
/
Copy pathdocs.yml
File metadata and controls
94 lines (76 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
---
name: docs
on:
push:
tags:
- ^v[0-9]+\.[0-9]+\.[0-9]+$
branches:
- main
env:
KEEP_VERSIONS: 15
jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Configure git
run: |
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@bots.github.com"
git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/*
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.8"
cache: pip
- name: Install dependencies
run: |
pip install antsibull-docs
make doc-setup
- name: Build docs
run: make doc
- name: Commit docs
run: |
VERSION=$(basename "${GITHUB_REF}")
# Checkout gh-pages branch (create orphan if doesn't exist)
git checkout gh-pages || git checkout --orphan gh-pages
# Remove existing version/branch folder to ensure clean state
if [ -d "$VERSION" ]; then
echo "Removing existing '$VERSION' folder..."
rm -rf "$VERSION"
fi
# Move new docs
mv docs/_build/html "$VERSION"
# Clean old versions (keep last N), excluding current version
echo "Cleaning old documentation versions (keeping last ${{ env.KEEP_VERSIONS }})..."
versions_to_delete=$(find . -maxdepth 1 -type d -name 'v*' -printf '%f\n' 2>/dev/null \
| grep -v "^${VERSION}$" \
| sort --version-sort --reverse \
| tail -n +${{ env.KEEP_VERSIONS }})
if [ -n "$versions_to_delete" ]; then
echo "Removing old versions:"
echo "$versions_to_delete"
echo "$versions_to_delete" | xargs -r rm -rf
else
echo "No old versions to remove"
fi
echo "Remaining versions:"
find . -maxdepth 1 -type d -name 'v*' -printf '%f\n' 2>/dev/null \
| sort --version-sort --reverse || echo "No version folders"
# Rebuild index with remaining versions
git show origin/main:docs/_gh_include/header.inc > index.html
(echo main; find . -maxdepth 1 -type d -name 'v*' -printf '%f\n' 2>/dev/null \
| sort --version-sort --reverse) \
| xargs -I@@ \
-n1 echo '<div class="col-md-4 center"><a href="@@/" class="btn-doc btn"><i class="fa fa-newspaper-o"></i><p>@@</p></a></div>' >> index.html
git show origin/main:docs/_gh_include/footer.inc >> index.html
# Stage all changes (including deletions)
git add -A
# Commit only if there are changes
if ! git diff --cached --quiet; then
git commit -m "update docs for ${VERSION}"
else
echo "No documentation changes to commit"
fi
- name: Push docs
run: git push origin gh-pages