From 2e41870337774431e730bc63805c2e3fb8492d10 Mon Sep 17 00:00:00 2001 From: reemo3dp <150130755+reemo3dp@users.noreply.github.com> Date: Wed, 13 Mar 2024 23:39:27 +0100 Subject: [PATCH] chore(docs): Generate previews --- .github/workflows/update_previews.yaml | 43 +++++++++++++++++++ .../preview_generator/markdown_generator.py | 2 +- 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/update_previews.yaml diff --git a/.github/workflows/update_previews.yaml b/.github/workflows/update_previews.yaml new file mode 100644 index 0000000..a3fef93 --- /dev/null +++ b/.github/workflows/update_previews.yaml @@ -0,0 +1,43 @@ +name: Update Previews +on: + workflow_dispatch: + push: + paths: + - '*.md' + - 'docs/*.md' + - 'docs/**/*.md' + branches: + - main + +jobs: + update_previews: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Python 3.11 + uses: actions/setup-python@v5 + with: + python-version: 3.11 + - name: Install Poetry + uses: snok/install-poetry@v1 + - name: Install dependencies + working-directory: ./packages/preview_generator + run: poetry install + - name: Update all previews + working-directory: ./packages/preview_generator + run: | + set -x + for i in $(ls $GITHUB_WORKSPACE/*.md $GITHUB_WORKSPACE/docs/**/*.md $GITHUB_WORKSPACE/docs/*.md); do + poetry run python markdown_generator.py "$i" + done + - name: Commit changes + working-directory: . + run: | + set -euxo pipefail + git config --global user.name "GitHub Actions" + git config --global user.email "githubactions@github.com" + git add *.md docs/**/*.md docs/*.md || true + git diff --staged --quiet && exit 0 || true + + git commit -m "chore(docs): Update previews" + git push origin HEAD:${GITHUB_REF} diff --git a/packages/preview_generator/markdown_generator.py b/packages/preview_generator/markdown_generator.py index 7e1bc02..bd5a7ec 100644 --- a/packages/preview_generator/markdown_generator.py +++ b/packages/preview_generator/markdown_generator.py @@ -11,7 +11,7 @@ def replace_with_preview(match): content = match.group('block') layers = match.group('layers') output_dir = os.path.dirname(args.markdown.name) - filename = os.path.join(output_dir, args.directory, "preview_" + str(zlib.crc32(layers.encode('utf-8')))+".gif") + filename = os.path.join(output_dir, args.directory, "preview_" + str(zlib.crc32(repr([layers, args]).encode('utf-8')))+".gif") relative_filename = "./"+os.path.relpath(filename, os.path.dirname(args.markdown.name)) # If file doesn't exist if not os.path.exists(filename):