Skip to content
28 changes: 28 additions & 0 deletions .github/scripts/nss-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash
# Build the NSS checkout at $NSS_DIR, then build and test nss-rs against it.
# Expects the environment mozilla/actions/nss sets up with 'deps-only'. Also the
# `git bisect run` predicate, so it runs from an arbitrary cwd and must not let
# one revision's artifacts decide the next revision's verdict.
set -o pipefail
Comment thread
larseggert marked this conversation as resolved.
Resolved

: "${NSS_DIR:?set by mozilla/actions/nss}"
: "${NSS_BUILD_FLAGS:?set by mozilla/actions/nss}"
: "${NSS_RS_DIR:?must point at the nss-rs checkout}"

# Or build.rs builds NSS again, with its own flags.
export NSS_PREBUILT=1

# build.rs reads $NSS_DIR/../dist, so a stale tree would mask a failed build.
rm -rf "${NSS_DIR}/../dist" || exit 125
[ "${SCCACHE_CC:-}" ] && [ "${SCCACHE_CXX:-}" ] && export CC="$SCCACHE_CC" CXX="$SCCACHE_CXX"
# Conditional, because an empty CFLAGS on Windows would override MSVC defaults.
[ -n "${NSS_BUILD_CFLAGS:-}" ] && export CFLAGS="$NSS_BUILD_CFLAGS"
# 125 is `git bisect` for "untestable": don't blame a revision NSS can't build.
# shellcheck disable=SC2086
"$NSS_DIR/build.sh" $NSS_BUILD_FLAGS || exit 125

cd "$NSS_RS_DIR" || exit 125
# Nothing tells cargo that dist changed, so force the bindings to regenerate.
cargo clean -p nss-rs || exit 125
Comment on lines +24 to +26

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Warning

The script's own failures reuse 125, which the workflow reads as "NSS head does not build".

cd, cargo clean and the rm -rf on line 16 are environment failures, not "this NSS revision is untestable". Exiting 125 makes the head job set NO_BUILD=true (line 128), which suppresses filing entirely when every failing platform hits it (line 301), and reports "NSS head does not build." in the NSS bug when only some do. A locked file under dist or a cargo clean that loses a race with sccache/AV on the Windows runners is the realistic trigger.

An exit code >= 128 is the right signal for both consumers: git bisect run aborts rather than silently skipping the revision (git-bisect docs: any code outside 0–127 aborts), and the head job no longer mistakes it for an NSS build failure.

Suggested change
cd "$NSS_RS_DIR" || exit 125
# Nothing tells cargo that dist changed, so force the bindings to regenerate.
cargo clean -p nss-rs || exit 125
cd "$NSS_RS_DIR" || exit 128
# Nothing tells cargo that dist changed, so force the bindings to regenerate.
cargo clean -p nss-rs || exit 128

Line 16 wants the same treatment; build.sh on line 22 is the only genuine 125.

cargo test --locked || exit $?
cargo test --locked --features blapi
325 changes: 325 additions & 0 deletions .github/workflows/nss-head.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,325 @@
name: NSS head
on:
schedule:
- cron: "17 5 * * *"
workflow_dispatch:
inputs:
last-good:
description: "NSS commit to bisect from, overriding the cached one."
default: ""
dry-run:
description: "Log the Bugzilla changes instead of making them."
type: boolean
default: false
test-bugzilla:
description: "Report to the Bugzilla dev instance, using BUGZILLA_TEST_API_KEY."
type: boolean
default: false

concurrency:
group: ${{ github.workflow }}

permissions:
contents: read

defaults:
run:
shell: bash

env:
CARGO_TERM_COLOR: never
RUST_BACKTRACE: 1
NSS_REPO: https://github.com/mozilla/nss.git
NSPR_REPO: https://github.com/mozilla/nspr.git

jobs:
# Pinned once, so that every platform reports on the same revision.
setup:
name: Resolve NSS head
runs-on: ubuntu-24.04
outputs:
head: ${{ steps.head.outputs.sha }}
nspr: ${{ steps.head.outputs.nspr }}
steps:
- id: head
run: |
nss=$(git ls-remote "$NSS_REPO" HEAD | cut -f1)
nspr=$(git ls-remote "$NSPR_REPO" HEAD | cut -f1)
if [ -z "$nss" ] || [ -z "$nspr" ]; then
echo "::error::Could not resolve NSS or NSPR HEAD"; exit 1
fi
echo "Testing NSS $nss with NSPR $nspr"
{ echo "sha=$nss"; echo "nspr=$nspr"; } >> "$GITHUB_OUTPUT"

