website: add "API Reference" generation #144
Workflow file for this run
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: Deploy website to Pages | |
on: | |
push: | |
paths: | |
- 'docs/**' | |
- 'Consul/**' | |
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: Setup .NET | |
uses: actions/setup-dotnet@v4 | |
with: | |
cache: true | |
- name: Restore tool | |
run: dotnet tool restore | |
- name: Generate API reference using DocFX | |
run: yarn run api:generate | |
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: Add build identifier | |
run: echo "${{ github.sha }}" > build/.build | |
working-directory: ./docs | |
if: github.ref == 'refs/heads/master' && steps.has-pages.outputs.has_pages == 'true' | |
- 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 | |
- name: Check Algolia secrets availability | |
run: | | |
if [ -n "${{ secrets.ALGOLIA_APP_ID }}" ] && [ -n "${{ secrets.ALGOLIA_API_KEY }}" ] && [ -n "${{ secrets.CRAWLER_USER_ID }}" ] && [ -n "${{ secrets.CRAWLER_API_KEY }}" ]; then | |
echo "ALGOLIA_SECRETS=true" >> $GITHUB_ENV | |
else | |
echo "ALGOLIA_SECRETS=false" >> $GITHUB_ENV | |
fi | |
- name: Wait for new version to be published | |
id: wait-for-new-version | |
if: ${{ env.ALGOLIA_SECRETS == 'true' }} | |
continue-on-error: true # Allows this step to fail without failing the job | |
run: | | |
max_retries=5 | |
new_version="${{ github.sha }}" | |
for i in $(seq 1 $max_retries); do | |
published_version=$(curl -s -f ${{ steps.deployment.outputs.page_url }}.build) | |
if [ "$published_version" == "$new_version" ]; then | |
echo "New version published!" | |
exit 0 | |
else | |
sleep_time=$((2**$i)) # exponential backoff | |
echo "Waiting for new version to be published for $sleep_time seconds ..." | |
sleep $sleep_time | |
fi | |
done | |
echo "New version not published after $max_retries attempts!" | |
exit 1 | |
- name: Trigger Algolia DocSearch Crawler | |
uses: algolia/algoliasearch-crawler-github-actions@v1 | |
if: ${{ steps.wait-for-new-version.outcome == 'success' }} # Only if the new version was successfully published | |
continue-on-error: true # Allows this step to fail without failing the job | |
with: | |
algolia-app-id: ${{ secrets.ALGOLIA_APP_ID }} # required | |
algolia-api-key: ${{ secrets.ALGOLIA_API_KEY }} # required | |
crawler-user-id: ${{ secrets.CRAWLER_USER_ID }} # required | |
crawler-api-key: ${{ secrets.CRAWLER_API_KEY }} # required | |
crawler-name: consuldot | |
override-config: false | |
site-url: 'https://consuldot.net' |