Build docs #2416
This file contains hidden or 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
# 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: | |
jobs: | |
build: | |
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' }} | |
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@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 | |
with: | |
submodules: recursive | |
lfs: true | |
fetch-depth: 1 | |
- 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@bd6b4b6205c4dbad673328db7b31b7fab9e241c0 # v4.6.1 | |
with: | |
python-version: '3.9' | |
- name: ❤️ Install Node 16 | |
uses: actions/[email protected] # v3.3.0 | |
with: | |
node-version: 16 | |
- name: 📚 Install Hugo | |
uses: peaceiris/[email protected] # v2.4.13 | |
with: | |
hugo-version: '0.91.2' | |
extended: true | |
- 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/pre-commit | |
sudo chmod -R 777 /mnt/airflow-site/.cache/pre-commit | |
- name: 🔎 Lint | |
run: | | |
uv tool install pre-commit --with pre-commit-uv | |
pre-commit run --all-files --color always | |
- name: 🗂 Checkout ${{ env.PUBLISH_BRANCH }} branch with minimum depth | |
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # 3.5.3 | |
with: | |
ref: ${{ env.PUBLISH_BRANCH }} | |
fetch-depth: 1 | |
path: dist | |
- name: 🔧 Build site | |
run: | | |
/mnt/airflow-site/site.sh build-site | |
- 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@010d0da01d0b5a38af31e9c3470dbfdabdecca3a # v4.0.1 | |
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@v4 | |
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: 🔄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 | |
run: | | |
set -x | |
echo "Running git config" | |
git config user.name "GitHub Actions" | |
git config user.email "[email protected]" | |
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 ${{ env.PUBLISH_BRANCH }} branch" | |
git push origin ${{ env.PUBLISH_BRANCH }} | |
- name: 🔧 Copy files from site to theme | |
run: | | |
./site.sh prepare-theme | |
- name: 🔧 Prepare sphinx_airflow_theme package ️ | |
working-directory: sphinx_airflow_theme | |
run: | | |
uv build | |
- name: 🚀 Upload sphinx_airflow_theme package as artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: airflow-sphinx-theme | |
path: './sphinx_airflow_theme/dist' | |
if-no-files-found: error | |
retention-days: 14 | |
- name: 🔧 Build theme demo | |
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 | |
uses: actions/upload-artifact@v4 | |
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: 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/* |