head:
name: NSS head on ${{ matrix.os }}
needs: setup
strategy:
fail-fast: false # Every platform's verdict goes into one report.
matrix:
os:
- ubuntu-24.04
- ubuntu-24.04-arm
- macos-15
- windows-2025
- ubuntu-22.04
- macos-14
- windows-2022
runs-on: ${{ matrix.os }}
# A bisect over a release's worth of NSS commits is ~7 from-scratch builds.
timeout-minutes: 330
env:
# NSS_DIR, NSS_PREBUILT and NSS_BUILD_FLAGS come from mozilla/actions/nss.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Note

Stale after the last round: nss-check.sh exports NSS_PREBUILT itself (line 13 there), precisely because deps-only does not set it. Leaving it listed here invites someone to drop that export.

Suggested change
# NSS_DIR, NSS_PREBUILT and NSS_BUILD_FLAGS come from mozilla/actions/nss.
# NSS_DIR and NSS_BUILD_FLAGS come from mozilla/actions/nss; nss-check.sh
# exports NSS_PREBUILT itself.

NSS_RS_DIR: ${{ github.workspace }}
HEAD_SHA: ${{ needs.setup.outputs.head }}
CACHE_KEY: nss-last-good-${{ matrix.os }}
# Absolute, because `git bisect run` invokes it from the NSS checkout.
CHECK: ${{ github.workspace }}/.github/scripts/nss-check.sh
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- uses: mozilla/actions/rust@f8e0d5c4cff5006ee24b6356272d47c9911450d1 # v2.0.6
with:
version: stable
token: ${{ secrets.GITHUB_TOKEN }}
rust-cache: false

- id: meta
uses: $/.github/actions/nss-metadata
Comment thread
larseggert marked this conversation as resolved.
Resolved

- uses: mozilla/actions/nss@264c6b750df669adb58286a26c5d0e04e839e06b # v2.0.8
with:
deps-only: true
Comment on lines +89 to +94

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Note

This is install-nss/action.yml minus the version inputs, and it pins a different mozilla/actions/nss.

install-nss already pairs nss-metadata with mozilla/actions/nss, but pins f8e0d5c # v2.0.6 where this pins 264c6b7 # v2.0.8. The two will drift on the next Renovate bump, and the deps-only build would then use a different action version than every other workflow. A deps-only passthrough on install-nss (which already exposes min-version, the only thing steps.meta is used for here) keeps the pin in one place:

Suggested change
- id: meta
uses: $/.github/actions/nss-metadata
- uses: mozilla/actions/nss@264c6b750df669adb58286a26c5d0e04e839e06b # v2.0.8
with:
deps-only: true
- id: meta
uses: ./install-nss
with:
deps-only: true
token: ${{ secrets.GITHUB_TOKEN }}


# Full history for the bisect range and tags; build.sh wants NSPR beside NSS.
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: mozilla/nss
ref: ${{ needs.setup.outputs.head }}
path: nss
fetch-depth: 0
persist-credentials: false
Comment thread
larseggert marked this conversation as resolved.
Resolved

- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: mozilla/nspr
ref: ${{ needs.setup.outputs.nspr }}
path: nspr
persist-credentials: false
Comment thread
larseggert marked this conversation as resolved.
Resolved

- name: Restore last known-good NSS commit
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: .nss-last-good
key: ${{ env.CACHE_KEY }}--${{ github.run_id }}
restore-keys: ${{ env.CACHE_KEY }}--

- name: Test NSS head
run: |
status=0
"$CHECK" 2>&1 | tee nss-head.log || status=$?
if [ "$status" -eq 0 ]; then
echo "BROKEN=false" >> "$GITHUB_ENV"
echo "$HEAD_SHA" > .nss-last-good
else
# 125 is the predicate's "NSS did not build": nothing to bisect for.
[ "$status" -ne 125 ] || echo "NO_BUILD=true" >> "$GITHUB_ENV"
echo "::warning::nss-rs fails against NSS head $HEAD_SHA (exit $status)"
echo "BROKEN=true" >> "$GITHUB_ENV"
fi
Comment thread
larseggert marked this conversation as resolved.
Resolved

- name: Bisect NSS
if: env.BROKEN == 'true' && env.NO_BUILD != 'true'
env:
MIN_VERSION: ${{ steps.meta.outputs.min-version }}
OVERRIDE: ${{ inputs.last-good }}
run: |
last_good="${OVERRIDE:-$(cat .nss-last-good 2>/dev/null || true)}"
# Fall back to the release the crate declares as its floor, which also
# covers a cache miss or a last-good commit head no longer descends from.
if [ -z "$last_good" ] || ! git -C "$NSS_DIR" merge-base --is-ancestor "$last_good" "$HEAD_SHA"; then
# The tag sits on a release branch, so take the branch point.
last_good=$(git -C "$NSS_DIR" merge-base "NSS_${MIN_VERSION//./_}_RTM^{commit}" "$HEAD_SHA")
echo "Bisecting from the $MIN_VERSION branch point at $last_good"
fi
# Bisect never tests its endpoints, so an environment that fails at
# every revision would otherwise pin the blame on the oldest one.
first_bad=""
git -C "$NSS_DIR" checkout --quiet "$last_good"
if ! "$CHECK" > last-good.log 2>&1; then
echo "::warning::nss-rs fails at the last known-good $last_good too, so the range is wrong or the build is broken"
echo "SELF_BROKEN=true" >> "$GITHUB_ENV"
else
git -C "$NSS_DIR" bisect start "$HEAD_SHA" "$last_good"
# Only a converged run leaves refs/bisect/bad on the first bad commit;
# after an abort it still points at the last revision tested.
if git -C "$NSS_DIR" bisect run "$CHECK" 2>&1 | tee bisect.log; then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Caution

On the Windows runners this blames an innocent commit.

git bisect run starts the predicate through the shell, and $CHECK contains backslashes (github.workspace is D:\a\nss-rs\nss-rs), which are among the metacharacters git tests for in prepare_shell_cmd(). So git runs sh -c 'D:\a\nss-rs\nss-rs/.github/scripts/nss-check.sh', sh eats the backslashes, the command is not found, and the status is 127 — neither 125 nor >= 128, so every revision is marked bad and the bisect converges on the commit right after last_good. The two direct "$CHECK" invocations above work, because bash resolves the mixed-separator path itself, so nothing else hints at the problem.

Passing the path as an argument keeps it out of the shell's word splitting:

Suggested change
if git -C "$NSS_DIR" bisect run "$CHECK" 2>&1 | tee bisect.log; then
if git -C "$NSS_DIR" bisect run bash "$CHECK" 2>&1 | tee bisect.log; then

Alternatively, drop the job-level env.CHECK and export a POSIX-style path after checkout, which also fixes it:

      - run: echo "CHECK=$(pwd)/.github/scripts/nss-check.sh" >> "$GITHUB_ENV"

first_bad=$(git -C "$NSS_DIR" rev-parse refs/bisect/bad)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tip

A converged bisect proves a new known-good commit; keeping it avoids re-bisecting the same range every day.

.nss-last-good is only updated when head is green, so while the bug stays open every daily run re-bisects from the old endpoint — ~7 from-scratch NSS builds × 7 platforms, every day, to rediscover the same commit. Recording the first bad commit's parent shrinks the next run to a day's worth of commits, and the pre-check above re-verifies the endpoint if it turns out not to be good after all.

Suggested change
first_bad=$(git -C "$NSS_DIR" rev-parse refs/bisect/bad)
first_bad=$(git -C "$NSS_DIR" rev-parse refs/bisect/bad)
# Narrow tomorrow's range: the parent of the first bad commit is
# good here, so there is no need to bisect the release again.
git -C "$NSS_DIR" rev-parse "$first_bad^" > .nss-last-good

The cache save step then needs to run for that case too:

        if: env.BROKEN == 'false' || env.FIRST_BAD != ''

else
echo "::warning::Bisect between $last_good and $HEAD_SHA did not converge"
fi
git -C "$NSS_DIR" bisect reset
fi
git -C "$NSS_DIR" checkout --quiet "$HEAD_SHA"
{
echo "FIRST_BAD=$first_bad"
echo "SUBJECT=$(git -C "$NSS_DIR" log -1 --format=%s "$first_bad" 2>/dev/null || true)"
} >> "$GITHUB_ENV"

