Skip to content

Commit f59fc6b

Browse files
authored
chore: update github action and pull request template (#2)
1 parent c1e7389 commit f59fc6b

File tree

2 files changed

+131
-0
lines changed

2 files changed

+131
-0
lines changed

.github/PULL_REQUEST_TEMPLATE.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
## What does this PR do
2+
3+
## Rationale for this change
4+
5+
## Standards checklist
6+
7+
- [ ] The PR title is descriptive
8+
- [ ] The commit messages are [semantic](https://www.conventionalcommits.org/)
9+
- [ ] Necessary tests are added
10+
- [ ] Updated the release notes
11+
- [ ] Necessary documents have been added if this is a new feature
12+
- [ ] Performance tests checked, no obvious performance degradation

.github/workflows/build-docs.yml

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
name: Build and Deploy Docs
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- 'v*'
8+
tags:
9+
- 'v*'
10+
11+
jobs:
12+
build-deploy-docs:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout Product Repo
17+
uses: actions/checkout@v2
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Set Variables Based on Ref
22+
id: vars
23+
run: |
24+
PRODUCT_NAME=$(basename $(pwd)) # Get the directory name as the product name
25+
echo "PRODUCT_NAME=$PRODUCT_NAME" >> $GITHUB_ENV
26+
CURRENT_REF=${GITHUB_REF##*/}
27+
IS_SEMVER=false
28+
SEMVER_REGEX="^v([0-9]+)\.([0-9]+)\.([0-9]+)$"
29+
30+
if [[ "${GITHUB_REF_TYPE}" == "branch" ]]; then
31+
if [[ "$CURRENT_REF" == "main" ]]; then
32+
echo "VERSION=main" >> $GITHUB_ENV
33+
echo "BRANCH=main" >> $GITHUB_ENV
34+
elif [[ "$CURRENT_REF" =~ $SEMVER_REGEX ]]; then
35+
IS_SEMVER=true
36+
echo "VERSION=$CURRENT_REF" >> $GITHUB_ENV
37+
echo "BRANCH=$CURRENT_REF" >> $GITHUB_ENV
38+
else
39+
echo "Branch '$CURRENT_REF' is not a valid semantic version. Skipping build."
40+
exit 0
41+
fi
42+
elif [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
43+
if [[ "$CURRENT_REF" =~ $SEMVER_REGEX ]]; then
44+
IS_SEMVER=true
45+
echo "VERSION=$CURRENT_REF" >> $GITHUB_ENV
46+
echo "BRANCH=main" >> $GITHUB_ENV # Set BRANCH to 'main' for tags
47+
else
48+
echo "Tag '$CURRENT_REF' is not a valid semantic version. Skipping build."
49+
exit 0
50+
fi
51+
fi
52+
53+
# Gather branches and tags, filter for semantic versions, sort, remove duplicates
54+
VERSIONS=$(git for-each-ref refs/remotes/origin refs/tags --format="%(refname:short)" | \
55+
grep -E "^v[0-9]+\.[0-9]+\.[0-9]+$" | sort -Vr | uniq | tr '\n' ',' | sed 's/,$//')
56+
echo "VERSIONS=main,$VERSIONS" >> $GITHUB_ENV
57+
58+
- name: Install Hugo
59+
run: |
60+
wget https://github.com/gohugoio/hugo/releases/download/v0.79.1/hugo_extended_0.79.1_Linux-64bit.tar.gz
61+
tar -xzvf hugo_extended_0.79.1_Linux-64bit.tar.gz
62+
sudo mv hugo /usr/local/bin/
63+
64+
- name: Checkout Docs Repo
65+
uses: actions/checkout@v2
66+
with:
67+
repository: infinilabs/docs
68+
path: docs-output
69+
token: ${{ secrets.DOCS_DEPLOYMENT_TOKEN }}
70+
71+
- name: Build Documentation
72+
run: |
73+
(cd docs && OUTPUT=$(pwd)/../docs-output make docs-build docs-place-redirect)
74+
75+
- name: Commit and Push Changes to Docs Repo
76+
working-directory: docs-output
77+
run: |
78+
git config user.name "GitHub Actions"
79+
git config user.email "[email protected]"
80+
81+
if [[ -n $(git status --porcelain) ]]; then
82+
git add .
83+
git commit -m "Rebuild $PRODUCT_NAME docs for version $VERSION"
84+
git push origin main
85+
else
86+
echo "No changes to commit."
87+
fi
88+
89+
- name: Rebuild Docs for Latest Version (main), if not already on main
90+
run: |
91+
# Only rebuild the main branch docs if the current ref is not "main"
92+
if [[ "$CURRENT_REF" != "main" ]]; then
93+
echo "Switching to main branch and rebuilding docs for 'latest'"
94+
95+
# Checkout the main branch of the product repo to rebuild docs for "latest"
96+
git checkout main
97+
98+
# Ensure the latest changes are pulled
99+
git pull origin main
100+
101+
# Build Docs for Main Branch (latest)
102+
(cd docs && OUTPUT=$(pwd)/../docs-output VERSION="main" BRANCH="main" make docs-build docs-place-redirect)
103+
104+
# Commit and Push Latest Docs to Main
105+
cd docs-output
106+
git config user.name "GitHub Actions"
107+
git config user.email "[email protected]"
108+
109+
if [[ -n $(git status --porcelain) ]]; then
110+
git add .
111+
git commit -m "Rebuild $PRODUCT_NAME docs for main branch with latest version"
112+
git push origin main
113+
else
114+
echo "No changes to commit for main."
115+
fi
116+
else
117+
echo "Current ref is 'main', skipping rebuild for 'latest'."
118+
fi
119+
working-directory: ./ # Working in the product repo

0 commit comments

Comments
 (0)