From c4c61c609ea3b7522bb9627383dab9fcd0fe2a5f Mon Sep 17 00:00:00 2001 From: mashehu Date: Fri, 26 Jan 2024 14:50:54 +0100 Subject: [PATCH 1/4] =?UTF-8?q?template:=20add=20=F0=9F=91=80=F0=9F=91=8D?= =?UTF-8?q?=F0=9F=8F=BB=F0=9F=8E=89=F0=9F=98=95=20reactions=20to=20fix-lin?= =?UTF-8?q?ting=20bot=20action?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/fix-linting.yml | 21 +++---- .../.github/workflows/fix-linting.yml | 57 ++++++++++++++++--- 2 files changed, 57 insertions(+), 21 deletions(-) diff --git a/.github/workflows/fix-linting.yml b/.github/workflows/fix-linting.yml index 5411deef43..e62d55083b 100644 --- a/.github/workflows/fix-linting.yml +++ b/.github/workflows/fix-linting.yml @@ -4,7 +4,7 @@ on: types: [created] jobs: - deploy: + fix-linting: # Only run if comment is on a PR with the main repo, and if it contains the magic keywords if: > contains(github.event.comment.html_url, '/pull/') && @@ -46,15 +46,15 @@ jobs: # indication that the linting has finished - name: react if linting finished succesfully - if: ${{ steps.pre-commit.outcome }} == 'success' + if: steps.pre-commit.outcome == 'success' uses: peter-evans/create-or-update-comment@23ff15729ef2fc348714a3bb66d2f655ca9066f2 # v3 with: comment-id: ${{ github.event.comment.id }} - reactions: +1 + reactions: "+1" - name: Commit & push changes id: commit-and-push - if: ${{ steps.pre-commit.outcome }} == 'failure' + if: steps.pre-commit.outcome == 'failure' run: | git config user.email "core@nf-co.re" git config user.name "nf-core-bot" @@ -63,30 +63,25 @@ jobs: git status git commit -m "[automated] Fix code linting" git push - - name: debug outcome value - run: echo ${{ steps.commit-and-push.outcome }} - name: react if linting errors were fixed id: react-if-fixed - if: ${{ steps.commit-and-push.outcome }} == 'success' + if: steps.commit-and-push.outcome == 'success' uses: peter-evans/create-or-update-comment@23ff15729ef2fc348714a3bb66d2f655ca9066f2 # v3 with: comment-id: ${{ github.event.comment.id }} reactions: hooray - - name: debug outcome value again - run: echo ${{ steps.commit-and-push.outcome }} - - name: react if linting errors were not fixed - if: ${{ steps.commit-and-push.outcome }} == 'failure' && ${{ steps.react-if-fixed.outcome }} != 'success' + if: steps.commit-and-push.outcome == 'failure' uses: peter-evans/create-or-update-comment@23ff15729ef2fc348714a3bb66d2f655ca9066f2 # v3 with: comment-id: ${{ github.event.comment.id }} reactions: confused - name: react if linting errors were not fixed - if: ${{ steps.commit-and-push.outcome }} == 'failure' && ${{ steps.react-if-fixed.outcome }} != 'success' - uses: peter-evans/create-or-update-comment@v3 + if: steps.commit-and-push.outcome == 'failure' + uses: peter-evans/create-or-update-comment@23ff15729ef2fc348714a3bb66d2f655ca9066f2 # v3 with: issue-number: ${{ github.event.issue.number }} body: | diff --git a/nf_core/pipeline-template/.github/workflows/fix-linting.yml b/nf_core/pipeline-template/.github/workflows/fix-linting.yml index d9986bd30f..d8fbf40c98 100644 --- a/nf_core/pipeline-template/.github/workflows/fix-linting.yml +++ b/nf_core/pipeline-template/.github/workflows/fix-linting.yml @@ -13,10 +13,17 @@ jobs: runs-on: ubuntu-latest steps: # Use the @nf-core-bot token to check out so we can push later - - uses: actions/checkout@v4 + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 with: token: ${{ secrets.nf_core_bot_auth_token }} + # indication that the linting is being fixed + - name: React on comment + uses: peter-evans/create-or-update-comment@23ff15729ef2fc348714a3bb66d2f655ca9066f2 # v3 + with: + comment-id: ${{ github.event.comment.id }} + reactions: eyes + # Action runs on the issue comment, so we don't get the PR by default # Use the gh cli to check out the PR - name: Checkout Pull Request @@ -24,25 +31,59 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.nf_core_bot_auth_token }} - - name: Set up Python 3.11 - uses: actions/setup-python@v5 + # Install and run pre-commit + - uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5 with: python-version: 3.11 - cache: "pip" - name: Install pre-commit run: pip install pre-commit - name: Run pre-commit - run: pre-commit run --all-files || echo "status=fail" >> $GITHUB_ENV + id: pre-commit + run: pre-commit run --all-files + continue-on-error: true + + # indication that the linting has finished + - name: react if linting finished succesfully + if: steps.pre-commit.outcome == 'success' + uses: peter-evans/create-or-update-comment@23ff15729ef2fc348714a3bb66d2f655ca9066f2 # v3 + with: + comment-id: ${{ github.event.comment.id }} + reactions: "+1" - name: Commit & push changes - if: env.status == 'fail' + id: commit-and-push + if: steps.pre-commit.outcome == 'failure' run: | git config user.email "core@nf-co.re" git config user.name "nf-core-bot" git config push.default upstream git add . git status - git commit -m "[automated] Fix linting with pre-commit" - git push {%- endraw %} + git commit -m "[automated] Fix code linting" + git push + + - name: react if linting errors were fixed + id: react-if-fixed + if: steps.commit-and-push.outcome == 'success' + uses: peter-evans/create-or-update-comment@23ff15729ef2fc348714a3bb66d2f655ca9066f2 # v3 + with: + comment-id: ${{ github.event.comment.id }} + reactions: hooray + + - name: react if linting errors were not fixed + if: steps.commit-and-push.outcome == 'failure' + uses: peter-evans/create-or-update-comment@23ff15729ef2fc348714a3bb66d2f655ca9066f2 # v3 + with: + comment-id: ${{ github.event.comment.id }} + reactions: confused + + - name: react if linting errors were not fixed + if: steps.commit-and-push.outcome == 'failure' + uses: peter-evans/create-or-update-comment@23ff15729ef2fc348714a3bb66d2f655ca9066f2 # v3 + with: + issue-number: ${{ github.event.issue.number }} + body: | + @${{ github.actor }} I tried to fix the linting errors, but it didn't work. Please fix them manually. + See [CI log](https://github.com{% endraw %}{{name}}{% raw %}/actions/runs/${{ github.run_id }}) for more details.{% endraw %} From 100d2e87b78d6eb2a33039ee4744ca48343ff294 Mon Sep 17 00:00:00 2001 From: mashehu Date: Fri, 26 Jan 2024 14:51:39 +0100 Subject: [PATCH 2/4] cache created logos and hand force over to create_logo --- nf_core/create.py | 26 +++++++++++--- nf_core/create_logo.py | 78 ++++++++++++++++++++++++------------------ 2 files changed, 67 insertions(+), 37 deletions(-) diff --git a/nf_core/create.py b/nf_core/create.py index 76fc50e8fa..f9e9933ee3 100644 --- a/nf_core/create.py +++ b/nf_core/create.py @@ -505,10 +505,12 @@ def fix_linting(self): def make_pipeline_logo(self): """Fetch a logo for the new pipeline from the nf-core website""" email_logo_path = Path(self.outdir) / "assets" - create_logo(text=self.template_params["short_name"], dir=email_logo_path, theme="light") + create_logo(text=self.template_params["short_name"], dir=email_logo_path, theme="light", force=self.force) for theme in ["dark", "light"]: readme_logo_path = Path(self.outdir) / "docs" / "images" - create_logo(text=self.template_params["short_name"], dir=readme_logo_path, width=600, theme=theme) + create_logo( + text=self.template_params["short_name"], dir=readme_logo_path, width=600, theme=theme, force=self.force + ) def git_init_pipeline(self): """Initialises the new pipeline as a Git repository and submits first commit. @@ -537,8 +539,24 @@ def git_init_pipeline(self): repo.index.commit(f"initial template build from nf-core/tools, version {nf_core.__version__}") if default_branch: repo.active_branch.rename(default_branch) - repo.git.branch("TEMPLATE") - repo.git.branch("dev") + try: + repo.git.branch("TEMPLATE") + repo.git.branch("dev") + + except git.GitCommandError as e: + if "already exists" in e.stderr: + log.debug("Branches 'TEMPLATE' and 'dev' already exist") + if self.force: + log.debug("Force option set - deleting branches") + repo.git.branch("-D", "TEMPLATE") + repo.git.branch("-D", "dev") + repo.git.branch("TEMPLATE") + repo.git.branch("dev") + else: + log.error( + "Branches 'TEMPLATE' and 'dev' already exist. Use --force to overwrite existing branches." + ) + sys.exit(1) log.info( "Done. Remember to add a remote and push to GitHub:\n" f"[white on grey23] cd {self.outdir} \n" diff --git a/nf_core/create_logo.py b/nf_core/create_logo.py index e40dd73452..4dfebd3712 100644 --- a/nf_core/create_logo.py +++ b/nf_core/create_logo.py @@ -5,6 +5,7 @@ from PIL import Image, ImageDraw, ImageFont import nf_core +from nf_core.utils import NFCORE_CACHE_DIR log = logging.getLogger(__name__) @@ -26,7 +27,6 @@ def create_logo( if not dir.is_dir(): log.debug(f"Creating directory {dir}") dir.mkdir(parents=True, exist_ok=True) - assets = Path(nf_core.__file__).parent / "assets/logo" if format == "svg": @@ -51,44 +51,56 @@ def create_logo( else: logo_filename = f"nf-core-{text}_logo_{theme}.png" if not filename else filename logo_filename = f"{logo_filename}.png" if not logo_filename.lower().endswith(".png") else logo_filename + cache_name = f"nf-core-{text}_logo_{theme}_{width}.png" logo_path = Path(dir, logo_filename) # Check if we haven't already created this logo if logo_path.is_file() and not force: log.info(f"Logo already exists at: {logo_path}. Use `--force` to overwrite.") return logo_path - - log.debug(f"Creating logo for {text}") - - # make sure the figure fits the text - font_path = assets / "MavenPro-Bold.ttf" - log.debug(f"Using font: {str(font_path)}") - font = ImageFont.truetype(str(font_path), 400) - text_length = font.getmask(text).getbbox()[2] # get the width of the text based on the font - - max_width = max( - 2300, text_length + len(text) * 20 - ) # need to add some more space to the text length to make sure it fits - - template_fn = "nf-core-repo-logo-base-lightbg.png" - if theme == "dark": - template_fn = "nf-core-repo-logo-base-darkbg.png" - - template_path = assets / template_fn - img = Image.open(str(template_path)) - # get the height of the template image - height = img.size[1] - - # Draw text - draw = ImageDraw.Draw(img) - color = theme == "dark" and (250, 250, 250) or (5, 5, 5) - draw.text((110, 465), text, color, font=font) - - # Crop to max width - img = img.crop((0, 0, max_width, height)) - - # Resize - img = img.resize((width, int((width / max_width) * height))) + # cache file + cache_path = Path(NFCORE_CACHE_DIR, "logo", cache_name) + img = None + if cache_path.is_file(): + log.debug(f"Logo already exists in cache at: {cache_path}. Reusing this file.") + img = Image.open(str(cache_path)) + if not img: + log.debug(f"Creating logo for {text}") + + # make sure the figure fits the text + font_path = assets / "MavenPro-Bold.ttf" + log.debug(f"Using font: {str(font_path)}") + font = ImageFont.truetype(str(font_path), 400) + text_length = font.getmask(text).getbbox()[2] # get the width of the text based on the font + + max_width = max( + 2300, text_length + len(text) * 20 + ) # need to add some more space to the text length to make sure it fits + + template_fn = "nf-core-repo-logo-base-lightbg.png" + if theme == "dark": + template_fn = "nf-core-repo-logo-base-darkbg.png" + + template_path = assets / template_fn + img = Image.open(str(template_path)) + # get the height of the template image + height = img.size[1] + + # Draw text + draw = ImageDraw.Draw(img) + color = theme == "dark" and (250, 250, 250) or (5, 5, 5) + draw.text((110, 465), text, color, font=font) + + # Crop to max width + img = img.crop((0, 0, max_width, height)) + + # Resize + img = img.resize((width, int((width / max_width) * height))) + + # Save to cache + Path(cache_path.parent).mkdir(parents=True, exist_ok=True) + log.debug(f"Saving logo to cache: {cache_path}") + img.save(cache_path, "PNG") # Save img.save(logo_path, "PNG") From ea68d7d8aca2507e4c3a50bb1a4012df79646ff8 Mon Sep 17 00:00:00 2001 From: nf-core-bot Date: Fri, 26 Jan 2024 13:56:02 +0000 Subject: [PATCH 3/4] [automated] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 707dc8635f..21750bf270 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ - Fix linting of a pipeline with patched custom module ([#2669](https://github.com/nf-core/tools/pull/2669)) - linting a pipeline also lints the installed subworkflows ([#2677](https://github.com/nf-core/tools/pull/2677)) - environment.yml name must be lowercase ([#2676](https://github.com/nf-core/tools/pull/2676)) +- template: add 👀👍🏻🎉😕 reactions to fix-bot action ([#2692](https://github.com/nf-core/tools/pull/2692)) ### Modules From 63b6a5a38cc51c1db124a0e220311c45840bd045 Mon Sep 17 00:00:00 2001 From: mashehu Date: Fri, 26 Jan 2024 14:57:09 +0100 Subject: [PATCH 4/4] add missing slash --- nf_core/pipeline-template/.github/workflows/fix-linting.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nf_core/pipeline-template/.github/workflows/fix-linting.yml b/nf_core/pipeline-template/.github/workflows/fix-linting.yml index d8fbf40c98..e69054ead6 100644 --- a/nf_core/pipeline-template/.github/workflows/fix-linting.yml +++ b/nf_core/pipeline-template/.github/workflows/fix-linting.yml @@ -86,4 +86,4 @@ jobs: issue-number: ${{ github.event.issue.number }} body: | @${{ github.actor }} I tried to fix the linting errors, but it didn't work. Please fix them manually. - See [CI log](https://github.com{% endraw %}{{name}}{% raw %}/actions/runs/${{ github.run_id }}) for more details.{% endraw %} + See [CI log](https://github.com/{% endraw %}{{name}}{% raw %}/actions/runs/${{ github.run_id }}) for more details.{% endraw %}