Feature Request
complete
I
Increased Kite
I’d like to request support for a built-in utility or plugin in Harness CI that replicates the behavior of the
nrwl/nx-set-shas
GitHub Action. The purpose of this utility is to accurately determine the NX_BASE
and NX_HEAD
SHAs required to run nx affected
commands during CI pipelines.This is a common need in monorepo setups using Nx, and the existing GitHub Action cannot be used as-is in Harness due to its dependency on
github.context
. While we can work around this with shell scripts and GitHub API calls, having an official plugin or step in Harness would:Eliminate boilerplate scripting
Avoid external GitHub Action dependencies
Improve reliability and native developer experience for Nx monorepos
Simplify onboarding for teams migrating from GitHub Actions
Desired Behavior:
When running on a feature branch, compute NX_BASE from the last successful pipeline run on
When running on main, compute NX_BASE from the previous successful main run
Expose NX_BASE and NX_HEAD as output variables
Log In
s
shivkumar.loka
complete
s
shivkumar.loka
The following script was tested and provided to be used in a step template:
```# Fetch all remote branches
git fetch origin '+refs/heads/
:refs/remotes/origin/
'Calculate NX_HEAD
NX_HEAD=$(git rev-parse HEAD)
echo "NX_HEAD: $NX_HEAD"
Determine CURRENT_BRANCH and TARGET_BRANCH
CURRENT_BRANCH="<+trigger.sourceBranch>"
TARGET_BRANCH="<+trigger.targetBranch>"
Fallback to git commands if variables are missing or null
if [ -z "$CURRENT_BRANCH" ] || [ "$CURRENT_BRANCH" = "null" ]; then
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
fi
if [ -z "$TARGET_BRANCH" ] || [ "$TARGET_BRANCH" = "null" ]; then
TARGET_BRANCH="main"
fi
echo "Current branch: $CURRENT_BRANCH"
echo "Target branch: $TARGET_BRANCH"
Calculate NX_BASE with fallback logic
if [ "$CURRENT_BRANCH" = "$TARGET_BRANCH" ]; then
Direct push to target branch (main)
NX_BASE=$(git rev-parse HEAD~1)
else
Try merge-base; fallback if it fails
if NX_BASE=$(git merge-base origin/$TARGET_BRANCH HEAD); then
echo "Using merge-base: $NX_BASE"
else
echo "WARNING: merge-base failed, falling back to HEAD~1"
NX_BASE=$(git rev-parse HEAD~1)
fi
fi
echo "NX_BASE: $NX_BASE"
```
Since this solution worked, we will close this request. Request you to reach out via support for further assistance on this topic.
Thank you
Regards
Shivkumar Loka
Product Team
This post was marked as
in progress
N
Nofar Bluestein
under review