Skip to content

Improve CI/CD for documentation website (#390) #137

Improve CI/CD for documentation website (#390)

Improve CI/CD for documentation website (#390) #137

name: Deploy website to Pages
on:
push:
paths:
- 'docs/**'
pull_request:
paths:
- 'docs/**'
workflow_dispatch: # Allows you to run this workflow manually from the Actions tab
permissions: # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
contents: read
pages: write
id-token: write
defaults: # Default to bash
run:
shell: bash
jobs:
build:
runs-on: ubuntu-latest
outputs:
has_pages: ${{ steps.has-pages.outputs.has_pages }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # Number of commits to fetch. 0 indicates all history for all branches and tags.
- name: Get Consul.NET latest version
id: version
uses: WyriHaximus/github-action-get-previous-tag@v1
with:
fallback: "vX.X.X.X" # Optional fallback tag to use when no tag can be found
- name: Set 'has_pages' to output
id: has-pages
run: echo "has_pages=$(gh api repos/${{ github.repository }} --jq .has_pages)" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Extract URL and BASE_URL
run: |
if [[ "${{ github.repository_owner }}" == "G-Research" ]]; then
echo "URL=https://consuldot.net" >> $GITHUB_ENV
echo "BASE_URL=/" >> $GITHUB_ENV
else
echo "URL=https://${{ github.repository_owner }}.github.io" >> $GITHUB_ENV
echo "BASE_URL=/${{ github.event.repository.name }}/" >> $GITHUB_ENV
fi
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "lts/*"
cache: yarn
cache-dependency-path: docs/yarn.lock
- name: Setup Pages
id: pages
uses: actions/configure-pages@v5
if: github.ref == 'refs/heads/master' && steps.has-pages.outputs.has_pages == 'true'
- name: Restore cache
uses: actions/cache@v4
with:
path: |
docs/build
docs/.docusaurus
key: ${{ runner.os }}-docusaurus-build-${{ hashFiles('docs/build') }}
restore-keys: |
${{ runner.os }}-docusaurus-build-
- name: Install dependencies
run: yarn install
working-directory: ./docs
- name: Build
run: yarn run build
working-directory: ./docs
env:
CONSUL_DOT_NET_VERSION: ${{ steps.version.outputs.tag }}
URL: ${{ env.URL }}
BASE_URL: ${{ env.BASE_URL }}
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
if: github.ref == 'refs/heads/master' && steps.has-pages.outputs.has_pages == 'true'
with:
path: ./docs/build
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
if: github.ref == 'refs/heads/master' && needs.build.outputs.has_pages == 'true'
concurrency: # Allow one concurrent deployment
group: "pages"
cancel-in-progress: true
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4