Skip to content

Commit

Permalink
Revert "template: add 👀👍🏻🎉😕 reactions to fix-linting bot action"
Browse files Browse the repository at this point in the history
  • Loading branch information
mashehu committed Jan 26, 2024
1 parent 5a2ce1b commit 3fe5bf2
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 126 deletions.
21 changes: 13 additions & 8 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:
fix-linting:
deploy:
# 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,25 +63,30 @@ 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'
if: ${{ steps.commit-and-push.outcome }} == 'failure' && ${{ steps.react-if-fixed.outcome }} != 'success'
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
if: ${{ steps.commit-and-push.outcome }} == 'failure' && ${{ steps.react-if-fixed.outcome }} != 'success'
uses: peter-evans/create-or-update-comment@v3
with:
issue-number: ${{ github.event.issue.number }}
body: |
Expand Down
2 changes: 0 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
- 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 All @@ -24,7 +23,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))
Expand Down
26 changes: 4 additions & 22 deletions nf_core/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,12 +505,10 @@ 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", force=self.force)
create_logo(text=self.template_params["short_name"], dir=email_logo_path, theme="light")
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, force=self.force
)
create_logo(text=self.template_params["short_name"], dir=readme_logo_path, width=600, theme=theme)

def git_init_pipeline(self):
"""Initialises the new pipeline as a Git repository and submits first commit.
Expand Down Expand Up @@ -539,24 +537,8 @@ 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)
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)
repo.git.branch("TEMPLATE")
repo.git.branch("dev")
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: 33 additions & 45 deletions nf_core/create_logo.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from PIL import Image, ImageDraw, ImageFont

import nf_core
from nf_core.utils import NFCORE_CACHE_DIR

log = logging.getLogger(__name__)

Expand All @@ -27,6 +26,7 @@ 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,56 +51,44 @@ 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
# 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")

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
img.save(logo_path, "PNG")

Expand Down
57 changes: 8 additions & 49 deletions nf_core/pipeline-template/.github/workflows/fix-linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,77 +13,36 @@ jobs:
runs-on: ubuntu-latest
steps:
# Use the @nf-core-bot token to check out so we can push later
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
- uses: actions/checkout@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 }}

# Install and run pre-commit
- uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: 3.11
cache: "pip"

- name: Install pre-commit
run: pip install pre-commit

- name: Run pre-commit
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"
run: pre-commit run --all-files || echo "status=fail" >> $GITHUB_ENV

- name: Commit & push changes
id: commit-and-push
if: steps.pre-commit.outcome == 'failure'
if: env.status == 'fail'
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 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 %}
git commit -m "[automated] Fix linting with pre-commit"
git push {%- endraw %}

0 comments on commit 3fe5bf2

Please sign in to comment.