-
Notifications
You must be signed in to change notification settings - Fork 426
280 lines (277 loc) Β· 13 KB
/
build.yml
File metadata and controls
280 lines (277 loc) Β· 13 KB
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
name: Build docs
on:
push:
branches: ['main', 'staging']
pull_request:
workflow_dispatch:
permissions:
contents: write
concurrency:
group: build-${{ github.ref }}
cancel-in-progress: true
jobs:
build: # zizmor: ignore[secrets-outside-env]
runs-on: ["ubuntu-22.04"]
env:
PROD_PUBLISH_REQUIRED: ${{ (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.ref == 'refs/heads/main' || 'false' }}
STAGING_PUBLISH_REQUIRED: ${{ (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.ref == 'refs/heads/staging' || 'false' }}
PUBLISH_BRANCH: ${{ github.ref == 'refs/heads/main' && 'publish' || 'staging-publish' }}
CLOUDFRONT_DISTRIBUTION_ID: ${{ github.ref == 'refs/heads/main' && 'E26P75MP9PMULE' || 'E197MS0XRJC5F3' }}
S3_DOCS_BUCKET: ${{ github.ref == 'refs/heads/main' && 'live-docs-airflow-apache-org' || 'staging-docs-airflow-apache-org' }}
steps:
- name: βΉοΈ Info
run: |
echo "PROD_PUBLISH_REQUIRED: ${PROD_PUBLISH_REQUIRED}"
echo "STAGING_PUBLISH_REQUIRED: ${STAGING_PUBLISH_REQUIRED}"
# Based on https://github.com/actions/runner-images/issues/2840
- name: πͺ Remove some stuff we don't need
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
- name: π’ Install stuff we need
run: |
type -p curl >/dev/null || (sudo apt update && sudo apt install curl -y)
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
&& sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
&& sudo apt update \
&& sudo apt install gh -y
- name: π Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
submodules: recursive
fetch-depth: 1
persist-credentials: false
- name: πCreate /mnt/airflow-site directory
run: sudo mkdir -p /mnt/airflow-site
- name: πMove repository to /mnt
run: |
sudo mv /home/runner/work/airflow-site/airflow-site /mnt/
# Create symbolic link
sudo mkdir -p /home/runner/work/airflow-site
sudo ln -s /mnt/airflow-site /home/runner/work/airflow-site/airflow-site
- name: πSet working directory to /mnt/airflow-site
working-directory: /mnt/airflow-site
run: echo "Working directory set to /mnt/airflow-site"
- name: π Setup Python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: '3.12'
- name: β€οΈ Install Node 22 LTS
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
with:
node-version: 22
- name: π Install Hugo
run: |
HUGO_VERSION="0.146.0"
curl -fsSL "https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.tar.gz" | sudo tar -xz -C /usr/local/bin hugo
- name: π¦ Install Docsy theme dependencies (Bootstrap & FontAwesome)
working-directory: /mnt/airflow-site/landing-pages/site/themes/docsy
run: npm install
- name: π’ Install node dependencies
run: |
/mnt/airflow-site/site.sh install-node-deps
- name: π Install uv
run: |
curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Ensure cache directory exists and adjust permissions
run: |
mkdir -p /mnt/airflow-site/.cache/prek
sudo chmod -R 777 /mnt/airflow-site/.cache/prek
- name: π Lint
run: |
uv tool install prek
prek run --all-files --color always
- name: π Checkout ${{ env.PUBLISH_BRANCH }} branch with minimum depth
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: ${{ env.PUBLISH_BRANCH }}
fetch-depth: 1
path: dist
set-safe-directory: 'true'
# We will push to the publish branch
persist-credentials: true
- name: π¦ Save previous sphinx_airflow_theme packages from publish branch
run: |
if [ -d dist/sphinx-airflow-theme ]; then
echo "Saving previous theme packages:"
ls -la dist/sphinx-airflow-theme/
cp -r dist/sphinx-airflow-theme /tmp/sphinx-airflow-theme-backup
else
echo "No previous theme packages found"
fi
- name: π§ Build site
run: |
/mnt/airflow-site/site.sh build-site
- name: π¦ Restore previous sphinx_airflow_theme packages
run: |
if [ -d /tmp/sphinx-airflow-theme-backup ]; then
mkdir -p dist/sphinx-airflow-theme
cp -r /tmp/sphinx-airflow-theme-backup/* dist/sphinx-airflow-theme/
echo "Restored previous theme packages:"
ls -la dist/sphinx-airflow-theme/
fi
- name: β Install AWS CLI v2
if: env.PROD_PUBLISH_REQUIRED != 'false' || env.STAGING_PUBLISH_REQUIRED != 'false'
run: |
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o /tmp/awscliv2.zip
unzip -q /tmp/awscliv2.zip -d /tmp
rm /tmp/awscliv2.zip
sudo /tmp/aws/install --update
rm -rf /tmp/aws/
- name: β Configure AWS credentials
if: env.PROD_PUBLISH_REQUIRED != 'false' || env.STAGING_PUBLISH_REQUIRED != 'false'
uses: aws-actions/configure-aws-credentials@8df5847569e6427dd6c4fb1cf565c83acfa8afa7 # v6.0.0
with:
aws-access-key-id: ${{ secrets.DOCS_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.DOCS_AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-2
- uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
name: π Upload website as artifact
if: ${{ github.event_name == 'pull_request' }}
with:
name: airflow-website
path: './dist'
if-no-files-found: error
retention-days: 7
- name: "π§ͺ Apply staging modifications: .htaccess and watermarks"
run: |
set -x
sed -i 's/d7fnmbhf26p21.cloudfront.net/d3a2du7x0n8ydr.cloudfront.net/' ./dist/.htaccess
echo "Updated ./dist/.htaccess"
cat ./dist/.htaccess
echo
uv run .github/scripts/add_watermark.py --pattern 'main*.css' \
--folder dist --image-directory images --url-prefix /images
if: github.ref == 'refs/heads/staging'
- name: π· Copy .asf.yaml to /dist/
if: env.PROD_PUBLISH_REQUIRED != 'false' || env.STAGING_PUBLISH_REQUIRED != 'false'
run: |
# The asf.yaml file must be in the branch from which the files are published.
# Otherwise, ASF publishing tools cannot detect it.
cp .asf.yaml ./dist/
- name: πͺ Remove node and node modules
run: |
rm -rf node_modules
sudo rm -rf "$AGENT_TOOLSDIRECTORY/node"
- name: π§ Copy files from site to theme
run: |
./site.sh prepare-theme
- name: π Check if sphinx_airflow_theme changed
id: check-theme
run: |
NEW_VERSION=$(cat sphinx_airflow_theme/LATEST_VERSION.txt | tr -d '[:space:]')
PUBLISHED_VERSION=""
if [ -f dist/sphinx-airflow-theme/LATEST_VERSION.txt ]; then
PUBLISHED_VERSION=$(cat dist/sphinx-airflow-theme/LATEST_VERSION.txt | tr -d '[:space:]')
fi
if [ "${NEW_VERSION}" != "${PUBLISHED_VERSION}" ]; then
echo "theme_changed=true" >> "${GITHUB_OUTPUT}"
echo "sphinx_airflow_theme version changed: ${PUBLISHED_VERSION} -> ${NEW_VERSION}"
else
echo "theme_changed=false" >> "${GITHUB_OUTPUT}"
echo "sphinx_airflow_theme version unchanged (${NEW_VERSION}), skipping theme upload"
fi
- name: π§ Prepare sphinx_airflow_theme package οΈ
if: steps.check-theme.outputs.theme_changed == 'true'
working-directory: sphinx_airflow_theme
run: |
uv build
- name: π¦ Copy sphinx_airflow_theme package to dist (preserving previous versions)
if: steps.check-theme.outputs.theme_changed == 'true'
run: |
mkdir -p dist/sphinx-airflow-theme
cp sphinx_airflow_theme/dist/* dist/sphinx-airflow-theme/
cp sphinx_airflow_theme/LATEST_VERSION.txt dist/sphinx-airflow-theme/
echo "All theme packages (including previous versions):"
ls -la dist/sphinx-airflow-theme/
- name: π Refresh PMC/COMMITTERS profiles
env:
PMC_COMMITTERS_FILES: landing-pages/site/data/committers.json,landing-pages/site/data/pmc.json
run: |
uv run ./.github/scripts/refresh_pmc_committer_images.py
- name: π Add commit to ${{ env.PUBLISH_BRANCH }} branch and deploy it
if: env.PROD_PUBLISH_REQUIRED != 'false' || env.STAGING_PUBLISH_REQUIRED != 'false'
working-directory: dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -x
echo "Running git config"
git config user.name "GitHub Actions"
git config user.email "[email protected]"
# actions/checkout@v6 stores credentials via includeIf gitdir conditions that
# break when the repo is symlinked to /mnt. Set the token explicitly.
git remote set-url origin "https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}.git"
echo "Running git add"
git add .
git diff HEAD
echo "Running git commit"
git commit --no-edit -m "Docs updated via ${GITHUB_REF}:${{ github.sha }}" --allow-empty
echo "Running git push to ${PUBLISH_BRANCH} branch"
git push origin ${PUBLISH_BRANCH}
- name: π Upload sphinx_airflow_theme package as artifact
if: steps.check-theme.outputs.theme_changed == 'true'
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
name: airflow-sphinx-theme
path: './sphinx_airflow_theme/dist'
if-no-files-found: error
retention-days: 14
- name: π§ Build theme demo
if: steps.check-theme.outputs.theme_changed == 'true'
working-directory: sphinx_airflow_theme
run: |
pip install ./dist/sphinx_airflow_theme-*.whl
cd demo
./docs.sh build
- name: π Upload sphinx_airflow_theme demo as artifact
if: steps.check-theme.outputs.theme_changed == 'true'
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
name: airflow-sphinx-theme-demo
path: './sphinx_airflow_theme/demo/_build'
if-no-files-found: error
retention-days: 14
- name: π Create releases on GitHub
working-directory: sphinx_airflow_theme
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_COMMIT: ${{ github.sha }}
GITHUB_REF: ${{ github.ref }}
if: steps.check-theme.outputs.theme_changed == 'true' && (env.PROD_PUBLISH_REQUIRED != 'false' || env.STAGING_PUBLISH_REQUIRED != 'false')
run: |
set -x
if [[ "${GITHUB_REF}" == "refs/heads/main" ]]; then
SUFFIX=""
else
SUFFIX="-staging"
fi
gh auth status
VERSION="$(cd sphinx_airflow_theme; uv run python -c 'import sphinx_airflow_theme; print(sphinx_airflow_theme.__version__)')"
TITLE=$(date "+%Y-%m-%d %H:%M:%S")
NOTES="Commit: ${GITHUB_COMMIT}
Source: ${GITHUB_REF}"
gh release delete "${VERSION}${SUFFIX}" -y || true
gh release create "${VERSION}${SUFFIX}" \
--title "${TITLE}" \
--notes "${NOTES}" \
./dist/*