-
Notifications
You must be signed in to change notification settings - Fork 87
165 lines (144 loc) · 5.56 KB
/
deploy-website.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
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
- 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'