From 1d7cd677f843721285580f619ecf3da55532eee3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Krzy=C5=9Bk=C3=B3w?= Date: Fri, 20 Sep 2024 22:10:01 +0200 Subject: [PATCH] feat: reusable workflow for deployment fix: latest_blog_posts crash with empty nav --- .github/workflows/reusable_deploy.yml | 85 +++++++++++++++++++ .../plugins/latest_blog_posts/plugin.py | 4 + 2 files changed, 89 insertions(+) create mode 100644 .github/workflows/reusable_deploy.yml diff --git a/.github/workflows/reusable_deploy.yml b/.github/workflows/reusable_deploy.yml new file mode 100644 index 0000000..64c0c4a --- /dev/null +++ b/.github/workflows/reusable_deploy.yml @@ -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/ssh-deploy@v5.1.0 + 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 }} + \ No newline at end of file diff --git a/mkdocs_nype/plugins/latest_blog_posts/plugin.py b/mkdocs_nype/plugins/latest_blog_posts/plugin.py index 4dc6ecb..939f09b 100644 --- a/mkdocs_nype/plugins/latest_blog_posts/plugin.py +++ b/mkdocs_nype/plugins/latest_blog_posts/plugin.py @@ -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")