-
Notifications
You must be signed in to change notification settings - Fork 0
111 lines (92 loc) · 4.93 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
name: "Pull Request Checker 🛃"
# Inspired from: https://github.com/docker-mailserver/docker-mailserver/blob/master/.github/workflows/docs-preview-prepare.yml
on:
# push:
# branches: [main]
pull_request:
branches: [main]
# Environment variables
env:
BUILD_DIR: build/mkdocs/site
NETLIFY_SITE_NAME: geotribu-sandbox
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@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.9
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 "::set-output name=config_path::mkdocs-free.yml"
else
# install insiders version using token
python -m pip install -U -r requirements-insiders.txt
echo "::set-output name=config_path::mkdocs.yml"
fi
- name: Build in strict mode
env:
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: Geotribu PREVIEW |" ${{steps.dependencies.outputs.config_path}}
# Adjust ${{steps.dependencies.outputs.config_path}} for preview build
sed -i "s|^site_url:.*|site_url: https://${NETLIFY_SITE_PREFIX}--${NETLIFY_SITE_NAME}.netlify.app/ |" ${{steps.dependencies.outputs.config_path}}
# 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}|" ${{steps.dependencies.outputs.config_path}}
# set repo and branch
sed -i "s|^repo_url:.*|repo_url: https://github.com/$GITHUB_REPOSITORY |" ${{steps.dependencies.outputs.config_path}}
sed -i "s|^edit_uri:.*|edit_uri: edit/$GITHUB_HEAD_REF/content |" ${{steps.dependencies.outputs.config_path}}
# build
mkdocs build --config-file ${{steps.dependencies.outputs.config_path}} --verbose --strict
# save mkdocs.yml for debug
cp ${{steps.dependencies.outputs.config_path}} ${{ 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@v2
with:
name: pr-build-website
path: artifact.tar.zst
retention-days: 1