Skip to content

Commit d344d2d

Browse files
committed
GHA to check node versions
1 parent 458f1c4 commit d344d2d

File tree

10 files changed

+308
-24
lines changed

10 files changed

+308
-24
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#!/usr/bin/env node
2+
3+
const fs = require('fs');
4+
const path = require('path');
5+
const yaml = require('yaml');
6+
7+
/**
8+
* Get the required Node.js version from package.json
9+
* @returns {string} The Node.js version number
10+
*/
11+
function getRequiredNodeVersion() {
12+
const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
13+
return packageJson.engines.node.replace('>=', '');
14+
}
15+
16+
/**
17+
* Check Node.js version in .lando.yml
18+
* @param {string} requiredVersion - The required Node.js version
19+
* @returns {string|null} Mismatch message if version differs, null if matches
20+
*/
21+
function checkLandoFile(requiredVersion) {
22+
const landoPath = '.lando.yml';
23+
const landoContent = fs.readFileSync(landoPath, 'utf8');
24+
const landoConfig = yaml.parse(landoContent);
25+
26+
const currentVersion = landoConfig.services.node.image.split(':')[1];
27+
if (currentVersion !== requiredVersion) {
28+
return `- .lando.yml has node:${currentVersion}, expected node:${requiredVersion}`;
29+
}
30+
return null;
31+
}
32+
33+
/**
34+
* Check Node.js version in workflow files
35+
* @param {string} requiredVersion - The required Node.js version
36+
* @returns {string[]} Array of mismatch messages
37+
*/
38+
function checkWorkflowFiles(requiredVersion) {
39+
const mismatches = [];
40+
const workflowsDir = '.github/workflows';
41+
42+
const files = fs.readdirSync(workflowsDir)
43+
.filter(file => file.endsWith('.yml'));
44+
45+
files.forEach(file => {
46+
const filePath = path.join(workflowsDir, file);
47+
const content = fs.readFileSync(filePath, 'utf8');
48+
const workflow = yaml.parse(content);
49+
50+
const checkObject = obj => {
51+
for (const key in obj) {
52+
if (key === 'node-version' && typeof obj[key] === 'string') {
53+
const version = obj[key].replace(/['"]/g, '');
54+
if (version !== requiredVersion) {
55+
mismatches.push(`- ${filePath} has Node.js ${version}, expected ${requiredVersion}`);
56+
}
57+
} else if (typeof obj[key] === 'object' && obj[key] !== null) {
58+
checkObject(obj[key]);
59+
}
60+
}
61+
};
62+
63+
checkObject(workflow);
64+
});
65+
66+
return mismatches;
67+
}
68+
69+
/**
70+
* Main function to check Node.js versions
71+
*/
72+
function main() {
73+
try {
74+
const requiredVersion = getRequiredNodeVersion();
75+
console.log(`Checking for Node.js version ${requiredVersion} across configuration files...`);
76+
77+
const mismatches = [];
78+
79+
const landoMismatch = checkLandoFile(requiredVersion);
80+
if (landoMismatch) mismatches.push(landoMismatch);
81+
82+
const workflowMismatches = checkWorkflowFiles(requiredVersion);
83+
mismatches.push(...workflowMismatches);
84+
85+
if (mismatches.length > 0) {
86+
console.error('\nNode.js version mismatches found:');
87+
console.error(mismatches.join('\n'));
88+
console.error('\nPlease update all Node.js versions to match package.json');
89+
process.exit(1);
90+
} else {
91+
console.log('All Node.js versions match package.json ✓');
92+
process.exit(0);
93+
}
94+
} catch (error) {
95+
console.error('Error:', error);
96+
process.exit(1);
97+
}
98+
}
99+
100+
main();

.github/workflows/pr-integration-tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Integration Tests (Leia)
1+
name: Integration Tests (Examples)
22

33
on:
44
pull_request:
@@ -19,7 +19,7 @@ jobs:
1919
os:
2020
- ubuntu-24.04
2121
node-version:
22-
- '18'
22+
- '20'
2323
steps:
2424
- name: Checkout code
2525
uses: actions/checkout@v4
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Check Node.js Versions
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
check-node-versions:
8+
runs-on: ubuntu-24.04
9+
10+
steps:
11+
- name: Checkout code
12+
uses: actions/checkout@v4
13+
14+
- name: Setup Node.js
15+
uses: actions/setup-node@v4
16+
with:
17+
node-version: '20'
18+
19+
- name: Install dependencies
20+
run: npm install yaml
21+
22+
- name: Check Node.js versions
23+
run: .github/scripts/check-node-versions.js

.github/workflows/pr-unit-tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ name: Run Unit Tests
22

33
on:
44
pull_request:
5+
workflow_dispatch:
56

67
jobs:
78
unit-tests:

.lando.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: lando-mailpit-plugin
33
services:
44
node:
55
type: lando
6-
image: node:18
6+
image: node:20
77
build:
88
- npm install
99
scanner: false

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
18
1+
20

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## {{ UNRELEASED_VERSION }} - [{{ UNRELEASED_DATE }}]({{ UNRELEASED_LINK }})
2+
3+
- Added CI check to ensure all Node.js versions match package.json.
4+
5+
## v1.0.0-beta.1 - [October 29, 2024](https://github.com/lando/mailpit/releases/tag/v1.0.0-beta.1)
6+
7+
- Initial release of the Mailpit integration plugin for Lando.

README.md

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,61 @@
1-
# Mailpit Plugin for Lando
2-
A [Mailpit](https://mailpit.axllent.org) integration plugin for Lando.
1+
# Mailpit Integration Plugin for Lando
2+
The official [Mailpit](https://mailpit.axllent.org) integration plugin for [Lando](https://lando.dev).
33

44
This is a work in progress. PRs and feedback are appreciated!
55

6+
## Planned Features
7+
8+
- [x] A Mailpit service for receiving emails.
9+
- [x] Mailpit UI accessible at http and https routes.
10+
- [x] Automatic configuration of services to send mail to Mailpit.
11+
- [x] Automatic installation of Mailpit sendmail client and configuration into services that need it.
12+
- [ ] Automatic proxy configuration for the Mailpit UI.
13+
- [ ] A global mailpit service that multiple apps can use.
14+
- [ ] A `lando mailpit` command that interacts with the mailpit service.
15+
- [ ] Automatic configuration of popular frameworks to send mail to Mailpit.
16+
- [ ] Add a mailpit service to a recipe with a single line of configuration.
17+
618
## Installation
719

820
Install the Mailpit plugin:
921
```bash
1022
lando plugin-add @lando/mailpit
1123
```
1224

13-
Add a mailpit service to your project:
25+
Add a mailpit service to your landofile:
1426
```yaml
27+
name: mysite
1528
services:
1629
mailpit:
1730
type: mailpit
18-
mailFrom:
31+
mailFrom: # Optional. The services to send mail from. Defaults to appserver.
1932
- appserver
33+
34+
proxy:
35+
mailpit:
36+
- mailpit.mysite.lndo.site
37+
```
38+
39+
Send mail from your app:
40+
```php
41+
<?php
42+
$to = 'recipient@example.com';
43+
$subject = 'Test email from My App';
44+
$message = 'This is a test email sent via PHP.';
45+
$headers = [
46+
'From: sender@example.com',
47+
'Content-Type: text/plain; charset=utf-8'
48+
];
49+
50+
mail($to, $subject, $message, implode("\r\n", $headers));
51+
52+
// The email will be captured by Mailpit and viewable at:
53+
// http://mailpit.mysite.lndo.site
2054
```
2155

22-
## Developer Information
56+
## Contributing
2357

24-
To get started with this project, follow these steps:
58+
To get started with contributing to this project, follow these steps:
2559

2660
1. Clone the repository:
2761
```bash
@@ -35,7 +69,7 @@ To get started with this project, follow these steps:
3569
```
3670

3771
3. Set up your development environment:
38-
- Ensure you have Node.js 18 or later installed.
72+
- Ensure you have Node.js 20 or later installed.
3973
- If you're using VS Code, consider installing the ESLint extension for real-time linting feedback.
4074

4175
4. Run the tests to verify the current state of the project:
@@ -50,9 +84,10 @@ Now you're ready to start developing! Check the issues page for tasks to work on
5084
This repository is structured as follows:
5185

5286
- `builders/`: Contains the main service builder for the Mailpit plugin.
53-
- `config/`: Contains configuration files used by the Mailpit plugin.
87+
- `config/`: Contains configuration files used in services managed by the Mailpit plugin.
5488
- `test/`: Contains unit test files.
5589
- `examples/`: Example configurations and usage scenarios executed by Leia for testing.
90+
- `utils/`: Utility functions used by the Mailpit plugin.
5691

5792
### Linting
5893

0 commit comments

Comments
 (0)