Skip to content

Conversation

@henrymercer
Copy link
Contributor

This API was introduced in Node.js 18. Let's use it instead of the check-disk-space package.

Risk assessment

For internal use only. Please select the risk level of this change:

  • Low risk: Changes are fully under feature flags, or have been fully tested and validated in pre-production environments and are highly observable, or are documentation or test only.

Which use cases does this change impact?

  • Advanced setup - Impacts users who have custom workflows.
  • Default setup - Impacts users who use default setup.
  • Code Scanning - Impacts Code Scanning (i.e. analysis-kinds: code-scanning).
  • Code Quality - Impacts Code Quality (i.e. analysis-kinds: code-quality).
  • Third-party analyses - Impacts third-party analyses (i.e. upload-sarif).
  • GHES - Impacts GitHub Enterprise Server.

How did/will you validate this change?

  • Unit tests - I am depending on unit test coverage (i.e. tests in .test.ts files).
  • End-to-end tests - I am depending on PR checks (i.e. tests in pr-checks).

If something goes wrong after this change is released, what are the mitigation and rollback strategies?

  • Rollback - Change can only be disabled by rolling back the release or releasing a new version with a fix.

How will you know if something goes wrong after this change is released?

  • Telemetry - I rely on existing telemetry or have made changes to the telemetry.
    • Alerts - New or existing monitors will trip if something goes wrong with this change.

Merge / deployment checklist

  • Confirm this change is backwards compatible with existing workflows.
  • Consider adding a changelog entry for this change.
  • Confirm the readme and docs have been updated if necessary.

This was introduced in Node.js 18
@henrymercer henrymercer requested a review from a team as a code owner October 28, 2025 11:44
Copilot AI review requested due to automatic review settings October 28, 2025 11:44
@github-actions github-actions bot added the size/XS Should be very easy to review label Oct 28, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR replaces the check-disk-space package with Node.js's native fs.statfs() API for checking disk usage. The change reduces external dependencies by leveraging built-in functionality introduced in Node.js 18.

Key changes:

  • Replaced check-disk-space package with fs.promises.statfs() API
  • Updated disk usage calculation to use filesystem block-based metrics (bsize, bavail, blocks)
  • Removed package dependency from package.json

Reviewed Changes

Copilot reviewed 14 out of 15 changed files in this pull request and generated no comments.

File Description
src/util.ts Replaced external disk space check with native Node.js API and updated calculation logic
package.json Removed check-disk-space dependency
lib/*.js Auto-generated JavaScript files reflecting source changes

Comment on lines +1115 to +1118
const blockSizeInBytes = diskUsage.bsize;
const numBlocksPerMb = (1024 * 1024) / blockSizeInBytes;
const numBlocksPerGb = (1024 * 1024 * 1024) / blockSizeInBytes;
if (diskUsage.bavail < 2 * numBlocksPerGb) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm surprised that we have to go through the block computation, and that there isn't a more direct measure in the API. But 🤷🏻

esbena
esbena previously approved these changes Oct 28, 2025
Copy link
Contributor

@esbena esbena left a comment

Choose a reason for hiding this comment

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

I don't see any existing tests of checkDiskUsage, we could verify that it produces some positive numbers without tying ourselves too much to the underlying runtime.

@github-actions github-actions bot added size/S Should be easy to review and removed size/XS Should be very easy to review labels Oct 28, 2025
@henrymercer
Copy link
Contributor Author

mbg
mbg previously approved these changes Oct 28, 2025
Copy link
Member

@mbg mbg left a comment

Choose a reason for hiding this comment

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

Nice. As discussed elsewhere, we don't have good test coverage for this, beyond it being run as part of every test workflow and as part of status report tests.

I think a unit test specifically for this would be tricky, beyond checking error conditions / nominal conditions. I am not sure how much that would gain us compared to what is already covered by the e2e workflows and other tests.

numTotalBytes: diskUsage.blocks * blockSizeInBytes,
};
} catch (error) {
logger.warning(
Copy link
Member

Choose a reason for hiding this comment

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

In a similar spirit to the log-level change we made in #3240, should we change this from a warning to a debug message? This is only really a best effort, so it may be better to avoid the workflow annotation that results from this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think while we expect the workflow validation to fail in a bunch of circumstances, this disk space check shouldn't fail. So I'd suggest we keep it as a warning.

Copy link
Member

Choose a reason for hiding this comment

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

No strong feelings, but I could imagine that this could also fail with weird filesystem / permission setups, especially on self-hosted runners.

mbg
mbg previously approved these changes Oct 28, 2025
Copy link
Member

@mbg mbg left a comment

Choose a reason for hiding this comment

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

Thanks for adding a unit test!

src/util.test.ts Outdated
Comment on lines 540 to 544
t.true(
diskUsage?.numAvailableBytes !== undefined &&
diskUsage.numAvailableBytes > 0,
);
t.true(diskUsage?.numTotalBytes !== undefined && diskUsage.numTotalBytes > 0);
Copy link
Member

Choose a reason for hiding this comment

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

Minor, but I quite like t.truthy in an if condition that guards the check on the property. The && makes it harder to debug which sub-condition failed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's hard to write because we can't compare undefined with 0. I'll make two separate assertions.

mbg
mbg previously approved these changes Oct 28, 2025
@henrymercer henrymercer merged commit e1c8976 into main Oct 28, 2025
243 checks passed
@henrymercer henrymercer deleted the henrymercer/disk-usage-node-api branch October 28, 2025 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S Should be easy to review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants