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
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
tests/ export-ignore
.github/ export-ignore
scripts/ export-ignore
CONTRIBUTING.md export-ignore
112 changes: 112 additions & 0 deletions .github/workflows/add-bruno-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
name: Add new Bruno CLI lockfiles

on:
schedule:
- cron: '0 5 * * *'
workflow_dispatch:

permissions: {}

jobs:
add:
name: Open a PR per new @usebruno/cli version
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v6

# npm >= 11.10 is needed for --min-release-age; Node 24 bundles npm 11.
- uses: actions/setup-node@v6
with:
node-version: '24'

- name: Generate lockfiles and open PRs
env:
GH_TOKEN: ${{ github.token }}
COOLDOWN_DAYS: '2'
# Comma-separated GitHub usernames to request review from. Teams
# can't be requested with GITHUB_TOKEN; use CODEOWNERS for teams.
LOCKFILE_REVIEWERS: ${{ vars.LOCKFILE_REVIEWERS }}
run: |
set -uo pipefail
git config user.name 'github-actions[bot]'
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'

base="$(git rev-parse HEAD)"
failures=()

# Always a draft, never auto-merged: a human has to mark it ready and
# merge it. Branch protection (see README) makes their approval
# mandatory.
open_pr() {
local version="$1" branch="$2" pr_url
pr_url="$(gh pr create --draft --base "${GITHUB_REF_NAME}" --head "${branch}" \
--title "chore: add lockfile for @usebruno/cli ${version}" \
--body "Adds \`lockfiles/${version}\`, generated by \`scripts/add-version.sh\` with a ${COOLDOWN_DAYS}-day release-age cooldown. Until this is merged and released, ${version} installs via the unlocked npm fallback; after that it installs from this lockfile.

**Human review required.** This PR was opened by automation as a draft and must not be merged without a person reviewing it:

- [ ] Compare the dependency tree with the previous lockfile (new, removed or bumped packages).
- [ ] Check Dependabot alerts / \`npm audit\` for this lockfile.
- [ ] Run the smoke tests (Actions → Smoke test → Run workflow on \`${branch}\`). PRs opened with \`GITHUB_TOKEN\` don't trigger them automatically.
- [ ] Mark ready for review, approve, merge, then cut a release so \`@v1\` users get the lockfile.

To decline this version, close the PR without deleting the branch; the workflow won't propose it again.")" || return 1

if [ -z "${LOCKFILE_REVIEWERS}" ]; then
echo "::warning::LOCKFILE_REVIEWERS repo variable is not set; no reviewers requested on ${pr_url}."
elif ! gh pr edit "${pr_url}" --add-reviewer "${LOCKFILE_REVIEWERS}"; then
echo "::warning::Could not request review from '${LOCKFILE_REVIEWERS}' on ${pr_url}."
fi
}

# Each step is chained so a failure returns instead of exiting:
# errexit doesn't apply inside a function called from `if`.
lock_and_push() {
local version="$1" branch="$2"
git switch --quiet --detach "${base}" &&
scripts/add-version.sh "${version}" &&
git switch --quiet -c "${branch}" &&
git add "lockfiles/${version}" &&
git commit --quiet -m "chore: add lockfile for @usebruno/cli ${version}" &&
git push --quiet origin "${branch}"
}

if ! versions="$(scripts/missing-versions.sh)"; then
echo "::error::Could not list @usebruno/cli versions."
exit 1
fi
if [ -z "${versions}" ]; then
echo "No new @usebruno/cli versions past the ${COOLDOWN_DAYS}-day cooldown."
exit 0
fi

for version in ${versions}; do
branch="bruno-lockfile/${version}"
echo "::group::${version}"

if git ls-remote --exit-code --heads origin "${branch}" > /dev/null; then
if [ -n "$(gh pr list --head "${branch}" --state all --json number --jq '.[].number')" ]; then
echo "${branch} already has a PR (open, merged or closed); skipping."
else
echo "${branch} exists without a PR (an earlier run failed); opening one."
open_pr "${version}" "${branch}" || failures+=("${version}")
fi
elif lock_and_push "${version}" "${branch}"; then
open_pr "${version}" "${branch}" || failures+=("${version}")
else
echo "::error::Could not generate or push a lockfile for ${version}."
failures+=("${version}")
git switch --quiet --force --detach "${base}"
git clean -fdq -- lockfiles
fi

echo "::endgroup::"
done

if [ "${#failures[@]}" -gt 0 ]; then
echo "::error::Failed for: ${failures[*]}. Other versions were still processed."
exit 1
fi
64 changes: 64 additions & 0 deletions .github/workflows/smoke-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,67 @@ jobs:
test "${{ steps.bru.outputs.duration-ms }}" = "0"
test "${{ steps.bru.outcome }}" = "failure"
test ! -e "${RUNNER_TEMP}/bruno-junit.xml"

version-resolution:
name: bru-version ${{ matrix.spec }} installs ${{ matrix.expect }} (${{ matrix.source }})
runs-on: ubuntu-latest
permissions:
contents: read
strategy:
fail-fast: false
matrix:
include:
- { spec: '^3', expect: '3.5.3', source: 'locked' }
- { spec: 'v4.2.1', expect: '4.2.1', source: 'locked' }
- { spec: '^1', expect: '1.40.0', source: 'locked' }
- { spec: '2.1.0', expect: '2.1.0', source: 'unlocked' }
steps:
- uses: actions/checkout@v6

- name: Run bru --version
id: bru
uses: ./
with:
bru-version: ${{ matrix.spec }}
working-directory: tests/collection
command: '--version'

- name: Assert resolved version and install source
env:
EXPECT: ${{ matrix.expect }}
SOURCE: ${{ matrix.source }}
run: |
set -euo pipefail
test "$(bru --version)" = "${EXPECT}"
if [ "${SOURCE}" = "locked" ]; then
test "$(command -v bru)" = "${RUNNER_TEMP}/bruno-cli-${EXPECT}/node_modules/.bin/bru"
else
test "$(command -v bru)" != "${RUNNER_TEMP}/bruno-cli-${EXPECT}/node_modules/.bin/bru"
fi

unknown-version:
name: Nonexistent bru-version fails before running bru
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v6

- name: Request a version that does not exist
id: bru
continue-on-error: true
uses: ./
with:
bru-version: '99.0.0'
working-directory: tests/collection
command: 'run health.bru --env ci'

- name: Assert the install step failed and bru never ran
run: |
set -euo pipefail
test "${{ steps.bru.outcome }}" = "failure"
test -z "${{ steps.bru.outputs.exit-code }}"
if command -v bru; then
echo "bru unexpectedly on PATH"
exit 1
fi
60 changes: 60 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Contributing

Notes for maintainers of this action. Consumer-facing documentation is in [README.md](README.md).

## How Bruno CLI installs work

`lib/install-cli.sh` resolves `bru-version` to a concrete `@usebruno/cli` version with `lib/resolve-version.js`. It accepts exact versions (with or without a leading `v`), ranges and dist-tags, the way npm does, and only considers versions published at least `cooldown-days` ago.

- **Locked:** if `lockfiles/<version>/package-lock.json` exists, the script copies it into `$RUNNER_TEMP`, runs `npm ci --ignore-scripts`, and adds that folder's `node_modules/.bin` to `$GITHUB_PATH`. Bruno's dependencies are never resolved at run time.
- **Fallback:** otherwise it prints a `::warning::` and runs `npm install -g --min-release-age=<cooldown-days>`, which resolves dependencies at run time.

Lockfiles exist for every 3.x and 4.x release, plus the most-downloaded 1.x and 2.x releases (each had at least 500 weekly downloads when it was added). Every locked package resolves from registry.npmjs.org, and GitHub's dependency graph and Dependabot alerts scan each lockfile.

Locking a version doesn't make it safe. Many lockfiles contain vulnerable dependencies that Bruno itself pins, and the old unlocked install got the same ones. To see the known issues for a version, run this in its folder:

```sh
npm audit --package-lock-only
```

## Adding or regenerating a lockfile

`scripts/add-version.sh` needs npm 11.10 or newer for `--min-release-age`:

```sh
scripts/add-version.sh 4.3.0 # add
FORCE=1 scripts/add-version.sh 4.3.0 # regenerate, picking up in-range dependency fixes
```

It runs `npm install --package-lock-only --ignore-scripts` in a temp folder with a 2-day release-age cooldown (`COOLDOWN_DAYS`), so neither Bruno nor any of its dependencies can be locked until it has been published for 2 days. It then checks that the locked CLI version is the one requested and that every package comes from registry.npmjs.org.

Lockfiles don't pick up dependency fixes on their own. Regenerate a version with `FORCE=1` to pick up fixes that fall within Bruno's semver ranges.

## Automated lockfile PRs

`.github/workflows/add-bruno-version.yml` runs daily and on manual dispatch. `scripts/missing-versions.sh` lists every stable release from `MIN_VERSION` (default 3.0.0) onwards that is past the cooldown and has no lockfile, including backports to older lines. The workflow opens one PR per version on a `bruno-lockfile/<version>` branch.

- If one version can't be locked, the others still get PRs, and the run fails listing the version that failed.
- If an earlier run pushed a branch but never opened its PR, the next run opens it.
- To decline a version, close its PR without deleting the branch, and it won't be proposed again.
- Older majors are locked selectively by hand.
- PRs opened with `GITHUB_TOKEN` don't trigger other workflows, so run the smoke tests manually on the PR branch.
- After merging, cut a release so `@v1` consumers get the new lockfile.

### Human review

These PRs always need a human to review them. The workflow opens them as drafts, never enables auto-merge, and requests review from the comma-separated GitHub usernames in the `LOCKFILE_REVIEWERS` repository variable. Teams can't be requested with the workflow's `GITHUB_TOKEN`, so use `CODEOWNERS` for team review.

To make a human approval mandatory, set up the repository:

- Protect `main` with a branch protection rule or ruleset that requires at least one approving review and blocks direct pushes.
- Add a `CODEOWNERS` entry for `/lockfiles/` and turn on "Require review from Code Owners", so an approval from the `github-actions` bot never counts.
- Turn on "Allow GitHub Actions to create and approve pull requests" so the workflow can open PRs. The same setting lets the bot approve PRs, which is why the Code Owners requirement matters.

## What consumers download

The Actions runner downloads the archive GitHub generates for a ref, not a clone. Anything consumers don't need at runtime (`tests/`, `.github/`, `scripts/` and this file) is marked `export-ignore` in `.gitattributes` to keep that archive small. `lib/` and `lockfiles/` are needed at runtime and must never be excluded. Check what consumers receive with:

```sh
git archive HEAD | tar -t
```
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ Customize the Bruno CLI GitHub Action to suit your API project's CI/CD workflow.
| Name | Type | Description |
|---|---|---|
| `command` | String | **Required.** The Bruno CLI command to run and its options (e.g. `run --env prod`). The action prepends `bru`. |
| `bru-version` | String | Version of `@usebruno/cli` to install. (Default: `latest`) |
| `bru-version` | String | Version of `@usebruno/cli` to install: an exact version, a range (e.g. `^3`, `4.2.x`) or a dist-tag (e.g. `latest`), resolved like npm does. Versions with a lockfile in [`lockfiles/`](lockfiles) install from it; others fall back to a normal `npm install` with a warning. (Default: `latest`) |
| `cooldown-days` | Number | Only install `@usebruno/cli` and dependency versions published at least this many days ago, to limit exposure to newly compromised releases. Ranges and tags pick the newest version past the cooldown; a pinned version newer than this fails. Set to `0` to disable. (Default: `2`) |
| `working-directory` | String | Path of the Bruno collection directory. (Default: `.`) |

**Example using all inputs:**
Expand All @@ -56,6 +57,7 @@ Customize the Bruno CLI GitHub Action to suit your API project's CI/CD workflow.
with:
command: 'run --env prod --reporter-junit results.xml'
bru-version: '3.5.0'
cooldown-days: 14
working-directory: tests/payments
```

Expand All @@ -75,15 +77,25 @@ Available as `${{ steps.<id>.outputs.<name> }}` in subsequent steps:

For `run` commands, the action adds a temporary JUnit reporter when one is not provided and populates the request-count outputs. Other Bruno CLI commands run unchanged and return zero for the request-count outputs.

### Locked installs

Most Bruno versions install from a lockfile shipped with the action (see [`lockfiles/`](lockfiles)), so every run gets the same fixed dependency tree and no dependency install scripts run. Other versions still work, but they fall back to a normal `npm install` and print a warning. Pin a locked version to avoid the fallback. Maintainers: see [CONTRIBUTING.md](CONTRIBUTING.md).

## Versioning

| Tag | Behaviour |
| Reference | Behaviour |
|---|---|
| `@v1` | Floating major. Receives every backwards-compatible release. |
| `@v1.0.0` | Immutable. Pinned to a specific release. |
| `@104e180c2e7219a915dc48b6979ddbafe0940fcd # v1.0.0` | Immutable. Pinned to the exact commit of the `v1.0.0` release. |

The `v<major>` tag is retagged automatically on every published release.

Git tags can be moved, so a release tag such as `@v1.0.0` can point at different code later. Only a full commit SHA is immutable. Keep the version in a trailing comment so it stays readable; Dependabot and Renovate update both the SHA and the comment when a new release comes out:

```yaml
- uses: usebruno/bruno-cli-action@104e180c2e7219a915dc48b6979ddbafe0940fcd # v1.0.0
```

## Examples

The following examples cover some of the reporting and artifact use case. Use `--reporter-junit` flag to emit clean JUnit XML; downstream actions render it for the user-visible surface needed or upload it as a workflow artifact.
Expand Down
9 changes: 7 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ inputs:
description: 'The bru subcommand and flags (e.g. "run --env prod --reporter-junit results.xml"). The action prepends "bru".'
required: true
bru-version:
description: 'Version of @usebruno/cli to install.'
description: 'Version, range or dist-tag of @usebruno/cli to install. Installs from lockfiles/ when the resolved version is locked, otherwise falls back to npm install.'
required: false
default: 'latest'
cooldown-days:
description: 'Only install @usebruno/cli and dependency versions published at least this many days ago. Set to 0 to disable.'
required: false
default: '2'
working-directory:
description: 'Shell working directory. Typically the Bruno collection root.'
required: false
Expand Down Expand Up @@ -41,7 +45,7 @@ runs:
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: '22'
node-version: '24'

- name: Install action dependencies (fast-xml-parser)
shell: bash
Expand All @@ -53,6 +57,7 @@ runs:
shell: bash
env:
BRU_VERSION: ${{ inputs.bru-version }}
COOLDOWN_DAYS: ${{ inputs.cooldown-days }}
run: ${{ github.action_path }}/lib/install-cli.sh

- name: Run bru
Expand Down
45 changes: 40 additions & 5 deletions lib/install-cli.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,44 @@
#!/usr/bin/env bash
# Install @usebruno/cli. bru-version (exact, range or dist-tag) is resolved to
# a concrete version past the cooldown. If lockfiles/<version>/ exists, install
# that pre-resolved dependency tree; otherwise fall back to a plain npm install.
set -euo pipefail

VERSION="${BRU_VERSION:-latest}"
SPEC="${BRU_VERSION:-latest}"
COOLDOWN_DAYS="${COOLDOWN_DAYS:-2}"
ACTION_ROOT="${GITHUB_ACTION_PATH:-$(cd "$(dirname "$0")/.." && pwd)}"
LOCK_ROOT="${ACTION_ROOT}/lockfiles"

echo "::group::Install @usebruno/cli@${VERSION}"
npm install -g "@usebruno/cli@${VERSION}"
bru --version
echo "::endgroup::"
RESOLVED="$(npm view @usebruno/cli versions time dist-tags --json |
node "${ACTION_ROOT}/lib/resolve-version.js" "${SPEC}" "${COOLDOWN_DAYS}" "${LOCK_ROOT}")" || {
# resolve-version.js prints its own ::error:: line on stdout.
[ -n "${RESOLVED:-}" ] && echo "${RESOLVED}"
exit 1
}
VERSION="${RESOLVED% *}"
SOURCE="${RESOLVED#* }"
echo "bru-version '${SPEC}' resolves to ${VERSION} (cooldown ${COOLDOWN_DAYS} days, ${SOURCE})."

