Skip to content

Commit a6435a8

Browse files
committed
Remove vulnerable PR-comment artifact pattern
These files conflicted with the patch and were reset wholesale to the nf-core/tools 4.0.3 template version, on the basis that they carry no pipeline-specific content. If this branch had local edits in them, those edits are gone — please review: .github/workflows/branch.yml .github/workflows/template-version-comment.yml
1 parent 79724da commit a6435a8

7 files changed

Lines changed: 201 additions & 96 deletions

File tree

.github/workflows/branch.yml

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,61 @@ name: nf-core branch protection
22
# This workflow is triggered on PRs to `main`/`master` branch on the repository
33
# It fails when someone tries to make a PR against the nf-core `main`/`master` branch instead of `dev`
44
on:
5-
pull_request_target:
5+
pull_request:
66
branches:
77
- main
88
- master
99

10+
permissions: {}
11+
1012
jobs:
1113
test:
1214
runs-on: ubuntu-latest
1315
steps:
1416
# PRs to the nf-core repo main/master branch are only ok if coming from the nf-core repo `dev` or any `patch` branches
1517
- name: Check PRs
1618
if: github.repository == 'nf-core/multiplesequencealign'
19+
env:
20+
HEAD_REPO: ${{ github.event.pull_request.head.repo.full_name }}
1721
run: |
18-
{ [[ ${{github.event.pull_request.head.repo.full_name }} == nf-core/multiplesequencealign ]] && [[ $GITHUB_HEAD_REF == "dev" ]]; } || [[ $GITHUB_HEAD_REF == "patch" ]]
22+
{ [[ "$HEAD_REPO" == nf-core/multiplesequencealign ]] && [[ $GITHUB_HEAD_REF == "dev" ]]; } || [[ $GITHUB_HEAD_REF == "patch" ]]
1923
20-
# If the above check failed, post a comment on the PR explaining the failure
21-
# NOTE - this doesn't currently work if the PR is coming from a fork, due to limitations in GitHub actions secrets
22-
- name: Post PR comment
24+
# If the above check failed, build a comment to be posted by the shared poster workflow
25+
- name: Build PR comment
2326
if: failure()
24-
uses: mshick/add-pr-comment@b8f338c590a895d50bcbfa6c5859251edc8952fc # v2
25-
with:
26-
message: |
27-
## This PR is against the `${{github.event.pull_request.base.ref}}` branch :x:
27+
env:
28+
PR_NUMBER: ${{ github.event.pull_request.number }}
29+
BASE_REF: ${{ github.event.pull_request.base.ref }}
30+
HEAD_REPO: ${{ github.event.pull_request.head.repo.full_name }}
31+
PR_USER: ${{ github.event.pull_request.user.login }}
32+
run: |
33+
mkdir -p pr-comment
34+
echo "$PR_NUMBER" > pr-comment/pr_number.txt
35+
echo "branch" > pr-comment/header.txt
36+
cat > pr-comment/comment.md <<EOF
37+
## This PR is against the \`${BASE_REF}\` branch :x:
2838
29-
* Do not close this PR
30-
* Click _Edit_ and change the `base` to `dev`
31-
* This CI test will remain failed until you push a new commit
39+
* Do not close this PR
40+
* Click _Edit_ and change the \`base\` to \`dev\`
41+
* This CI test will remain failed until you push a new commit
3242
33-
---
43+
---
3444
35-
Hi @${{ github.event.pull_request.user.login }},
45+
Hi @${PR_USER},
3646
37-
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.
38-
The ${{github.event.pull_request.base.ref}} branch on nf-core repositories should always contain code from the latest release.
39-
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.
47+
It looks like this pull-request is has been made against the [${HEAD_REPO}](https://github.com/${HEAD_REPO}) ${BASE_REF} branch.
48+
The ${BASE_REF} branch on nf-core repositories should always contain code from the latest release.
49+
Because of this, PRs to ${BASE_REF} are only allowed if they come from the [${HEAD_REPO}](https://github.com/${HEAD_REPO}) \`dev\` branch.
4050
41-
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.
42-
Note that even after this, the test will continue to show as failing until you push a new commit.
51+
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.
52+
Note that even after this, the test will continue to show as failing until you push a new commit.
4353
44-
Thanks again for your contribution!
45-
repo-token: ${{ secrets.GITHUB_TOKEN }}
46-
allow-repeats: false
54+
Thanks again for your contribution!
55+
EOF
56+
57+
- name: Upload PR comment artifact
58+
if: failure()
59+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
60+
with:
61+
name: pr-comment
62+
path: pr-comment/

.github/workflows/linting.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,21 @@ jobs:
8181
lint_log.txt
8282
lint_results.md
8383
PR_number.txt
84+
85+
# Build a comment for the shared pr-comment.yml poster to publish on the PR
86+
- name: Prepare PR comment
87+
if: ${{ always() }}
88+
env:
89+
PR_NUMBER: ${{ github.event.pull_request.number }}
90+
run: |
91+
mkdir -p pr-comment
92+
echo "$PR_NUMBER" > pr-comment/pr_number.txt
93+
echo "lint" > pr-comment/header.txt
94+
[ -f lint_results.md ] && cp lint_results.md pr-comment/comment.md || true
95+
96+
- name: Upload PR comment artifact
97+
if: ${{ always() }}
98+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
99+
with:
100+
name: pr-comment
101+
path: pr-comment/

.github/workflows/linting_comment.yml

Lines changed: 0 additions & 28 deletions
This file was deleted.

.github/workflows/pr-comment.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Post PR comment
2+
# Shared, privileged comment poster.
3+
#
4+
# This is the single workflow that runs with a write token. It is triggered
5+
# after any of the listed "producer" workflows complete on a pull request.
6+
# Each producer runs untrusted PR code (if any) with a read-only token and
7+
# uploads a `pr-comment` artifact describing the comment to post; this workflow
8+
# only ever reads that plain-text artifact, so no PR code is executed here.
9+
#
10+
# Artifact contract (uploaded by producers under the name `pr-comment`):
11+
# pr_number.txt - the pull request number
12+
# header.txt - sticky-comment identifier (keeps comment types separate)
13+
# comment.md - the Markdown body (omit the file to post nothing)
14+
15+
on:
16+
workflow_run:
17+
workflows:
18+
- "nf-core linting"
19+
- "nf-core template version comment"
20+
- "nf-core branch protection"
21+
- "Run nf-test"
22+
23+
permissions:
24+
actions: read
25+
contents: read
26+
pull-requests: write
27+
28+
jobs:
29+
post-comment:
30+
runs-on: ubuntu-latest
31+
if: github.event.workflow_run.event == 'pull_request'
32+
steps:
33+
- name: Download PR comment artifact
34+
uses: dawidd6/action-download-artifact@b6e2e70617bc3265edd6dab6c906732b2f1ae151 # v21
35+
with:
36+
run_id: ${{ github.event.workflow_run.id }}
37+
name: pr-comment
38+
path: pr-comment
39+
if_no_artifact_found: ignore
40+
41+
- name: Read comment metadata
42+
id: meta
43+
run: |
44+
echo "::group::Downloaded pr-comment contents"
45+
ls -la pr-comment 2>/dev/null || echo "No pr-comment/ directory was downloaded."
46+
echo "::endgroup::"
47+
48+
if [ ! -d pr-comment ]; then
49+
echo "No pr-comment artifact found; nothing to post."
50+
exit 0
51+
fi
52+
53+
if [ ! -f pr-comment/comment.md ]; then
54+
echo "Artifact present but no comment.md; nothing to post."
55+
exit 0
56+
fi
57+
58+
pr_number=$(cat pr-comment/pr_number.txt)
59+
header=$(cat pr-comment/header.txt)
60+
echo "Found comment.md (header='$header', pr_number='$pr_number')."
61+
62+
# Guard against anything unexpected ending up in the PR number.
63+
case "$pr_number" in
64+
''|*[!0-9]*)
65+
echo "Invalid PR number: '$pr_number'"
66+
exit 1
67+
;;
68+
esac
69+
70+
echo "pr_number=$pr_number" >> "$GITHUB_OUTPUT"
71+
echo "header=$header" >> "$GITHUB_OUTPUT"
72+
echo "post=true" >> "$GITHUB_OUTPUT"
73+
echo "Will post comment to PR #${pr_number}."
74+
75+
- name: Post PR comment
76+
if: steps.meta.outputs.post == 'true'
77+
uses: marocchino/sticky-pull-request-comment@5770ad5eb8f42dd2c4f34da00c94c5381e49af88 # v3.0.5
78+
with:
79+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
80+
number: ${{ steps.meta.outputs.pr_number }}
81+
header: ${{ steps.meta.outputs.header }}
82+
path: pr-comment/comment.md
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: nf-core template version comment
2+
# This workflow is triggered on PRs to check if the pipeline template version matches the latest nf-core version.
3+
# It posts a comment to the PR, even if it comes from a fork.
4+
5+
on:
6+
pull_request:
7+
8+
permissions: {}
9+
10+
jobs:
11+
check_template_version:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Check out pipeline code
15+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
16+
with:
17+
ref: ${{ github.event.pull_request.head.sha }}
18+
19+
- name: Read template version from .nf-core.yml
20+
uses: nichmor/minimal-read-yaml@1f7205277e25e156e1f63815781db80a6d490b8f # v0.0.2
21+
id: read_yml
22+
with:
23+
config: ${{ github.workspace }}/.nf-core.yml
24+
25+
- name: Install nf-core
26+
run: |
27+
python -m pip install --upgrade pip
28+
pip install nf-core
29+
30+
- name: Build PR comment if template is outdated
31+
# The fork-controlled version is passed via the environment and only ever
32+
# used as quoted shell data (never interpolated into a command), so it
33+
# cannot be used for script injection.
34+
env:
35+
PR_VERSION: ${{ steps.read_yml.outputs['nf_core_version'] }}
36+
PR_NUMBER: ${{ github.event.pull_request.number }}
37+
run: |
38+
mkdir -p pr-comment
39+
echo "$PR_NUMBER" > pr-comment/pr_number.txt
40+
echo "template-version" > pr-comment/header.txt
41+
42+
latest_version=$(nf-core --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -n1)
43+
44+
if [ -n "$PR_VERSION" ] && [ -n "$latest_version" ] && [ "$PR_VERSION" != "$latest_version" ]; then
45+
cat > pr-comment/comment.md <<EOF
46+
> [!WARNING]
47+
> Newer version of the nf-core template is available.
48+
>
49+
> Your pipeline is using an old version of the nf-core template: ${PR_VERSION}.
50+
> Please update your pipeline to the latest version.
51+
>
52+
> For more documentation on how to update your pipeline, please see the [Synchronisation documentation](https://nf-co.re/docs/developing/template-syncs/overview).
53+
EOF
54+
fi
55+
56+
- name: Upload PR comment artifact
57+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
58+
with:
59+
name: pr-comment
60+
path: pr-comment/

.github/workflows/template_version_comment.yml

Lines changed: 0 additions & 46 deletions
This file was deleted.

.nf-core.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ lint:
33
files_exist:
44
- conf/igenomes.config
55
- conf/igenomes_ignored.config
6+
- .github/workflows/linting_comment.yml
67
files_unchanged:
78
- .github/CONTRIBUTING.md
9+
- .github/workflows/branch.yml
10+
- .github/workflows/linting.yml
811
multiqc_config: false
912
nf_core_version: 3.2.1
1013
repository_type: pipeline

0 commit comments

Comments
 (0)