Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow skipping node version-1 in unit tests #126

Merged
merged 1 commit into from
Aug 29, 2024
Merged

Conversation

iowillhoit
Copy link
Contributor

@iowillhoit iowillhoit commented Aug 29, 2024

Allows you to disable the node version-1 in unit tests

You would enable this feature by setting UT_DISABLE_NODE_PREVIOUS in your Github org's (or repo's) Action Variables (docs for org)

@W-16617566@

Here is a script for QA. Run source theFile.sh

#!/bin/sh

test() {
    NODE_VERSION_CURRENT="current"
    if [ "$INPUTS_NODE_DISABLE_CURRENT" = "true" ] || [ -n "$INPUTS_NODE_VERSION_OVERRIDE" ]; then
        NODE_VERSION_CURRENT=""
    fi

    NODE_VERSION="lts/*"
    if [ -n "$INPUTS_NODE_VERSION_OVERRIDE" ]; then
        NODE_VERSION="$INPUTS_NODE_VERSION_OVERRIDE"
    fi

    NODE_PREVIOUS_LTS="lts/-1"
    if [ "$INPUTS_NODE_DISABLE_PREVIOUS" = "true" ]; then
        NODE_PREVIOUS_LTS=""
    fi

    if [ -n "$INPUTS_NODE_VERSION_OVERRIDE" ] && [ "$INPUTS_NODE_DISABLE_PREVIOUS" != "true" ] ; then
        NODE_VERSION_MAJOR=$(echo "$INPUTS_NODE_VERSION_OVERRIDE" | cut -d '.' -f 1)
        # LTS-1 will always be the previous LTS, which is always even. Here we calculate the nearest LTS
        if [ $((NODE_VERSION_MAJOR % 2)) = 0 ]; then
        NODE_PREVIOUS_LTS="$((NODE_VERSION_MAJOR - 2))"
        else
        NODE_PREVIOUS_LTS="$((NODE_VERSION_MAJOR - 1))"
        fi
    fi

    echo "nodeVersions<<EOF"
        jq -n --arg v1 "$NODE_VERSION_CURRENT" --arg v2 "$NODE_VERSION" --arg v3 "$NODE_PREVIOUS_LTS"  '[$v1, $v2, $v3] | map(select(. != ""))'
    echo "EOF"
}

# [
#   "current",
#   "lts/*",
#   "lts/-1"
# ]
test

# [
#   "current",
#   "lts/*",
# ]
INPUTS_NODE_DISABLE_PREVIOUS="true"
test
unset INPUTS_NODE_DISABLE_PREVIOUS


# [
#   "lts/*",
#   "lts/-1"
# ]
INPUTS_NODE_DISABLE_CURRENT="true"
test
unset INPUTS_NODE_DISABLE_CURRENT


# [
#   "lts/*"
# ]
INPUTS_NODE_DISABLE_CURRENT="true"
INPUTS_NODE_DISABLE_PREVIOUS="true"
test
unset INPUTS_NODE_DISABLE_CURRENT
unset INPUTS_NODE_DISABLE_PREVIOUS


# [
#   "16"
# ]
INPUTS_NODE_DISABLE_CURRENT="true"
INPUTS_NODE_DISABLE_PREVIOUS="true"
INPUTS_NODE_VERSION_OVERRIDE="16.17.0"
test
unset INPUTS_NODE_DISABLE_CURRENT
unset INPUTS_NODE_DISABLE_PREVIOUS
unset INPUTS_NODE_VERSION_OVERRIDE

# [
#   "14",
#   "12"
# ]
INPUTS_NODE_VERSION_OVERRIDE="14"
test
unset INPUTS_NODE_VERSION_OVERRIDE

Copy link

@nvuillam nvuillam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonderful ❤️

else
jq -n --arg v1 "$NODE_VERSION" --arg v2 "$NODE_PREVIOUS_LTS" '[$v1, $v2]'
fi
jq -n --arg v1 "$NODE_VERSION_CURRENT" --arg v2 "$NODE_VERSION" --arg v3 "$NODE_PREVIOUS_LTS" '[$v1, $v2, $v3] | map(select(. != ""))'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool trick 😎

@cristiand391
Copy link
Member

QA notes:

couldn't QA in our repos b/c of some branch references to main:
https://github.com/salesforcecli/plugin-data/actions/runs/10619524051/job/29437311728

✅ followed QA script, scenarios look good
✅ tested varios combination of values, jq always filter empty values and version overrides look good.

@cristiand391 cristiand391 merged commit c79b9ba into main Aug 29, 2024
2 checks passed
@iowillhoit iowillhoit deleted the ew/skip-node-minus branch August 29, 2024 17:37
@nvuillam
Copy link

nvuillam commented Aug 29, 2024

It works on my repo by defining UT_DISABLE_NODE_PREVIOUS="true" in repository variables, thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants