Skip to content

Commit

Permalink
feat: reusable workflow for deployment
Browse files Browse the repository at this point in the history
fix: latest_blog_posts crash with empty nav
  • Loading branch information
kamilkrzyskow committed Sep 21, 2024
1 parent a2ddbc3 commit 1d7cd67
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
85 changes: 85 additions & 0 deletions .github/workflows/reusable_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Reusable Nype Deploy CI

on:
workflow_call:
secrets:
SSH_PRIVATE_KEY:
required: true
SSH_HOST:
required: true
SSH_PORT:
required: true
SSH_USER:
required: true
SSH_TARGET:
required: true
SSH_COMMAND:
required: true

env:
CI: true

permissions:
contents: write

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Configure Git Credentials
run: |
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
- name: Download variable dependency list from the theme
run: |
wget -O requirements-theme.txt https://raw.githubusercontent.com/nypesap/mkdocs-nype/main/requirements.txt
wget -O pyproject-theme.toml https://raw.githubusercontent.com/nypesap/mkdocs-nype/main/pyproject.toml
- name: Install Python
id: install-python
uses: actions/setup-python@v5
with:
python-version: 3.x
cache: pip
- name: Process Python Cache
id: cache-requirements
uses: actions/cache@v4
with:
path: venv
key: requirements-${{ steps.install-python.outputs.python-version }}-${{ hashFiles('requirements*.txt', 'pyproject*.toml') }}
- name: Install Uncached Requirements
if: steps.cache-requirements.outputs.cache-hit != 'true'
run: |
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
- run: mkdir -p .cache; echo mkdocs-material > .cache/safe
- uses: actions/cache@v4
with:
key: mkdocs-material-${{ hashfiles('.cache/**') }}
path: .cache
restore-keys: |
mkdocs-material-
- run: venv/bin/python -m mkdocs_nype --minify --inject-minified
- run: venv/bin/python -m mkdocs build --strict
- name: Prepare deploy archive
run: |
zip -r site.zip site/
sha256sum site.zip > checksum
sha256sum -c checksum
mkdir -p deploy
zip deploy/deploy.zip site.zip checksum
- name: Deploy files via rsync and SSH
uses: easingthemes/[email protected]
with:
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
source: deploy/
remote_host: ${{ secrets.SSH_HOST }}
remote_port: ${{ secrets.SSH_PORT }}
remote_user: ${{ secrets.SSH_USER }}
target: ${{ secrets.SSH_TARGET }}
script_after_required: true
script_after: |
export SSH_TARGET=${{ secrets.SSH_TARGET }}
${{ secrets.SSH_COMMAND }}
4 changes: 4 additions & 0 deletions mkdocs_nype/plugins/latest_blog_posts/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ def on_page_markdown(self, markdown: str, page: Page, config: MkDocsConfig, file
if page.file.src_uri != "index.md":
return

# awesome-pages-plugin
if config.nav is None:
return

self.exec_count[page.file.src_uri] = self.exec_count.get(page.file.src_uri, 0) + 1

lines = markdown.split("\n")
Expand Down

0 comments on commit 1d7cd67

Please sign in to comment.