-
Notifications
You must be signed in to change notification settings - Fork 11
106 lines (89 loc) · 3.68 KB
/
build-docs.yml
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
95
96
97
98
99
100
101
102
103
104
105
106
name: Build and Deploy Docs
on:
push:
branches:
- main
- 'v*' # To trigger for any version branches (e.g., v1.0.0)
tags:
- 'v*' # To trigger for any version tags (e.g., v1.0.0)
jobs:
build-deploy-docs:
runs-on: ubuntu-latest
steps:
- name: Checkout Product Repo
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set Variables Based on Branch or Tag
id: vars
run: |
CURRENT_REF=${GITHUB_REF##*/}
# Check if the trigger is a tag or a branch
if [[ "$CURRENT_REF" == "main" ]]; then
echo "VERSION=latest" >> $GITHUB_ENV
echo "BRANCH=main" >> $GITHUB_ENV
echo "VERSIONS=latest,`git branch -r --list "origin/v*" | sed 's|origin/||' | sort -Vr | tr '\n' ',' | sed 's/,$//'`" >> $GITHUB_ENV
elif [[ "$CURRENT_REF" =~ ^v.* ]]; then
echo "VERSION=$CURRENT_REF" >> $GITHUB_ENV
echo "BRANCH=$CURRENT_REF" >> $GITHUB_ENV
echo "VERSIONS=latest,`git branch -r --list "origin/v*" | sed 's|origin/||' | sort -Vr | tr '\n' ',' | sed 's/,$//'`" >> $GITHUB_ENV
else
echo "Skipping docs build, branch/tag doesn't match versioning pattern."
exit 0
fi
- name: Install Hugo
run: |
wget https://github.com/gohugoio/hugo/releases/download/v0.79.1/hugo_extended_0.79.1_Linux-64bit.tar.gz
tar -xzvf hugo_extended_0.79.1_Linux-64bit.tar.gz
sudo mv hugo /usr/local/bin/
- name: Prepare Config File
run: make config
- name: Checkout Docs Repo
uses: actions/checkout@v2
with:
repository: infinilabs/docs
path: docs-output
token: ${{ secrets.DOCS_DEPLOYMENT_TOKEN }}
- name: Build Documentation
run: |
OUTPUT=$(pwd)/docs-output make build
- name: Commit and Push Changes
working-directory: docs-output
run: |
git config user.name "GitHub Actions"
git config user.email "[email protected]"
if [[ -n $(git status --porcelain) ]]; then
git add .
git commit -m "$(git log -1 --pretty=%B)"
git push origin main
else
echo "No changes to commit."
fi
- name: Rebuild Docs for Latest Version (main), if not already on main
run: |
# Only rebuild the main branch docs if the current ref is not "main"
if [[ "$CURRENT_REF" != "main" ]]; then
echo "Switching to main branch and rebuilding docs for 'latest'"
# Checkout the main branch of the product repo to rebuild docs for "latest"
git checkout main
# Ensure the latest changes are pulled
git pull origin main
# Prepare Config for Main Branch Docs
make config
# Build Docs for Main Branch (latest)
OUTPUT=$(pwd)/docs-output make build
# Now handle the docs repository (docs-output), commit and push changes there
cd docs-output # Switch to the docs-output directory (docs repo)
git config user.name "GitHub Actions"
git config user.email "[email protected]"
if [[ -n $(git status --porcelain) ]]; then
git add .
git commit -m "Rebuild docs for main branch with latest version"
git push origin main
else
echo "No changes to commit for docs."
fi
else
echo "Current ref is 'main', skipping rebuild for 'latest'."
fi
working-directory: ./ # Working in the product repo, no commit here