if [ "${SOURCE}" = "locked" ]; then
INSTALL_DIR="${RUNNER_TEMP:-$(mktemp -d)}/bruno-cli-${VERSION}"
rm -rf "${INSTALL_DIR}"
mkdir -p "${INSTALL_DIR}"
cp "${LOCK_ROOT}/${VERSION}/package.json" "${LOCK_ROOT}/${VERSION}/package-lock.json" "${INSTALL_DIR}/"

echo "::group::Install @usebruno/cli@${VERSION} from lockfile"
# --ignore-scripts: no dependency lifecycle scripts run. The only one in the
# tree (protobufjs) is not needed at runtime.
(cd "${INSTALL_DIR}" && npm ci --ignore-scripts --no-audit --no-fund)
"${INSTALL_DIR}/node_modules/.bin/bru" --version
echo "::endgroup::"

if [ -n "${GITHUB_PATH:-}" ]; then
echo "${INSTALL_DIR}/node_modules/.bin" >> "${GITHUB_PATH}"
fi
else
echo "::warning::@usebruno/cli ${VERSION} has no lockfile in this action; installing with npm, which resolves its dependencies at run time."
echo "::group::Install @usebruno/cli@${VERSION}"
npm install -g --min-release-age="${COOLDOWN_DAYS}" "@usebruno/cli@${VERSION}"
bru --version
echo "::endgroup::"
fi
Loading