From ceb58ed2c26d3bd11df2def3087da4287029ad16 Mon Sep 17 00:00:00 2001 From: Florian Heilmann Date: Tue, 12 Dec 2023 18:08:30 +0100 Subject: [PATCH] fix: Fix up image upload, add workflow --- .github/workflows/post_process_pr.yml | 27 ++++++++++++++++----------- .github/workflows/test_pr.yml | 4 ++-- voron_ci/utils/imagekit_uploader.py | 11 ++++++----- voron_ci/utils/pr_helper.py | 21 +++++---------------- 4 files changed, 29 insertions(+), 34 deletions(-) diff --git a/.github/workflows/post_process_pr.yml b/.github/workflows/post_process_pr.yml index c422df3..6536856 100644 --- a/.github/workflows/post_process_pr.yml +++ b/.github/workflows/post_process_pr.yml @@ -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 @@ -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 diff --git a/.github/workflows/test_pr.yml b/.github/workflows/test_pr.yml index f6e2ac6..19db043 100644 --- a/.github/workflows/test_pr.yml +++ b/.github/workflows/test_pr.yml @@ -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 diff --git a/voron_ci/utils/imagekit_uploader.py b/voron_ci/utils/imagekit_uploader.py index 4fe8eb5..0ba6059 100644 --- a/voron_ci/utils/imagekit_uploader.py +++ b/voron_ci/utils/imagekit_uploader.py @@ -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 @@ -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: @@ -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: diff --git a/voron_ci/utils/pr_helper.py b/voron_ci/utils/pr_helper.py index 0b6fb50..30c6cec 100644 --- a/voron_ci/utils/pr_helper.py +++ b/voron_ci/utils/pr_helper.py @@ -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! @@ -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) @@ -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) @@ -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: