diff --git a/.yamllint.yml b/.yamllint.yml index 1581a03..7a3c7c1 100644 --- a/.yamllint.yml +++ b/.yamllint.yml @@ -4,3 +4,4 @@ extends: default rules: braces: max-spaces-inside: 1 + line-length: disable diff --git a/action.yml b/action.yml index bab8465..127ff98 100644 --- a/action.yml +++ b/action.yml @@ -16,6 +16,13 @@ runs: using: "composite" steps: - uses: actions/checkout@v3 + - name: git config user + shell: bash + run: | + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + with: + lfs: true - name: Install pipenv shell: bash run: pip install --user pipenv @@ -37,6 +44,11 @@ runs: - name: Pull changes from sync so we can update the metadata file shell: bash run: git pull + - uses: stefanzweifel/git-auto-commit-action@3ea6ae190baf489ba007f7c92608f33ce20ef04a # v4.16.0 + with: + file_pattern: ".gitattributes **/resources/*" + commit_message: "Update resources" + commit_author: "github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>" - uses: stefanzweifel/git-auto-commit-action@3ea6ae190baf489ba007f7c92608f33ce20ef04a # v4.16.0 with: file_pattern: "*GitHubPublisher.json" diff --git a/github_publisher.py b/github_publisher.py index 83768da..2459dfe 100644 --- a/github_publisher.py +++ b/github_publisher.py @@ -4,6 +4,7 @@ import base64 import re +import subprocess # nosec B404 import time import uuid from functools import lru_cache @@ -629,6 +630,27 @@ def convert_card_content(self, card: guru.Card): for iframe in content.select("iframe"): iframe.replace_with(iframe.attrs.get("src")) + # Download images and replace image URLs with local file paths + for image in content.select("img"): + filename = image.attrs.get("data-ghq-card-content-image-filename") + file_extension = path.splitext(filename)[1] + + collection_path: str = self.get_external_collection_path(card.collection) + image_relative_path = f"resources/{filename}" + image_absolute_path = f"{collection_path}/{image_relative_path}" + guru.download_file( + image.attrs.get("src"), + image_absolute_path, + headers={"Authorization": source._Guru__get_basic_auth_value()}, + ) + image.attrs["src"] = image_relative_path + + # Ensure the file extension is tracked by Git LFS + subprocess.run(["/usr/bin/git", "lfs", "track", f"*{file_extension}"], check=True) # nosec B603 + + # Stage the file for commit + subprocess.run(["/usr/bin/git", "add", image_absolute_path], check=True) # nosec B603 + # Add a title to the content that links to the card in Guru return f"# [{card.title}]({card.url})\n\n{content.prettify()}"