From 1b3f7e7a69af9d3efb2f321d7d19a82b9b48c120 Mon Sep 17 00:00:00 2001 From: mashehu Date: Fri, 26 Jan 2024 16:33:29 +0100 Subject: [PATCH 1/6] fix linting --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 51afe36aeb..3a7508ec61 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,7 +24,6 @@ - environment.yml name must be lowercase ([#2676](https://github.com/nf-core/tools/pull/2676)) - lint `nextflow.config` default values match the ones specified in `nextflow_schema.json` ([#2684](https://github.com/nf-core/tools/pull/2684)) - ### Modules - Fix empty json output for `nf-core list local` ([#2668](https://github.com/nf-core/tools/pull/2668)) From dbb5800ed819b51066abc9ab2b34e291b06324fb Mon Sep 17 00:00:00 2001 From: mashehu Date: Fri, 26 Jan 2024 16:36:40 +0100 Subject: [PATCH 2/6] reapply changes to fix-linting action --- .github/workflows/fix-linting.yml | 21 +++---- .../.github/workflows/fix-linting.yml | 59 ++++++++++++++++--- 2 files changed, 58 insertions(+), 22 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..71f235ef41 100644 --- a/nf_core/pipeline-template/.github/workflows/fix-linting.yml +++ b/nf_core/pipeline-template/.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/') && @@ -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 08ff3030cd6499e33b1e80ffce7c92a9acf509d1 Mon Sep 17 00:00:00 2001 From: mashehu Date: Fri, 26 Jan 2024 16:37:09 +0100 Subject: [PATCH 3/6] =?UTF-8?q?Revert=20"Revert=20"template:=20add=20?= =?UTF-8?q?=F0=9F=91=80=F0=9F=91=8D=F0=9F=8F=BB=F0=9F=8E=89=F0=9F=98=95=20?= =?UTF-8?q?reactions=20to=20fix-linting=20bot=20action""?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 3fe5bf21d6abede75dc2203f991c511cb5ebc975. --- CHANGELOG.md | 2 ++ nf_core/create.py | 26 +++++++++++--- nf_core/create_logo.py | 78 ++++++++++++++++++++++++------------------ 3 files changed, 69 insertions(+), 37 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c8da9cdef..51afe36aeb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ - Remove `nfcore_external_java_deps.jar` from lib directory in pipeline template ([#2675](https://github.com/nf-core/tools/pull/2675)) - Add function to check `-profile` is well formatted ([#2678](https://github.com/nf-core/tools/pull/2678)) - Add new pipeline error message pointing to docs when 'requirement exceeds available memory' error message ([#2680](https://github.com/nf-core/tools/pull/2680)) +- add 👀👍🏻🎉😕 reactions to fix-linting-bot action ([#2692](https://github.com/nf-core/tools/pull/2692)) ### Download @@ -23,6 +24,7 @@ - environment.yml name must be lowercase ([#2676](https://github.com/nf-core/tools/pull/2676)) - lint `nextflow.config` default values match the ones specified in `nextflow_schema.json` ([#2684](https://github.com/nf-core/tools/pull/2684)) + ### Modules - Fix empty json output for `nf-core list local` ([#2668](https://github.com/nf-core/tools/pull/2668)) 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 a45e60533e28086fe25cdef93aa22128659142a7 Mon Sep 17 00:00:00 2001 From: nf-core-bot Date: Fri, 26 Jan 2024 15:38:49 +0000 Subject: [PATCH 4/6] [automated] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 51afe36aeb..268cf097ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,7 +23,7 @@ - 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)) - lint `nextflow.config` default values match the ones specified in `nextflow_schema.json` ([#2684](https://github.com/nf-core/tools/pull/2684)) - +- Nicer lint bot comment again ([#2694](https://github.com/nf-core/tools/pull/2694)) ### Modules From a45dc71570d6f99df4c64c4e4fb9a990dad9bf39 Mon Sep 17 00:00:00 2001 From: mashehu Date: Fri, 26 Jan 2024 16:39:05 +0100 Subject: [PATCH 5/6] fix linting --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 51afe36aeb..3a7508ec61 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,7 +24,6 @@ - environment.yml name must be lowercase ([#2676](https://github.com/nf-core/tools/pull/2676)) - lint `nextflow.config` default values match the ones specified in `nextflow_schema.json` ([#2684](https://github.com/nf-core/tools/pull/2684)) - ### Modules - Fix empty json output for `nf-core list local` ([#2668](https://github.com/nf-core/tools/pull/2668)) From 91f1d3ca90c46e10e1da458e8f1569eb13d81e84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20H=C3=B6rtenhuber?= Date: Fri, 26 Jan 2024 16:39:42 +0100 Subject: [PATCH 6/6] Update CHANGELOG.md --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 268cf097ac..3a7508ec61 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,7 +23,6 @@ - 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)) - lint `nextflow.config` default values match the ones specified in `nextflow_schema.json` ([#2684](https://github.com/nf-core/tools/pull/2684)) -- Nicer lint bot comment again ([#2694](https://github.com/nf-core/tools/pull/2694)) ### Modules