Skip to content
Open
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
101 changes: 101 additions & 0 deletions .github/workflows/dev-build-comment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: Dev build comment

# Posts a comment on each pull request with instructions for testing the
# automated dev build of that PR, published by the nextflow-dev-builds repo.
# The comment is created once and then updated in place on each push.
#
# Uses pull_request_target so the comment can also be posted on PRs from
# forks. This is safe because the workflow never checks out or executes any
# code from the PR: it only reads PR metadata and the VERSION file, whose
# content is validated before use.

on:
pull_request_target:
types: [opened, reopened, synchronize]

permissions: {}

concurrency:
group: dev-build-comment-${{ github.event.pull_request.number }}
cancel-in-progress: true

jobs:
comment:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
# Trigger an immediate build instead of waiting for the scheduled run in
# the dev-builds repo. Requires the DEV_BUILDS_DISPATCH_TOKEN secret
# (fine-grained PAT with actions:write on nextflow-dev-builds). Failure
# is reported in the PR comment but never blocks anything.
- name: Trigger dev build
id: dispatch
env:
GH_TOKEN: ${{ secrets.DEV_BUILDS_DISPATCH_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
DEV_REPO: nextflow-io/nextflow-dev-builds
run: |
set -euo pipefail
if [ -z "$GH_TOKEN" ]; then
echo "::notice::DEV_BUILDS_DISPATCH_TOKEN is not set, the scheduled build will pick up this push instead"
echo "status=scheduled" >> "$GITHUB_OUTPUT"
elif gh workflow run build.yml -R "$DEV_REPO" -f pr="$PR_NUMBER"; then
echo "status=triggered" >> "$GITHUB_OUTPUT"
else
echo "::warning::Failed to trigger dev build in $DEV_REPO, the scheduled build will pick up this push instead"
echo "status=failed" >> "$GITHUB_OUTPUT"
fi

- name: Create or update comment
env:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
DEV_REPO: nextflow-io/nextflow-dev-builds
MARKER: '<!-- dev-build-comment -->'
DISPATCH_STATUS: ${{ steps.dispatch.outputs.status }}
run: |
set -euo pipefail
base=$(gh api "repos/$GITHUB_REPOSITORY/contents/VERSION?ref=$HEAD_SHA" --jq .content | base64 -d | tr -d '[:space:]')
version="${base}-pr-${PR_NUMBER}-${HEAD_SHA:0:7}"

case "$DISPATCH_STATUS" in
triggered) timing="shortly (build triggered automatically)" ;;
failed) timing="within about 30 minutes (automatic build trigger failed, falling back to the scheduled build)" ;;
*) timing="within about 30 minutes (next scheduled build)" ;;
esac
# the VERSION file in a PR is attacker-controlled, so only allow safe characters
if [[ ! "$version" =~ ^[A-Za-z0-9.\-]+$ ]]; then
echo "unsafe version string '$version', skipping comment"
exit 0
fi
body=$(cat <<EOF
$MARKER
## 📦 Nextflow dev build

A development build of this PR (commit \`${HEAD_SHA:0:7}\`) will be [published](https://github.com/$DEV_REPO/releases/tag/v${version}) ${timing}. Test it with:

\`\`\`bash
NXF_DEV=pr-${PR_NUMBER} nextflow run <pipeline>
\`\`\`

Or, with Nextflow versions that don't support \`NXF_DEV\` yet:

\`\`\`bash
NXF_BASE=https://github.com/$DEV_REPO/releases/download \\
NXF_VER=${version} \\
nextflow run <pipeline>
\`\`\`

For testing purposes only. See [$DEV_REPO](https://github.com/$DEV_REPO) for details. This comment is updated on each push.
EOF
)

comment_id=$(gh api "repos/$GITHUB_REPOSITORY/issues/$PR_NUMBER/comments?per_page=100" --paginate \
--jq '[.[] | select(.body | startswith(env.MARKER)) | .id] | first // empty' | head -n1)
if [ -n "$comment_id" ]; then
gh api --silent -X PATCH "repos/$GITHUB_REPOSITORY/issues/comments/$comment_id" -f body="$body"
else
gh api --silent -X POST "repos/$GITHUB_REPOSITORY/issues/$PR_NUMBER/comments" -f body="$body"
fi
34 changes: 34 additions & 0 deletions .github/workflows/dev-build-dispatch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Dev build dispatch

# Triggers an immediate dev build of master in nextflow-io/nextflow-dev-builds
# on each push, instead of waiting for the scheduled build there.
#
# Requires the DEV_BUILDS_DISPATCH_TOKEN secret (fine-grained PAT with
# actions:write on the nextflow-dev-builds repo). Without it, the push is
# picked up by the scheduled build within about 30 minutes.

on:
push:
branches: [master]

permissions: {}

jobs:
dispatch:
runs-on: ubuntu-latest
steps:
- name: Trigger dev build of master
env:
GH_TOKEN: ${{ secrets.DEV_BUILDS_DISPATCH_TOKEN }}
DEV_REPO: nextflow-io/nextflow-dev-builds
run: |
set -euo pipefail
if [ -z "$GH_TOKEN" ]; then
echo "::notice::DEV_BUILDS_DISPATCH_TOKEN is not set, the scheduled build in $DEV_REPO will pick up this push within about 30 minutes"
exit 0
fi
if gh workflow run build.yml -R "$DEV_REPO" -f branch=master; then
echo "dev build of master triggered in $DEV_REPO"
else
echo "::warning::Failed to trigger dev build in $DEV_REPO, the scheduled build will pick up this push within about 30 minutes"
fi
5 changes: 5 additions & 0 deletions docs/reference/env-vars.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ The following environment variables control the configuration of the Nextflow ru
:::
: Defines the DSL version that should be used in not specified otherwise in the script of config file (default: `2`)

`NXF_DEV`
: :::{versionadded} 26.05.0-edge
:::
: Use an automated development build of Nextflow, for testing purposes only. Set to `master` for the latest build of the master branch, or `pr-<number>` for the latest build of a pull request. Builds are published in the [nextflow-dev-builds](https://github.com/nextflow-io/nextflow-dev-builds) repository.

`NXF_DISABLE_CHECK_LATEST`
: :::{versionadded} 23.09.0-edge
:::
Expand Down
21 changes: 21 additions & 0 deletions nextflow
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,26 @@
#

[[ "$NXF_DEBUG" == 'x' ]] && set -x

# NXF_DEV selects an automated development build, for testing purposes only:
# `NXF_DEV=master` for the latest build of the master branch, `NXF_DEV=pr-1234`
# for the latest build of a pull request. See the repository below for details.
if [[ $NXF_DEV ]]; then
NXF_DEV_REPO=${NXF_DEV_REPO:-'https://github.com/nextflow-io/nextflow-dev-builds'}
NXF_BASE=${NXF_BASE:-$NXF_DEV_REPO/releases/download}
if [[ ! $NXF_VER ]]; then
if command -v curl &>/dev/null; then
NXF_VER=$(curl -fsSL "$NXF_DEV_REPO/raw/master/latest/$NXF_DEV" 2>/dev/null)
elif command -v wget &>/dev/null; then
NXF_VER=$(wget -qO- "$NXF_DEV_REPO/raw/master/latest/$NXF_DEV" 2>/dev/null)
fi
if [[ ! $NXF_VER ]]; then
>&2 echo "ERROR: Cannot find a Nextflow dev build for '$NXF_DEV' -- check $NXF_DEV_REPO"
exit 1
fi
fi
fi

NXF_VER=${NXF_VER:-'26.04.3'}
NXF_ORG=${NXF_ORG:-'nextflow-io'}
NXF_HOME=${NXF_HOME:-$HOME/.nextflow}
Expand Down Expand Up @@ -264,6 +284,7 @@ while [[ $# != 0 ]]; do
;;
-self-update|self-update)
if [[ ! "$cmd" ]]; then
[[ $NXF_DEV ]] && die "Cannot self-update when NXF_DEV is set -- unset it and try again"
[[ -z $NXF_EDGE && $NXF_VER = *-edge ]] && NXF_EDGE=1
unset NXF_VER
install "$0" update
Expand Down
Loading