2024-04-10 22:18:32 +02:00
|
|
|
name: 🛠️ Build Website
|
2024-04-03 09:06:38 +02:00
|
|
|
|
|
|
|
on:
|
|
|
|
workflow_call:
|
|
|
|
inputs:
|
2024-04-08 22:20:31 +02:00
|
|
|
config:
|
2024-04-05 21:47:56 +02:00
|
|
|
type: string
|
2024-04-08 22:20:31 +02:00
|
|
|
default: build
|
2024-04-03 09:06:38 +02:00
|
|
|
ref:
|
|
|
|
required: true
|
|
|
|
type: string
|
|
|
|
repo:
|
|
|
|
required: true
|
|
|
|
type: string
|
|
|
|
lang:
|
|
|
|
type: string
|
|
|
|
default: en
|
|
|
|
context:
|
|
|
|
type: string
|
|
|
|
default: deploy-preview
|
|
|
|
continue-on-error:
|
|
|
|
type: boolean
|
|
|
|
default: true
|
2024-04-10 22:18:32 +02:00
|
|
|
privileged:
|
|
|
|
type: boolean
|
|
|
|
default: true
|
2024-08-02 16:01:38 +02:00
|
|
|
strict:
|
|
|
|
type: boolean
|
|
|
|
default: false
|
2024-04-03 09:06:38 +02:00
|
|
|
|
|
|
|
permissions:
|
|
|
|
contents: read
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
build:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
continue-on-error: ${{ inputs.continue-on-error }}
|
|
|
|
permissions:
|
|
|
|
contents: read
|
|
|
|
|
|
|
|
steps:
|
2024-04-10 22:18:32 +02:00
|
|
|
- name: Add GitHub Token to Environment
|
|
|
|
run: |
|
2024-04-10 12:52:09 +02:00
|
|
|
echo "GH_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> "$GITHUB_ENV"
|
2024-04-08 22:20:31 +02:00
|
|
|
|
2024-04-10 22:18:32 +02:00
|
|
|
- name: Set Metadata
|
|
|
|
if: inputs.config == 'build'
|
2024-04-08 22:20:31 +02:00
|
|
|
run: |
|
2024-04-10 12:52:09 +02:00
|
|
|
{
|
2024-04-10 22:18:32 +02:00
|
|
|
echo "BUILD_CONTEXT=${{ inputs.context }}"
|
2024-04-11 08:41:22 +02:00
|
|
|
echo "EXTRA_FLAGS=""$EXTRA_FLAGS" --production""
|
2024-04-10 12:52:09 +02:00
|
|
|
} >> "$GITHUB_ENV"
|
2024-04-08 22:20:31 +02:00
|
|
|
|
2024-04-10 22:18:32 +02:00
|
|
|
- name: Set Metadata for Privileged Builds
|
|
|
|
if: inputs.privileged
|
2024-04-11 08:41:22 +02:00
|
|
|
run: |
|
|
|
|
echo "BUILD_INSIDERS=true" >> "$GITHUB_ENV"
|
|
|
|
echo "EXTRA_FLAGS=""$EXTRA_FLAGS" --insiders"" >> "$GITHUB_ENV"
|
2024-04-10 22:18:32 +02:00
|
|
|
|
|
|
|
- name: Set Metadata for Offline Mode
|
|
|
|
if: inputs.config == 'offline'
|
|
|
|
run: |
|
|
|
|
{
|
2024-04-11 08:41:22 +02:00
|
|
|
echo "EXTRA_FLAGS=""$EXTRA_FLAGS" --offline""
|
2024-04-10 22:18:32 +02:00
|
|
|
} >> "$GITHUB_ENV"
|
2024-04-08 22:20:31 +02:00
|
|
|
|
2024-08-02 16:01:38 +02:00
|
|
|
- name: Set Metadata for Strict Mode
|
|
|
|
if: inputs.strict
|
|
|
|
run: |
|
|
|
|
echo "EXTRA_FLAGS=""$EXTRA_FLAGS" --cmd_flags=--strict"" >> "$GITHUB_ENV"
|
|
|
|
|
2024-04-10 22:18:32 +02:00
|
|
|
- name: Download Repository
|
|
|
|
uses: actions/checkout@v4
|
2024-04-03 09:06:38 +02:00
|
|
|
with:
|
|
|
|
repository: ${{ inputs.repo }}
|
|
|
|
ref: ${{ inputs.ref }}
|
|
|
|
persist-credentials: "false"
|
|
|
|
fetch-depth: 0
|
|
|
|
|
2024-04-10 22:18:32 +02:00
|
|
|
- name: Download Submodules
|
|
|
|
uses: actions/download-artifact@v4
|
2024-04-03 09:06:38 +02:00
|
|
|
with:
|
|
|
|
pattern: repo-*
|
|
|
|
path: modules
|
|
|
|
|
2024-04-10 22:18:32 +02:00
|
|
|
- name: Move mkdocs-material-insiders to mkdocs-material
|
|
|
|
if: inputs.privileged
|
|
|
|
run: |
|
2024-04-03 09:06:38 +02:00
|
|
|
rmdir modules/mkdocs-material
|
|
|
|
mv modules/repo-mkdocs-material-insiders modules/mkdocs-material
|
2024-04-10 22:18:32 +02:00
|
|
|
|
|
|
|
- name: Move brand submodule to theme/assets/brand
|
|
|
|
run: |
|
2024-04-03 09:06:38 +02:00
|
|
|
rmdir theme/assets/brand
|
|
|
|
mv modules/repo-brand theme/assets/brand
|
|
|
|
|
2024-04-10 22:18:32 +02:00
|
|
|
- name: Copy Translation Files
|
|
|
|
if: inputs.lang != 'en'
|
2024-04-03 09:06:38 +02:00
|
|
|
run: |
|
|
|
|
cp -rl modules/repo-i18n/i18n .
|
|
|
|
cp -rl modules/repo-i18n/includes .
|
|
|
|
|
2024-04-11 19:29:00 +02:00
|
|
|
- name: Install Python (pipenv)
|
|
|
|
if: inputs.privileged
|
2024-04-10 22:18:32 +02:00
|
|
|
uses: actions/setup-python@v5
|
2024-04-03 09:06:38 +02:00
|
|
|
with:
|
|
|
|
cache: "pipenv"
|
|
|
|
|
2024-04-11 19:29:00 +02:00
|
|
|
- name: Install Python (no pipenv)
|
|
|
|
if: ${{ !inputs.privileged }}
|
|
|
|
uses: actions/setup-python@v5
|
|
|
|
|
2024-04-10 22:18:32 +02:00
|
|
|
- name: Restore Privacy Plugin Cache
|
|
|
|
uses: actions/cache/restore@v4.0.2
|
|
|
|
id: privacy_cache_restore
|
2024-04-03 09:06:38 +02:00
|
|
|
with:
|
2024-04-10 22:18:32 +02:00
|
|
|
key: privacy-cache-${{ inputs.repo }}-${{ hashfiles('.cache/plugin/privacy/**') }}
|
|
|
|
path: |
|
|
|
|
.cache/plugin/privacy
|
2024-04-03 09:06:38 +02:00
|
|
|
restore-keys: |
|
2024-04-10 22:18:32 +02:00
|
|
|
privacy-cache-${{ inputs.repo }}-
|
|
|
|
privacy-cache-privacyguides/privacyguides.org-
|
|
|
|
privacy-cache-
|
2024-04-03 09:06:38 +02:00
|
|
|
|
2024-04-10 22:18:32 +02:00
|
|
|
- name: Restore Social Plugin Cache
|
|
|
|
uses: actions/cache/restore@v4.0.2
|
|
|
|
id: social_cache_restore
|
2024-04-03 09:06:38 +02:00
|
|
|
with:
|
2024-04-10 22:18:32 +02:00
|
|
|
key: social-cache-${{ inputs.repo }}-${{ inputs.lang }}-${{ hashfiles('.cache/plugin/social/manifest.json') }}
|
2024-04-03 09:06:38 +02:00
|
|
|
path: |
|
2024-04-10 22:18:32 +02:00
|
|
|
.cache/plugin/social/manifest.json
|
|
|
|
.cache/plugin/social/assets
|
2024-04-03 09:06:38 +02:00
|
|
|
restore-keys: |
|
2024-04-10 22:18:32 +02:00
|
|
|
social-cache-${{ inputs.repo }}-${{ inputs.lang }}-
|
|
|
|
social-cache-privacyguides/privacyguides.org-${{ inputs.lang }}-
|
2024-04-03 09:06:38 +02:00
|
|
|
|
2024-04-10 22:18:32 +02:00
|
|
|
- name: Restore Optimize Plugin Cache
|
|
|
|
uses: actions/cache/restore@v4.0.2
|
|
|
|
id: optimize_cache_restore
|
|
|
|
with:
|
|
|
|
key: optimize-cache-${{ inputs.repo }}-${{ hashfiles('.cache/plugin/optimize/manifest.json') }}
|
|
|
|
path: |
|
|
|
|
.cache/plugin/optimize
|
|
|
|
restore-keys: |
|
|
|
|
optimize-cache-${{ inputs.repo }}-
|
|
|
|
optimize-cache-privacyguides/privacyguides.org-
|
|
|
|
optimize-cache-
|
|
|
|
|
|
|
|
- name: Install Python Dependencies
|
|
|
|
if: inputs.privileged
|
|
|
|
run: |
|
2024-04-03 09:06:38 +02:00
|
|
|
pip install pipenv
|
|
|
|
pipenv install
|
|
|
|
sudo apt install pngquant
|
|
|
|
|
2024-04-10 22:18:32 +02:00
|
|
|
- name: Install Python Dependencies (Unprivileged)
|
|
|
|
if: ${{ !inputs.privileged }}
|
|
|
|
run: |
|
|
|
|
pip install mkdocs-material
|
|
|
|
sudo apt install pngquant
|
2024-04-11 19:29:00 +02:00
|
|
|
echo "EXTRA_FLAGS=""$EXTRA_FLAGS" --cmd=mkdocs"" >> "$GITHUB_ENV"
|
2024-04-10 22:18:32 +02:00
|
|
|
|
|
|
|
- name: Build Website
|
|
|
|
run: |
|
2024-04-11 08:41:22 +02:00
|
|
|
eval ./run.sh --build --lang=${{ inputs.lang }} "$EXTRA_FLAGS"
|
2024-04-10 22:18:32 +02:00
|
|
|
|
|
|
|
- name: Package Website
|
|
|
|
run: |
|
|
|
|
tar -czf site-${{ inputs.config }}-${{ inputs.lang }}.tar.gz site
|
|
|
|
|
|
|
|
- name: Find Privacy Plugin Cache
|
|
|
|
uses: actions/cache/restore@v4.0.2
|
|
|
|
if: steps.privacy_cache_restore.outputs.cache-hit != 'true'
|
|
|
|
id: privacy_cache_test
|
2024-04-03 09:06:38 +02:00
|
|
|
with:
|
2024-04-10 22:18:32 +02:00
|
|
|
key: privacy-cache-privacyguides/privacyguides.org-${{ hashfiles('.cache/plugin/privacy/**') }}
|
|
|
|
lookup-only: true
|
|
|
|
path: |
|
|
|
|
.cache/plugin/privacy
|
2024-04-03 09:06:38 +02:00
|
|
|
|
2024-04-10 22:18:32 +02:00
|
|
|
- name: Find Social Plugin Cache
|
|
|
|
uses: actions/cache/restore@v4.0.2
|
|
|
|
if: steps.social_cache_restore.outputs.cache-hit != 'true'
|
|
|
|
id: social_cache_test
|
2024-04-03 09:06:38 +02:00
|
|
|
with:
|
2024-04-10 22:18:32 +02:00
|
|
|
key: social-cache-privacyguides/privacyguides.org-${{ inputs.lang }}-${{ hashfiles('.cache/plugin/social/manifest.json') }}
|
|
|
|
lookup-only: true
|
2024-04-03 09:06:38 +02:00
|
|
|
path: |
|
2024-04-10 22:18:32 +02:00
|
|
|
.cache/plugin/social/manifest.json
|
|
|
|
.cache/plugin/social/assets
|
|
|
|
|
|
|
|
- name: Find Optimize Plugin Cache
|
|
|
|
uses: actions/cache/restore@v4.0.2
|
|
|
|
if: steps.optimize_cache_restore.outputs.cache-hit != 'true'
|
|
|
|
id: optimize_cache_test
|
|
|
|
with:
|
|
|
|
key: optimize-cache-privacyguides/privacyguides.org-${{ hashfiles('.cache/plugin/optimize/manifest.json') }}
|
|
|
|
lookup-only: true
|
|
|
|
path: |
|
|
|
|
.cache/plugin/optimize
|
|
|
|
|
|
|
|
- name: Save Privacy Plugin Cache
|
|
|
|
uses: actions/cache/save@v4.0.2
|
|
|
|
if: steps.privacy_cache_test.outputs.cache-hit != 'true'
|
|
|
|
with:
|
|
|
|
key: privacy-cache-${{ inputs.repo }}-${{ hashfiles('.cache/plugin/privacy/**') }}
|
|
|
|
path: .cache/plugin/privacy
|
|
|
|
|
|
|
|
- name: Save Social Plugin Cache
|
|
|
|
uses: actions/cache/save@v4.0.2
|
|
|
|
if: steps.social_cache_test.outputs.cache-hit != 'true'
|
|
|
|
with:
|
|
|
|
key: social-cache-${{ inputs.repo }}-${{ inputs.lang }}-${{ hashfiles('.cache/plugin/social/manifest.json') }}
|
|
|
|
path: |
|
|
|
|
.cache/plugin/social/manifest.json
|
|
|
|
.cache/plugin/social/assets
|
|
|
|
|
|
|
|
- name: Save Optimize Plugin Cache
|
|
|
|
uses: actions/cache/save@v4.0.2
|
|
|
|
if: steps.optimize_cache_test.outputs.cache-hit != 'true'
|
|
|
|
with:
|
|
|
|
key: optimize-cache-${{ inputs.repo }}-${{ hashfiles('.cache/plugin/optimize/manifest.json') }}
|
|
|
|
path: .cache/plugin/optimize
|
2024-04-03 09:06:38 +02:00
|
|
|
|
2024-04-10 22:18:32 +02:00
|
|
|
- name: Upload Site
|
|
|
|
uses: actions/upload-artifact@v4
|
2024-04-03 09:06:38 +02:00
|
|
|
with:
|
2024-04-08 22:20:31 +02:00
|
|
|
name: site-${{ inputs.config }}-${{ inputs.lang }}.tar.gz
|
|
|
|
path: site-${{ inputs.config }}-${{ inputs.lang }}.tar.gz
|
2024-04-10 22:18:32 +02:00
|
|
|
retention-days: 1
|
2024-04-08 22:20:31 +02:00
|
|
|
|
|
|
|
offline_package:
|
|
|
|
if: inputs.config == 'offline' && inputs.lang == 'en'
|
|
|
|
needs: build
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
continue-on-error: ${{ inputs.continue-on-error }}
|
|
|
|
permissions:
|
|
|
|
contents: read
|
|
|
|
|
|
|
|
steps:
|
|
|
|
- uses: actions/download-artifact@v4
|
|
|
|
with:
|
|
|
|
name: site-offline-en.tar.gz
|
|
|
|
|
|
|
|
- run: |
|
2024-04-10 22:18:32 +02:00
|
|
|
tar -xzf site-offline-en.tar.gz
|
|
|
|
tar -czf offline.tar.gz site/en
|
2024-04-08 22:20:31 +02:00
|
|
|
zip -r -q offline.zip site/en
|
|
|
|
|
|
|
|
- name: Upload tar.gz file
|
|
|
|
uses: actions/upload-artifact@v4
|
|
|
|
with:
|
|
|
|
name: offline.tar.gz
|
|
|
|
path: offline.tar.gz
|
|
|
|
|
|
|
|
- name: Upload zip file
|
|
|
|
uses: actions/upload-artifact@v4
|
|
|
|
with:
|
|
|
|
name: offline.zip
|
|
|
|
path: offline.zip
|
|
|
|
|
|
|
|
- name: Create ZIM File
|
|
|
|
uses: addnab/docker-run-action@v3
|
|
|
|
with:
|
|
|
|
image: ghcr.io/openzim/zim-tools:3.1.3
|
|
|
|
options: -v ${{ github.workspace }}:/data
|
|
|
|
run: |
|
|
|
|
zimwriterfs -w index.html -I assets/brand/logos/png/square/pg-yellow.png -l eng -t "Privacy Guides" -d "Your central privacy and security resource to protect yourself online." -c "Privacy Guides" -p "Jonah Aragon" -n "Privacy Guides" -e "https://github.com/privacyguides/privacyguides.org" /data/site/en /data/offline-privacy_guides.zim
|
|
|
|
|
|
|
|
- name: Upload ZIM file
|
|
|
|
uses: actions/upload-artifact@v4
|
|
|
|
with:
|
|
|
|
name: offline-privacy_guides.zim
|
|
|
|
path: offline-privacy_guides.zim
|