-
-
Notifications
You must be signed in to change notification settings - Fork 3
121 lines (102 loc) · 5.16 KB
/
pr_checker_build.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
name: "Pull Request Checker 🛃"
# Inspired from: https://github.com/docker-mailserver/docker-mailserver/blob/master/.github/workflows/docs-preview-prepare.yml
on:
pull_request:
branches:
- main
# Environment variables
env:
BUILD_DIR: build/mkdocs/site
NETLIFY_SITE_NAME: geotribu-preprod
NETLIFY_SITE_PREFIX: geotribu-english-${{ github.event.pull_request.number }}
PR_NUMBER: ${{ 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@v4
- name: Set up Python
uses: actions/setup-python@v5
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@v4
with:
key: ${{ github.ref }}
path: .cache
- name: Build in strict mode
env:
MKDOCS_EDIT_URI: "edit/$GITHUB_HEAD_REF/content"
MKDOCS_ENABLE_PLUGIN_RSS: true
MKDOCS_ENABLE_PLUGIN_SOCIAL: true
MKDOCS_ENABLE_PLUGIN_SOCIAL_CARDS: true
MKDOCS_PLUGIN_BLOG_DRAFT_FUTURE_DATE: false
MKDOCS_SITE_NAME: "Geotribu in English PREVIEW - PR ${{ github.event.pull_request.number }}"
MKDOCS_SITE_COPYRIGHT: '<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: |
# store custom env vars that need resolution
export MKDOCS_EDIT_URI="edit/${GITHUB_HEAD_REF}/content"
export MKDOCS_SITE_URL="https://${NETLIFY_SITE_PREFIX}--${NETLIFY_SITE_NAME}.netlify.app/"
# merge different configs
python scripts/100_mkdocs_config_merger.py -c ${{ env.MKDOCS_CONFIG_FILENAME }}
# build
mkdocs build --config-file ${{ env.MKDOCS_CONFIG_FILENAME }} --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
# store specific env vars
echo "MKDOCS_EDIT_URI=$MKDOCS_EDIT_URI" >> pr.env
echo "MKDOCS_SITE_COPYRIGHT=$MKDOCS_SITE_COPYRIGHT" >> pr.env
echo "MKDOCS_SITE_NAME=$MKDOCS_SITE_NAME" >> pr.env
echo "MKDOCS_SITE_URL=$MKDOCS_SITE_URL" >> pr.env
# 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@v4
with:
name: pr-build-website
path: artifact.tar.zst
retention-days: 1