Skip to content

MAJ du thème en 9.2 #73

MAJ du thème en 9.2

MAJ du thème en 9.2 #73

name: "Pull Request Checker 🛃"
# Inspired from: https://github.com/docker-mailserver/docker-mailserver/blob/main/.github/workflows/docs-preview-prepare.yml
on:
pull_request:
branches: [main]
# Environment variables
env:
BUILD_DIR: build/mkdocs/site
NETLIFY_SITE_NAME: geotribu-contribuer-preview
NETLIFY_SITE_PREFIX: preview-pullrequest-${{ github.event.pull_request.number }}
# If the workflow for a PR is triggered multiple times, previous existing runs will be canceled.
# eg: Applying multiple suggestions from a review directly via the Github UI.
# Instances of the 2nd phase of this workflow (via `workflow_run`) presently lack concurrency limits due to added complexity.
concurrency:
group: deploypreview-pullrequest-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
build:
name: "Check site build 📦"
runs-on: ubuntu-latest
if: ${{ github.repository_owner == 'geotribu' }}
steps:
- name: Get source code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.11
cache: "pip"
- name: Install dependencies
id: dependencies
env:
GH_TOKEN_MATERIAL_INSIDERS: ${{ secrets.GH_TOKEN_MATERIAL_INSIDERS }}
run: |
python -m pip install -U pip setuptools wheel
# if secret (PR created by repo collaborator) exists = paid features, else only free
if [[ -z "${GH_TOKEN_MATERIAL_INSIDERS}" ]]; then
echo "::warning:: L'accès aux token est réservé aux comptes avec droits d'écriture sur le dépôt. La version gratuite du thème est donc utilisée sans mots-clés, etc.)"
python -m pip install -U -r requirements-free.txt
echo "MKDOCS_CONFIG_FILENAME=mkdocs-free.yml" >> $GITHUB_ENV
else
# install insiders version using token
python -m pip install -U -r requirements-insiders.txt
echo "MKDOCS_CONFIG_FILENAME=mkdocs.yml" >> $GITHUB_ENV
fi
- name: Cache build dependencies (external assets downloaded)
uses: actions/cache@v3
with:
key: ${{ github.ref }}
path: .cache
- name: Build in strict mode
env:
MKDOCS_ENABLE_PLUGIN_CARDS: true
NETLIFY_BRANDING: '<a href="https://www.netlify.com/"><img alt="Deploys by Netlify" src="https://www.netlify.com/img/global/badges/netlify-color-accent.svg" style="float: right;"></a>'
run: |
# site name
sed -i "s|^site_name:.*|site_name: Contribution Geotribu PREVIEW |" ${{ env.MKDOCS_CONFIG_FILENAME }}
# Adjust ${{ env.MKDOCS_CONFIG_FILENAME }} for preview build
sed -i "s|^site_url:.*|site_url: https://${NETLIFY_SITE_PREFIX}--${NETLIFY_SITE_NAME}.netlify.app/ |" ${{ env.MKDOCS_CONFIG_FILENAME }}
# Insert sponsor branding into page content (Provider OSS plan requirement):
# Upstream does not provide a nicer maintainable way to do this..
# Prepends HTML to copyright text and then aligns to the right side.
sed -i "s|^copyright: '|copyright: '${NETLIFY_BRANDING}|" ${{ env.MKDOCS_CONFIG_FILENAME }}
# set repo and branch
sed -i "s|^repo_url:.*|repo_url: https://github.com/$GITHUB_REPOSITORY |" ${{ env.MKDOCS_CONFIG_FILENAME }}
sed -i "s|^edit_uri:.*|edit_uri: edit/$GITHUB_HEAD_REF/content |" ${{ env.MKDOCS_CONFIG_FILENAME }}
# merge different configs
python scripts/mkdocs_config_merger.py -c ${{ env.MKDOCS_CONFIG_FILENAME }}
# build
mkdocs build --config-file ${{ env.MKDOCS_CONFIG_FILENAME }} --verbose --strict
# save mkdocs.yml for debug
cp ${{ env.MKDOCS_CONFIG_FILENAME }} ${{ env.BUILD_DIR }}
# remove files reserved for production
rm ${{ env.BUILD_DIR }}/CNAME
rm ${{ env.BUILD_DIR }}/robots.txt
rm ${{ env.BUILD_DIR }}/sitemap.xml
rm ${{ env.BUILD_DIR }}/sitemap.xml.gz
# Minimize risk of upload failure by bundling files to a single compressed archive (tar + zstd).
# Bundles build dir and env file into a compressed archive, nested file paths will be preserved.
- name: "Prepare artifact for transfer"
run: |
# Save ENV for transfer
echo "GITHUB_REPOSITORY=$GITHUB_REPOSITORY" >> pr.env
echo "GITHUB_HEAD_REF=$GITHUB_HEAD_REF" >> pr.env
echo "PR_HEADSHA=${{ github.event.pull_request.head.sha }}" >> pr.env
echo "PR_NUMBER=${{ github.event.pull_request.number }}" >> pr.env
echo "PR_TITLE=${{ github.event.pull_request.title }}" >> pr.env
echo "NETLIFY_SITE_NAME=${{ env.NETLIFY_SITE_NAME }}" >> pr.env
echo "NETLIFY_SITE_PREFIX=${{ env.NETLIFY_SITE_PREFIX }}" >> pr.env
echo "BUILD_DIR=${{ env.BUILD_DIR }}" >> pr.env
# archive build dir
tar --zstd -cf artifact.tar.zst pr.env ${{ env.BUILD_DIR }}
- name: Save build website as artifact
uses: actions/upload-artifact@v3.1.2
with:
name: pr-build-website
path: artifact.tar.zst
retention-days: 1