Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nicer lint bot comment again #2694

Merged
merged 8 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions .github/workflows/fix-linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/') &&
Expand Down Expand Up @@ -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"
Expand All @@ -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: |
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
26 changes: 22 additions & 4 deletions nf_core/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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"
Expand Down
78 changes: 45 additions & 33 deletions nf_core/create_logo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand All @@ -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":
Expand All @@ -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")

Expand Down
59 changes: 50 additions & 9 deletions nf_core/pipeline-template/.github/workflows/fix-linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/') &&
Expand All @@ -13,36 +13,77 @@ 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
run: gh pr checkout ${{ github.event.issue.number }}
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 %}
Loading