Skip to content

Commit 8cd1dfb

Browse files
dcarleyclaude
andcommitted
fix(metrics): FLOX_DISABLE_METRICS conditional
Callers who set `FLOX_DISABLE_METRICS: "true"` at the workflow `env:` level were silently having their setting overwritten. The `disable-metrics` input defaulted to `"false"`, and `core.exportVariable` writes to `$GITHUB_ENV`, which the runner folds into the job's global environment — overwriting any prior value. This meant the obvious way to opt out of metrics was broken. Guard the single `run()` export so it only fires when the caller actually passes the input. When `disable-metrics` is unset (the new default of `""`), the action leaves `FLOX_DISABLE_METRICS` untouched — at whatever value the caller already set, or absent, in which case the flox CLI applies its own default (disabled by its `#[serde(default)]` bool). `action.yml` default changed from `"false"` to `""` and the description expanded to explain the new semantics. `README.md` inputs table updated to match. `dist/index.js` rebuilt to match. Tests cover both branches of the `run()` guard: an unset input leaves `FLOX_DISABLE_METRICS` untouched (the regression), and an explicit value is still exported. 64 tests pass, statement/line coverage at 100%. Refs: ECO-104 Forge-Agent: implementation-worker (03fbd38a) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 205078e commit 8cd1dfb

5 files changed

Lines changed: 93 additions & 5 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ jobs:
7979
|-------|-------------|---------|
8080
| `version` | Select a specific version from a channel | `""` |
8181
| `channel` | One of: `stable`, `qa`, `nightly`, or a commit hash | `"stable"` |
82-
| `disable-metrics` | Disable sending anonymous usage statistics to flox | `"false"` |
82+
| `disable-metrics` | Disable sending anonymous usage statistics to flox | `""` |
8383
| `retries` | Number of retries for downloading and installing Flox | `"3"` |
8484
| `use-cache` | Cache the downloaded flox package to speed up subsequent runs | `"true"` |
8585
| `github-token` | GitHub token for Nix flake rate limiting | `${{ github.token }}` |

action.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ inputs:
1717
default: "stable"
1818

1919
disable-metrics:
20-
description: "Disable sending anonymous usage statistics to flox"
21-
default: "false"
20+
description: >-
21+
Disable sending anonymous usage statistics to flox.
22+
When unset, honors the FLOX_DISABLE_METRICS env var
23+
(or the CLI default if neither is set).
24+
default: ""
2225

2326
base-url:
2427
deprecationMessage: "Please use channel option"

dist/index.js

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,9 @@ export async function writeJobSummary({
280280
export async function run() {
281281
try {
282282
const disable_metrics = core.getInput('disable-metrics')
283-
core.exportVariable('FLOX_DISABLE_METRICS', disable_metrics)
283+
if (disable_metrics !== '') {
284+
core.exportVariable('FLOX_DISABLE_METRICS', disable_metrics)
285+
}
284286

285287
core.startGroup('Download & Install flox')
286288
const nix = await which('nix', { nothrow: true })

src/main.test.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,3 +917,84 @@ describe('main', () => {
917917
})
918918
})
919919
})
920+
921+
describe('run disable-metrics guard', () => {
922+
beforeEach(() => {
923+
jest.clearAllMocks()
924+
core.getInput.mockReturnValue('')
925+
core.summary = {
926+
addHeading: jest.fn().mockReturnThis(),
927+
addTable: jest.fn().mockReturnThis(),
928+
write: jest.fn().mockResolvedValue(undefined)
929+
}
930+
})
931+
932+
it('does not export FLOX_DISABLE_METRICS in run() when disable-metrics input is unset', async () => {
933+
which.mockImplementation(cmd => {
934+
if (cmd === 'nix')
935+
return Promise.resolve('/nix/var/nix/profiles/default/bin/nix')
936+
if (cmd === 'flox') return Promise.resolve('/usr/local/bin/flox')
937+
return Promise.resolve(null)
938+
})
939+
core.getInput.mockImplementation(name => {
940+
if (name === 'disable-upgrade-notifications') return 'true'
941+
return ''
942+
})
943+
fs.existsSync.mockReturnValue(true)
944+
fs.readFileSync.mockReturnValue('')
945+
exec.exec.mockImplementation(async (cmd, args, opts) => {
946+
if (
947+
cmd === 'flox' &&
948+
args &&
949+
args[0] === '--version' &&
950+
opts &&
951+
opts.listeners
952+
) {
953+
opts.listeners.stdout(Buffer.from('flox 1.7.6\n'))
954+
}
955+
return 0
956+
})
957+
958+
await main.run()
959+
960+
expect(core.exportVariable).not.toHaveBeenCalledWith(
961+
'FLOX_DISABLE_METRICS',
962+
expect.anything()
963+
)
964+
})
965+
966+
it('exports FLOX_DISABLE_METRICS in run() when disable-metrics input is explicitly set', async () => {
967+
which.mockImplementation(cmd => {
968+
if (cmd === 'nix')
969+
return Promise.resolve('/nix/var/nix/profiles/default/bin/nix')
970+
if (cmd === 'flox') return Promise.resolve('/usr/local/bin/flox')
971+
return Promise.resolve(null)
972+
})
973+
core.getInput.mockImplementation(name => {
974+
if (name === 'disable-metrics') return 'true'
975+
if (name === 'disable-upgrade-notifications') return 'true'
976+
return ''
977+
})
978+
fs.existsSync.mockReturnValue(true)
979+
fs.readFileSync.mockReturnValue('')
980+
exec.exec.mockImplementation(async (cmd, args, opts) => {
981+
if (
982+
cmd === 'flox' &&
983+
args &&
984+
args[0] === '--version' &&
985+
opts &&
986+
opts.listeners
987+
) {
988+
opts.listeners.stdout(Buffer.from('flox 1.7.6\n'))
989+
}
990+
return 0
991+
})
992+
993+
await main.run()
994+
995+
expect(core.exportVariable).toHaveBeenCalledWith(
996+
'FLOX_DISABLE_METRICS',
997+
'true'
998+
)
999+
})
1000+
})

0 commit comments

Comments
 (0)