Skip to content

Commit

Permalink
fix: Fix up image upload, add workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
FHeilmann committed Dec 12, 2023
1 parent fe31882 commit ceb58ed
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 34 deletions.
27 changes: 16 additions & 11 deletions .github/workflows/post_process_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ on:

jobs:
create_pr_comment:
if: ${{ github.event.workflow_run.event == 'pull_request' }}
permissions:
pull-requests: write
runs-on: ubuntu-latest
steps:
# Sanitize the file list
- name: Create PR comment 💬
id: create_pr_comment
uses: docker://ghcr.io/fheilmann/voron_ci_container:latest
Expand All @@ -24,13 +24,18 @@ jobs:
with:
args: set-pr-comment-labels

# upload_imagekit:
# if: ${{ github.event.workflow_run.event == 'pull_request' }}
# uses: VoronDesign/.github/.github/workflows/upload-artifact-imagekit.yml@main
# with:
# artifact_name: pr_rotated_stls
# images_subfolder: img
# imagekit-url-endpoint: https://ik.imagekit.io/vorondesign
# secrets:
# IMAGEKIT_PRIVATE_KEY: ${{ secrets.IMAGEKIT_PRIVATE_KEY }}
# IMAGEKIT_PUBLIC_KEY: ${{ secrets.IMAGEKIT_PUBLIC_KEY }}
upload_imagekit:
if: ${{ github.event.workflow_run.event == 'pull_request' }}
runs-on: ubuntu-latest
steps:
- name: Upload images to imagekit 📸
id: imagekit-upload
uses: docker://ghcr.io/fheilmann/voron_ci_container:latest
env:
IMAGEKIT_UPLOADER_WORKFLOW_RUN_ID: ${{ github.event.workflow_run.id }}
IMAGEKIT_UPLOADER_ARTIFACT_NAME: ci_output
IMAGEKIT_UPLOADER_GITHUB_REPOSITORY: ${{ github.repository }}
IMAGEKIT_UPLOADER_PUBLIC_KEY: ${{ secrets.IMAGEKIT_PUBLIC_KEY }}
IMAGEKIT_UPLOADER_PRIVATE_KEY: ${{ secrets.IMAGEKIT_PRIVATE_KEY }}
IMAGEKIT_UPLOADER_IMAGEKIT_ENDPOINT: ${{ secrets.IMAGEKIT_URL_ENDPOINT }}
IMAGEKIT_UPLOADER_VERBOSE: true
4 changes: 2 additions & 2 deletions .github/workflows/test_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ jobs:
ROTATION_CHECKER_INPUT_DIR: ${{ github.workspace }}/tests/test_repository_root/printer_mods
ROTATION_CHECKER_VERBOSE: true
ROTATION_CHECKER_IGNORE_WARNINGS: true
ROTATION_CHECKER_IMAGEKIT_ENDPOINT: ./img
ROTATION_CHECKER_IMAGEKIT_SUBFOLDER: test_run
ROTATION_CHECKER_IMAGEKIT_ENDPOINT: ${{ secrets.IMAGEKIT_URL_ENDPOINT }}
ROTATION_CHECKER_IMAGEKIT_SUBFOLDER: img
with:
args: check-stl-rotation
# Generate a README
Expand Down
11 changes: 6 additions & 5 deletions voron_ci/utils/imagekit_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from imagekitio.models.UploadFileRequestOptions import UploadFileRequestOptions
from loguru import logger

from voron_ci.constants import StepIdentifier
from voron_ci.utils.github_action_helper import GithubActionHelper
from voron_ci.utils.logging import init_logging

Expand All @@ -19,7 +20,7 @@
from imagekitio.models.results import UploadFileResult

ENV_VAR_PREFIX = "IMAGEKIT_UPLOADER"
IMAGE_SUBDIRECTORY = "rotation_checker/img"
IMAGE_SUBDIRECTORY = f"{StepIdentifier.ROTATION_CHECK.step_id}/img"


class ImageKitUploader:
Expand Down Expand Up @@ -64,18 +65,18 @@ def run(self: Self) -> None:
logger.info("Downloading artifact '{}' from workflow '{}'", self.artifact_name, self.workflow_run_id)
with tempfile.TemporaryDirectory() as tmpdir:
logger.info("Created temporary directory '{}'", tmpdir)
tmp_path = Path(tmpdir)
self.tmp_path = Path(tmpdir)

GithubActionHelper.download_artifact(
repo=self.github_repository,
workflow_run_id=self.workflow_run_id,
artifact_name=self.artifact_name,
target_directory=tmp_path,
target_directory=self.tmp_path,
)

self.image_base_path = Path(tmp_path, IMAGE_SUBDIRECTORY)
self.image_base_path = Path(self.tmp_path, IMAGE_SUBDIRECTORY)

logger.info("Processing Image files in '{}'", tmp_path.as_posix())
logger.info("Processing Image files in '{}'", self.tmp_path.as_posix())

images: list[Path] = list(self.image_base_path.glob("**/*.png"))
if not images:
Expand Down
21 changes: 5 additions & 16 deletions voron_ci/utils/pr_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,6 @@
"""

CLOSING_SUCCESS = """
Congratulations, all checks have completed successfully! Your PR is now ready for review!
"""

CLOSING_FAILURE = """
Unfortunately, some checks have failed. Please fix the issues and update your PR.
"""

CLOSING_BOT_NOTICE = """
I am a 🤖, this comment was generated automatically!
Expand All @@ -45,7 +33,8 @@ def __init__(self: Self, args: configargparse.Namespace) -> None:
self.tmp_path: Path = Path()

self.pr_number: int = -1
self.summaries: str = ""

self.comment_body: str = PREAMBLE
self.labels: list[str] = []

init_logging(verbose=args.verbose)
Expand All @@ -69,8 +58,8 @@ def _parse_artifact(self: Self) -> None:
Path(self.tmp_path, pr_step_identifier.step_id, "outcome.txt").exists(),
)
continue
self.summaries += Path(self.tmp_path, pr_step_identifier.step_id, "summary.md").read_text()
self.summaries += "\n\n"
self.comment_body += Path(self.tmp_path, pr_step_identifier.step_id, "summary.md").read_text()
self.comment_body += "\n\n"
outcome: StepResult = StepResult[Path(self.tmp_path, pr_step_identifier.step_id, "outcome.txt").read_text()]
if outcome > StepResult.SUCCESS:
self.labels.append(pr_step_identifier.step_pr_label)
Expand All @@ -93,7 +82,7 @@ def run(self: Self) -> None:
self._parse_artifact()
if self.pr_number > 0:
GithubActionHelper.set_labels_on_pull_request(repo=self.github_repository, pull_request_number=self.pr_number, labels=self.labels)
GithubActionHelper.update_or_create_pr_comment(repo=self.github_repository, pull_request_number=self.pr_number, comment_body=self.summaries)
GithubActionHelper.update_or_create_pr_comment(repo=self.github_repository, pull_request_number=self.pr_number, comment_body=self.comment_body)


def main() -> None:
Expand Down

0 comments on commit ceb58ed

Please sign in to comment.