build: update to support tags #10
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |