Skip to content
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
60 changes: 38 additions & 22 deletions .github/workflows/branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,61 @@ name: nf-core branch protection
# This workflow is triggered on PRs to `main`/`master` branch on the repository
# It fails when someone tries to make a PR against the nf-core `main`/`master` branch instead of `dev`
on:
pull_request_target:
pull_request:
branches:
- main
- master

permissions: {}

jobs:
test:
runs-on: ubuntu-latest
steps:
# PRs to the nf-core repo main/master branch are only ok if coming from the nf-core repo `dev` or any `patch` branches
- name: Check PRs
if: github.repository == 'nf-core/deepmodeloptim'
env:
HEAD_REPO: ${{ github.event.pull_request.head.repo.full_name }}
run: |
{ [[ ${{github.event.pull_request.head.repo.full_name }} == nf-core/deepmodeloptim ]] && [[ $GITHUB_HEAD_REF == "dev" ]]; } || [[ $GITHUB_HEAD_REF == "patch" ]]
{ [[ "$HEAD_REPO" == nf-core/deepmodeloptim ]] && [[ $GITHUB_HEAD_REF == "dev" ]]; } || [[ $GITHUB_HEAD_REF == "patch" ]]

# If the above check failed, post a comment on the PR explaining the failure
# NOTE - this doesn't currently work if the PR is coming from a fork, due to limitations in GitHub actions secrets
- name: Post PR comment
# If the above check failed, build a comment to be posted by the shared poster workflow
- name: Build PR comment
if: failure()
uses: mshick/add-pr-comment@b8f338c590a895d50bcbfa6c5859251edc8952fc # v2
with:
message: |
## This PR is against the `${{github.event.pull_request.base.ref}}` branch :x:
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
BASE_REF: ${{ github.event.pull_request.base.ref }}
HEAD_REPO: ${{ github.event.pull_request.head.repo.full_name }}
PR_USER: ${{ github.event.pull_request.user.login }}
run: |
mkdir -p pr-comment
echo "$PR_NUMBER" > pr-comment/pr_number.txt
echo "branch" > pr-comment/header.txt
cat > pr-comment/comment.md <<EOF
## This PR is against the \`${BASE_REF}\` branch :x:

* Do not close this PR
* Click _Edit_ and change the `base` to `dev`
* This CI test will remain failed until you push a new commit
* Do not close this PR
* Click _Edit_ and change the \`base\` to \`dev\`
* This CI test will remain failed until you push a new commit

---
---

Hi @${{ github.event.pull_request.user.login }},
Hi @${PR_USER},

It looks like this pull-request is has been made against the [${{github.event.pull_request.head.repo.full_name }}](https://github.com/${{github.event.pull_request.head.repo.full_name }}) ${{github.event.pull_request.base.ref}} branch.
The ${{github.event.pull_request.base.ref}} branch on nf-core repositories should always contain code from the latest release.
Because of this, PRs to ${{github.event.pull_request.base.ref}} are only allowed if they come from the [${{github.event.pull_request.head.repo.full_name }}](https://github.com/${{github.event.pull_request.head.repo.full_name }}) `dev` branch.
It looks like this pull-request is has been made against the [${HEAD_REPO}](https://github.com/${HEAD_REPO}) ${BASE_REF} branch.
The ${BASE_REF} branch on nf-core repositories should always contain code from the latest release.
Because of this, PRs to ${BASE_REF} are only allowed if they come from the [${HEAD_REPO}](https://github.com/${HEAD_REPO}) \`dev\` branch.

You do not need to close this PR, you can change the target branch to `dev` by clicking the _"Edit"_ button at the top of this page.
Note that even after this, the test will continue to show as failing until you push a new commit.
You do not need to close this PR, you can change the target branch to \`dev\` by clicking the _"Edit"_ button at the top of this page.
Note that even after this, the test will continue to show as failing until you push a new commit.

Thanks again for your contribution!
repo-token: ${{ secrets.GITHUB_TOKEN }}
allow-repeats: false
Thanks again for your contribution!
EOF

- name: Upload PR comment artifact
if: failure()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: pr-comment
path: pr-comment/
18 changes: 18 additions & 0 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,21 @@ jobs:
lint_log.txt
lint_results.md
PR_number.txt

# Build a comment for the shared pr-comment.yml poster to publish on the PR
- name: Prepare PR comment
if: ${{ always() }}
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
mkdir -p pr-comment
echo "$PR_NUMBER" > pr-comment/pr_number.txt
echo "lint" > pr-comment/header.txt
[ -f lint_results.md ] && cp lint_results.md pr-comment/comment.md || true

- name: Upload PR comment artifact
if: ${{ always() }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: pr-comment
path: pr-comment/
28 changes: 0 additions & 28 deletions .github/workflows/linting_comment.yml

This file was deleted.

82 changes: 82 additions & 0 deletions .github/workflows/pr-comment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Post PR comment
# Shared, privileged comment poster.
#
# This is the single workflow that runs with a write token. It is triggered
# after any of the listed "producer" workflows complete on a pull request.
# Each producer runs untrusted PR code (if any) with a read-only token and
# uploads a `pr-comment` artifact describing the comment to post; this workflow
# only ever reads that plain-text artifact, so no PR code is executed here.
#
# Artifact contract (uploaded by producers under the name `pr-comment`):
# pr_number.txt - the pull request number
# header.txt - sticky-comment identifier (keeps comment types separate)
# comment.md - the Markdown body (omit the file to post nothing)

on:
workflow_run:
workflows:
- "nf-core linting"
- "nf-core template version comment"
- "nf-core branch protection"
- "Run nf-test"

permissions:
actions: read
contents: read
pull-requests: write

jobs:
post-comment:
runs-on: ubuntu-latest
if: github.event.workflow_run.event == 'pull_request'
steps:
- name: Download PR comment artifact
uses: dawidd6/action-download-artifact@b6e2e70617bc3265edd6dab6c906732b2f1ae151 # v21
with:
run_id: ${{ github.event.workflow_run.id }}
name: pr-comment
path: pr-comment
if_no_artifact_found: ignore

- name: Read comment metadata
id: meta
run: |
echo "::group::Downloaded pr-comment contents"
ls -la pr-comment 2>/dev/null || echo "No pr-comment/ directory was downloaded."
echo "::endgroup::"

if [ ! -d pr-comment ]; then
echo "No pr-comment artifact found; nothing to post."
exit 0
fi

if [ ! -f pr-comment/comment.md ]; then
echo "Artifact present but no comment.md; nothing to post."
exit 0
fi

pr_number=$(cat pr-comment/pr_number.txt)
header=$(cat pr-comment/header.txt)
echo "Found comment.md (header='$header', pr_number='$pr_number')."

# Guard against anything unexpected ending up in the PR number.
case "$pr_number" in
''|*[!0-9]*)
echo "Invalid PR number: '$pr_number'"
exit 1
;;
esac

echo "pr_number=$pr_number" >> "$GITHUB_OUTPUT"
echo "header=$header" >> "$GITHUB_OUTPUT"
echo "post=true" >> "$GITHUB_OUTPUT"
echo "Will post comment to PR #${pr_number}."

- name: Post PR comment
if: steps.meta.outputs.post == 'true'
uses: marocchino/sticky-pull-request-comment@5770ad5eb8f42dd2c4f34da00c94c5381e49af88 # v3.0.5
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
number: ${{ steps.meta.outputs.pr_number }}
header: ${{ steps.meta.outputs.header }}
path: pr-comment/comment.md
60 changes: 60 additions & 0 deletions .github/workflows/template-version-comment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: nf-core template version comment
# This workflow is triggered on PRs to check if the pipeline template version matches the latest nf-core version.
# It posts a comment to the PR, even if it comes from a fork.

on:
pull_request:

permissions: {}

jobs:
check_template_version:
runs-on: ubuntu-latest
steps:
- name: Check out pipeline code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Read template version from .nf-core.yml
uses: nichmor/minimal-read-yaml@1f7205277e25e156e1f63815781db80a6d490b8f # v0.0.2
id: read_yml
with:
config: ${{ github.workspace }}/.nf-core.yml

- name: Install nf-core
run: |
python -m pip install --upgrade pip
pip install nf-core

- name: Build PR comment if template is outdated
# The fork-controlled version is passed via the environment and only ever
# used as quoted shell data (never interpolated into a command), so it
# cannot be used for script injection.
env:
PR_VERSION: ${{ steps.read_yml.outputs['nf_core_version'] }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
mkdir -p pr-comment
echo "$PR_NUMBER" > pr-comment/pr_number.txt
echo "template-version" > pr-comment/header.txt

latest_version=$(nf-core --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -n1)

if [ -n "$PR_VERSION" ] && [ -n "$latest_version" ] && [ "$PR_VERSION" != "$latest_version" ]; then
cat > pr-comment/comment.md <<EOF
> [!WARNING]
> Newer version of the nf-core template is available.
>
> Your pipeline is using an old version of the nf-core template: ${PR_VERSION}.
> Please update your pipeline to the latest version.
>
> For more documentation on how to update your pipeline, please see the [Synchronisation documentation](https://nf-co.re/docs/developing/template-syncs/overview).
EOF
fi

- name: Upload PR comment artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: pr-comment
path: pr-comment/
46 changes: 0 additions & 46 deletions .github/workflows/template_version_comment.yml

This file was deleted.

6 changes: 4 additions & 2 deletions .nf-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ lint:
- conf/igenomes_ignored.config
- assets/multiqc_config.yml
- conf/test_full.config
- .github/workflows/linting_comment.yml
files_unchanged:
- .github/CONTRIBUTING.md
- assets/sendmail_template.txt
Expand All @@ -15,15 +16,16 @@ lint:
- assets/nf-core-deepmodeloptim_logo_light.png
- docs/images/nf-core-deepmodeloptim_logo_light.png
- docs/images/nf-core-deepmodeloptim_logo_dark.png
- .github/workflows/branch.yml
- .github/workflows/linting.yml
multiqc_config: false
nextflow_config:
- params.input
nf_core_version: 3.2.0
repository_type: pipeline
template:
author: Mathys Grapotte
description: nf-core/deepmodeloptim is an end-to-end pipeline designed to
facilitate the testing and development of deep learning models for genomics.
description: nf-core/deepmodeloptim is an end-to-end pipeline designed to facilitate the testing and development of deep learning models for genomics.
force: false
is_nfcore: true
name: deepmodeloptim
Expand Down
Loading