Skip to content

Fix GitHub Actions workflow to respect minimum Node.js version selection and centralize version fallbacks#1161

Merged
Apollon77 merged 6 commits intomasterfrom
copilot/fix-1144
Sep 20, 2025
Merged

Fix GitHub Actions workflow to respect minimum Node.js version selection and centralize version fallbacks#1161
Apollon77 merged 6 commits intomasterfrom
copilot/fix-1144

Conversation

Copy link
Contributor

Copilot AI commented Aug 31, 2025

The GitHub Actions workflow template was incorrectly using hardcoded Node.js test versions, causing CI failures when adapters were created with Node.js 20+ as the minimum version. The workflow would still attempt to run tests on Node.js 18.x, leading to npm engine compatibility errors:

npm error code EBADENGINE
npm error engine Unsupported engine
npm error engine Not compatible with your version of node/npm: iobroker.typescript-demo@0.0.1
npm error notsup Not compatible with your version of node/npm: iobroker.typescript-demo@0.0.1
npm error notsup Required: {"node":">= 20"}
npm error notsup Actual:   {"npm":"10.8.2","node":"v18.20.8"}

Changes Made

Dynamic Node.js Version Filtering

Updated templates/_github/workflows/test-and-release.yml.ts to dynamically filter Node.js versions based on the user's minimum version selection:

Before:

const ltsNodeVersion = "20.x";
const adapterTestVersions = ["20.x", "22.x", "24.x"]; // Hardcoded

After:

// Determine the LTS version and test versions based on the minimum Node.js version selected
const minNodeVersion = answers.nodeVersion || RECOMMENDED_NODE_VERSION_FALLBACK;
const ltsNodeVersion = `${minNodeVersion}.x`;

// Filter test versions to only include versions >= the minimum version
const allTestVersions = ["20.x", "22.x", "24.x"];
const minVersionNumber = parseInt(minNodeVersion, 10);
const adapterTestVersions = allTestVersions.filter(version => {
    const versionNumber = parseInt(version.split('.')[0], 10);
    return versionNumber >= minVersionNumber;
});

Centralized Version Fallbacks

Created src/lib/constants.ts to centralize fallback values and eliminate code duplication. Updated three template files that were using hardcoded Node.js version fallbacks:

  • templates/_github/workflows/test-and-release.yml.ts
  • templates/package.json.ts
  • templates/tsconfig.json.ts

All now import and use the RECOMMENDED_NODE_VERSION_FALLBACK constant, making future updates easier to maintain.

Results

Now when creating adapters with different minimum Node.js versions:

  • Node.js 20: Tests against [20.x, 22.x, 24.x], uses 20.x for LTS operations
  • Node.js 22: Tests against [22.x, 24.x], uses 22.x for LTS operations
  • Node.js 24: Tests against [24.x], uses 24.x for LTS operations

This ensures CI pipelines only test against compatible Node.js versions, eliminating the engine compatibility failures while improving code maintainability.

Testing

Added comprehensive test coverage to prevent regressions, validating that the workflow correctly filters Node.js versions for all supported minimum versions (20, 22, 24).

Fixes #1144.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 2 commits August 31, 2025 19:57
Co-authored-by: Apollon77 <11976694+Apollon77@users.noreply.github.com>
Co-authored-by: Apollon77 <11976694+Apollon77@users.noreply.github.com>
Copilot AI changed the title [WIP] new repo created with minimum node.js 20 tries to run node.js 18 tests Fix GitHub Actions workflow to respect minimum Node.js version selection Aug 31, 2025
Copilot AI requested a review from Apollon77 August 31, 2025 20:02
const ltsNodeVersion = "20.x";
const adapterTestVersions = ["20.x", "22.x", "24.x"];
// Determine the LTS version and test versions based on the minimum Node.js version selected
const minNodeVersion = answers.nodeVersion || "20";
Copy link
Collaborator

Choose a reason for hiding this comment

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

please add a constant for the "recommended nodejs fall back version" in a new file for such fallbacks (are there more such fallbacks in the code?) and import from there

Copy link
Collaborator

Choose a reason for hiding this comment

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

@copilot please add a constant for the "recommended nodejs fall back version" in a new file for such fallbacks (are there more such fallbacks in the code?) and import from there

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a new constants file src/lib/constants.ts with RECOMMENDED_NODE_VERSION_FALLBACK constant. Found and updated three locations where "20" was used as a Node.js version fallback:

  • templates/_github/workflows/test-and-release.yml.ts
  • templates/package.json.ts
  • templates/tsconfig.json.ts

All now import and use the centralized constant. Commit fb9ad97.

- Add RECOMMENDED_NODE_VERSION_FALLBACK constant in src/lib/constants.ts
- Update templates/_github/workflows/test-and-release.yml.ts to import and use the constant
- Update templates/package.json.ts to import and use the constant
- Update templates/tsconfig.json.ts to import and use the constant
- Fix prettier formatting issues in test file

This centralizes the fallback value, making it easier to maintain and update in the future.

Co-authored-by: Apollon77 <11976694+Apollon77@users.noreply.github.com>
Copilot AI changed the title Fix GitHub Actions workflow to respect minimum Node.js version selection Fix GitHub Actions workflow to respect minimum Node.js version selection and centralize version fallbacks Aug 31, 2025
Copilot AI requested a review from Apollon77 August 31, 2025 20:49
@Apollon77 Apollon77 marked this pull request as ready for review September 2, 2025 20:46
@Apollon77 Apollon77 enabled auto-merge (squash) September 20, 2025 12:25
@Apollon77 Apollon77 merged commit 6a11d5a into master Sep 20, 2025
7 checks passed
@Apollon77 Apollon77 deleted the copilot/fix-1144 branch September 20, 2025 12:27
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.

new repo created with minimum node.js 20 tries to run node.js 18 tests

2 participants