# One file per platform, which the report job merges into a single verdict.
- name: Record the verdict
if: ${{ !cancelled() && env.BROKEN != '' }}
env:
OS: ${{ matrix.os }}
run: |
jq -n --arg os "$OS" --arg broken "$BROKEN" \
--arg no_build "${NO_BUILD:-false}" --arg self_broken "${SELF_BROKEN:-false}" \
--arg first_bad "${FIRST_BAD:-}" --arg subject "${SUBJECT:-}" \
--rawfile log nss-head.log \
'{os: $os, broken: ($broken == "true"), no_build: ($no_build == "true"),
self_broken: ($self_broken == "true"),
first_bad: $first_bad, subject: $subject, log: $log[-4000:]}' > verdict.json
Comment thread
larseggert marked this conversation as resolved.
Resolved

- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
if: ${{ !cancelled() }}
with:
name: nss-head-${{ matrix.os }}
path: |
verdict.json
nss-head.log
last-good.log
bisect.log
if-no-files-found: ignore

- uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
if: env.BROKEN == 'false'
with:
path: .nss-last-good
key: ${{ env.CACHE_KEY }}--${{ github.run_id }}

# Last, so that the verdict is recorded and uploaded either way.
- name: Fail this platform
if: env.BROKEN == 'true'
run: exit 1

report:
name: Report to Bugzilla
needs: [setup, head]
if: ${{ !cancelled() }}
runs-on: ubuntu-24.04
env:
# The dev instance mirrors the NSS product, so reporting can be exercised
# end to end without touching real bugs.
BUGZILLA: ${{ inputs.test-bugzilla && 'https://bugzilla-dev.allizom.org/rest' || 'https://bugzilla.mozilla.org/rest' }}
# Identifies the bug this workflow owns, so it can update and close it.
MARKER: "[nss-rs-head]"
# A missing test key must not fall through to the production one.
BUGZILLA_API_KEY: ${{ inputs.test-bugzilla && secrets.BUGZILLA_TEST_API_KEY || (!inputs.test-bugzilla && secrets.BUGZILLA_API_KEY) || '' }} # zizmor: ignore[secrets-outside-env]
HEAD_SHA: ${{ needs.setup.outputs.head }}
HEAD_RESULT: ${{ needs.head.result }}
RUN: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
steps:
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
pattern: nss-head-*
path: verdicts

- name: Summarise the verdicts
run: |
shopt -s nullglob
verdicts=(verdicts/*/verdict.json)
[ ${#verdicts[@]} -gt 0 ] || { echo "::error::No platform reported a verdict"; exit 1; }
Comment thread
larseggert marked this conversation as resolved.
Resolved
jq -s 'sort_by(.os)' "${verdicts[@]}" > all.json
jq -r '.[] | "\(if .broken then "FAIL" else "ok" end)\t\(.os)\t\(.first_bad)"' all.json
{
echo "BROKEN=$(jq -r 'any(.broken) | tostring' all.json)"
echo "NO_BUILD=$(jq -r '[.[] | select(.broken)] | (length > 0 and all(.no_build)) | tostring' all.json)"
# Changes whenever the set of failing platforms or their commits does.
echo "FINGERPRINT=$(jq -cS 'map(select(.broken) | {os, first_bad})' all.json \
| sha256sum | cut -c1-12)"
Comment on lines +240 to +241

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Note

The fingerprint ignores the failure mode, so a platform that changes why it fails posts no update.

first_bad is "" for all three of "NSS does not build", "fails at the last known-good too" and "bisect inconclusive", so e.g. windows-2025 going from no_build to a genuine-but-inconclusive failure keeps {os, first_bad} identical: the dedup on line 314 matches, no comment is added, and the bug's detail stays stale for as long as the set of platforms doesn't change.

Suggested change
echo "FINGERPRINT=$(jq -cS 'map(select(.broken) | {os, first_bad})' all.json \
| sha256sum | cut -c1-12)"
echo "FINGERPRINT=$(jq -cS 'map(select(.broken) | {os, first_bad, no_build, self_broken})' all.json \
| sha256sum | cut -c1-12)"

} >> "$GITHUB_ENV"

- name: Report to Bugzilla
if: env.BUGZILLA_API_KEY != ''
env:
DRY_RUN: ${{ inputs.dry-run }}
run: |
bz() {
local method=$1 path=$2
shift 2
# Retry only reads: a retried POST can file the same bug twice.
local retry=()
[ "$method" != GET ] || retry=(--retry 3 --retry-all-errors)
# No -L: curl keeps custom headers across a cross-host redirect.
curl -fsS --max-time 60 "${retry[@]}" -X "$method" "$BUGZILLA/$path" \
-H "X-BUGZILLA-API-KEY: $BUGZILLA_API_KEY" \
-H "Content-Type: application/json" "$@"
}
Comment thread
larseggert marked this conversation as resolved.
Resolved
# A dry run still searches and builds the payloads, but posts nothing.
mutate() { # method path payload
[ "$DRY_RUN" == "true" ] || { bz "$1" "$2" -d "$3"; return; }
{ echo "dry-run: $1 $BUGZILLA/$2"; jq . <<< "$3"; } >&2
echo '{"id": "(dry-run)"}'
}
show="${BUGZILLA%/rest}/show_bug.cgi?id="
id=$(bz GET bug -G \
--data-urlencode "whiteboard=$MARKER" \
--data-urlencode "resolution=---" \
--data-urlencode "order=bug_id" \
--data-urlencode "include_fields=id" | jq -r '.bugs[0].id // ""')

if [ "$BROKEN" == "false" ]; then
Comment thread
larseggert marked this conversation as resolved.
Resolved
# A timed-out platform uploads no verdict, so the rest look green.
[ "$HEAD_RESULT" == "success" ] ||
{ echo "::warning::Not every platform reported; leaving bug $id alone"; exit 0; }
[ -n "$id" ] || { echo "NSS head is fine and no bug is open."; exit 0; }
body="nss-rs builds and tests cleanly against NSS head $HEAD_SHA on every platform, so this is fixed. Closed automatically by $RUN."
mutate PUT "bug/$id" "$(jq -n --arg c "$body" \
'{status: "RESOLVED", resolution: "WORKSFORME", comment: {body: $c}}')" > /dev/null
echo "::notice::Closed $show$id"
exit 0
fi

failed=$(jq -r '[.[] | select(.broken) | .os] | join(", ")' all.json)
detail=$(jq -r '.[] | select(.broken) |
"## \(.os)\n\n\(if .no_build then "NSS head does not build."
elif .self_broken then "nss-rs also fails at the last known-good revision, so this may not be an NSS regression."
elif .first_bad == "" then "First bad commit: bisect inconclusive"
else "First bad commit: \(.first_bad) \(.subject)\n https://github.com/mozilla/nss/commit/\(.first_bad)" end)\n\n```\n\(.log)\n```\n"' all.json)
body=$(cat <<EOF
Building and testing nss-rs (https://github.com/mozilla/nss-rs) against NSS
head $HEAD_SHA fails on: $failed

$detail

Reported automatically by $RUN
nss-rs-fingerprint: $FINGERPRINT
EOF
)
if [ "$NO_BUILD" == "true" ]; then
echo "::warning::NSS head does not build on $failed; not filing"
exit 0
fi
summary="nss-rs fails against NSS head on $failed"
if [ -z "$id" ]; then
id=$(mutate POST bug "$(jq -n --arg s "$summary" \
--arg d "$body" --arg w "$MARKER" \
'{product: "NSS", component: "Libraries", version: "trunk", type: "defect",
summary: $s, description: $d, whiteboard: $w}')" | jq -r '.id')
echo "::notice::Filed $show$id"
elif ! comments=$(bz GET "bug/$id/comment"); then
echo "::error::Could not read the comments on bug $id"; exit 1
elif grep -qF "$FINGERPRINT" <<< "$comments"; then
echo "Bug $id already reports this set of failures."
else
# The failing set changed, so the summary is stale.
mutate PUT "bug/$id" "$(jq -n --arg s "$summary" --arg d "$body" \
'{summary: $s, comment: {body: $d}}')" > /dev/null
echo "::notice::Updated $show$id"
fi
Comment thread
larseggert marked this conversation as resolved.
Resolved

- name: Fail if any platform is broken
if: env.BROKEN == 'true'
run: exit 1
Loading