@happychef/algorithm 1.2.11 → 1.2.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci-cd.yml +234 -234
- package/BRANCH_PROTECTION_SETUP.md +167 -167
- package/CHANGELOG.md +8 -8
- package/README.md +144 -144
- package/RESERVERINGEN_GIDS.md +986 -986
- package/__tests__/filters.test.js +276 -276
- package/__tests__/isDateAvailable.test.js +175 -175
- package/__tests__/isTimeAvailable.test.js +168 -168
- package/__tests__/restaurantData.test.js +422 -422
- package/__tests__/tableHelpers.test.js +247 -247
- package/assignTables.js +424 -424
- package/changes/2025/December/PR2___change.md +14 -14
- package/changes/2025/December/PR3_add__change.md +20 -20
- package/changes/2025/December/PR4___.md +15 -15
- package/changes/2025/December/PR5___.md +15 -15
- package/changes/2025/December/PR6__del_.md +17 -17
- package/changes/2025/December/PR7_add__change.md +21 -21
- package/changes/2026/January/PR8_add__change.md +39 -0
- package/changes/2026/January/PR9_add__change.md +20 -0
- package/filters/maxArrivalsFilter.js +114 -114
- package/filters/maxGroupsFilter.js +221 -221
- package/filters/timeFilter.js +89 -89
- package/getAvailableTimeblocks.js +158 -158
- package/grouping.js +162 -162
- package/index.js +42 -42
- package/isDateAvailable.js +80 -80
- package/isDateAvailableWithTableCheck.js +171 -171
- package/isTimeAvailable.js +25 -25
- package/jest.config.js +23 -23
- package/package.json +27 -27
- package/processing/dailyGuestCounts.js +73 -73
- package/processing/mealTypeCount.js +133 -133
- package/processing/timeblocksAvailable.js +167 -167
- package/reservation_data/counter.js +64 -64
- package/restaurant_data/exceptions.js +149 -149
- package/restaurant_data/openinghours.js +123 -123
- package/simulateTableAssignment.js +709 -699
- package/tableHelpers.js +178 -178
- package/tables/time/parseTime.js +19 -19
- package/tables/time/shifts.js +7 -7
- package/tables/utils/calculateDistance.js +13 -13
- package/tables/utils/isTableFreeForAllSlots.js +14 -14
- package/tables/utils/isTemporaryTableValid.js +39 -39
- package/test/test_counter.js +194 -194
- package/test/test_dailyCount.js +81 -81
- package/test/test_datesAvailable.js +106 -106
- package/test/test_exceptions.js +172 -172
- package/test/test_isDateAvailable.js +330 -330
- package/test/test_mealTypeCount.js +54 -54
- package/test/test_timesAvailable.js +88 -88
- package/test-detailed-filter.js +100 -100
- package/test-lunch-debug.js +110 -110
- package/test-max-arrivals-filter.js +79 -79
- package/test-meal-stop-fix.js +147 -147
- package/test-meal-stop-simple.js +93 -93
- package/test-timezone-debug.js +47 -47
- package/test.js +336 -336
|
@@ -1,234 +1,234 @@
|
|
|
1
|
-
name: CI/CD Pipeline
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches:
|
|
6
|
-
- main
|
|
7
|
-
pull_request:
|
|
8
|
-
branches:
|
|
9
|
-
- main
|
|
10
|
-
types: [opened, synchronize, reopened]
|
|
11
|
-
|
|
12
|
-
jobs:
|
|
13
|
-
test:
|
|
14
|
-
name: Run Tests
|
|
15
|
-
runs-on: ubuntu-latest
|
|
16
|
-
|
|
17
|
-
strategy:
|
|
18
|
-
matrix:
|
|
19
|
-
node-version: [18.x, 20.x]
|
|
20
|
-
|
|
21
|
-
steps:
|
|
22
|
-
- name: Checkout code
|
|
23
|
-
uses: actions/checkout@v4
|
|
24
|
-
|
|
25
|
-
- name: Setup Node.js ${{ matrix.node-version }}
|
|
26
|
-
uses: actions/setup-node@v4
|
|
27
|
-
with:
|
|
28
|
-
node-version: ${{ matrix.node-version }}
|
|
29
|
-
cache: 'npm'
|
|
30
|
-
|
|
31
|
-
- name: Install dependencies
|
|
32
|
-
run: npm ci
|
|
33
|
-
|
|
34
|
-
- name: Run tests
|
|
35
|
-
id: test-run
|
|
36
|
-
run: npm test -- --verbose 2>&1 | tee test-output.txt
|
|
37
|
-
continue-on-error: true
|
|
38
|
-
|
|
39
|
-
- name: Run tests with coverage
|
|
40
|
-
if: always()
|
|
41
|
-
run: npm run test:coverage
|
|
42
|
-
continue-on-error: true
|
|
43
|
-
|
|
44
|
-
- name: Generate test summary
|
|
45
|
-
if: always()
|
|
46
|
-
run: |
|
|
47
|
-
echo "## Test Results for Node.js ${{ matrix.node-version }}" >> $GITHUB_STEP_SUMMARY
|
|
48
|
-
echo "" >> $GITHUB_STEP_SUMMARY
|
|
49
|
-
|
|
50
|
-
# Extract test results
|
|
51
|
-
TEST_OUTPUT=$(cat test-output.txt)
|
|
52
|
-
|
|
53
|
-
if echo "$TEST_OUTPUT" | grep -q "Tests:.*failed"; then
|
|
54
|
-
echo "❌ **Tests Failed**" >> $GITHUB_STEP_SUMMARY
|
|
55
|
-
echo "" >> $GITHUB_STEP_SUMMARY
|
|
56
|
-
|
|
57
|
-
# Extract summary line
|
|
58
|
-
SUMMARY=$(echo "$TEST_OUTPUT" | grep "Test Suites:" | tail -1)
|
|
59
|
-
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
|
|
60
|
-
echo "$SUMMARY" >> $GITHUB_STEP_SUMMARY
|
|
61
|
-
echo "$TEST_OUTPUT" | grep "Tests:" | tail -1 >> $GITHUB_STEP_SUMMARY
|
|
62
|
-
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
|
|
63
|
-
echo "" >> $GITHUB_STEP_SUMMARY
|
|
64
|
-
|
|
65
|
-
# Show failed tests
|
|
66
|
-
echo "### Failed Tests:" >> $GITHUB_STEP_SUMMARY
|
|
67
|
-
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
|
|
68
|
-
echo "$TEST_OUTPUT" | grep -A 10 "FAIL" | head -30 >> $GITHUB_STEP_SUMMARY
|
|
69
|
-
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
|
|
70
|
-
else
|
|
71
|
-
echo "✅ **All Tests Passed!**" >> $GITHUB_STEP_SUMMARY
|
|
72
|
-
echo "" >> $GITHUB_STEP_SUMMARY
|
|
73
|
-
|
|
74
|
-
# Extract summary line
|
|
75
|
-
SUMMARY=$(echo "$TEST_OUTPUT" | grep "Test Suites:" | tail -1)
|
|
76
|
-
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
|
|
77
|
-
echo "$SUMMARY" >> $GITHUB_STEP_SUMMARY
|
|
78
|
-
echo "$TEST_OUTPUT" | grep "Tests:" | tail -1 >> $GITHUB_STEP_SUMMARY
|
|
79
|
-
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
|
|
80
|
-
fi
|
|
81
|
-
|
|
82
|
-
- name: Comment PR with test results
|
|
83
|
-
if: always() && github.event_name == 'pull_request' && matrix.node-version == '20.x'
|
|
84
|
-
uses: actions/github-script@v7
|
|
85
|
-
with:
|
|
86
|
-
script: |
|
|
87
|
-
const fs = require('fs');
|
|
88
|
-
const testOutput = fs.readFileSync('test-output.txt', 'utf8');
|
|
89
|
-
|
|
90
|
-
// Check if tests failed
|
|
91
|
-
const hasFailed = testOutput.includes('FAIL');
|
|
92
|
-
const summaryLine = testOutput.match(/Test Suites:.*$/m)?.[0] || '';
|
|
93
|
-
const testsLine = testOutput.match(/Tests:.*$/m)?.[0] || '';
|
|
94
|
-
|
|
95
|
-
let comment = '';
|
|
96
|
-
|
|
97
|
-
if (hasFailed) {
|
|
98
|
-
comment = `## ❌ Tests Failed on Node.js ${{ matrix.node-version }}
|
|
99
|
-
|
|
100
|
-
**Summary:**
|
|
101
|
-
\`\`\`
|
|
102
|
-
${summaryLine}
|
|
103
|
-
${testsLine}
|
|
104
|
-
\`\`\`
|
|
105
|
-
|
|
106
|
-
### 🔴 Failed Tests Details:
|
|
107
|
-
|
|
108
|
-
`;
|
|
109
|
-
|
|
110
|
-
// Extract failed test details
|
|
111
|
-
const failedTests = testOutput.match(/FAIL.*\n(.*\n){0,15}/g) || [];
|
|
112
|
-
failedTests.forEach(fail => {
|
|
113
|
-
const lines = fail.split('\n').slice(0, 10);
|
|
114
|
-
comment += '\`\`\`\n' + lines.join('\n') + '\n\`\`\`\n\n';
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
comment += `
|
|
118
|
-
### 💡 What to do:
|
|
119
|
-
1. Review the failed test(s) above
|
|
120
|
-
2. Fix the issues in your code
|
|
121
|
-
3. Push the changes to this PR
|
|
122
|
-
4. Tests will run automatically again
|
|
123
|
-
|
|
124
|
-
**This PR cannot be merged until all tests pass.**
|
|
125
|
-
`;
|
|
126
|
-
} else {
|
|
127
|
-
comment = `## ✅ All Tests Passed on Node.js ${{ matrix.node-version }}
|
|
128
|
-
|
|
129
|
-
**Summary:**
|
|
130
|
-
\`\`\`
|
|
131
|
-
${summaryLine}
|
|
132
|
-
${testsLine}
|
|
133
|
-
\`\`\`
|
|
134
|
-
|
|
135
|
-
### 🎉 Great work!
|
|
136
|
-
All tests are passing. This PR is ready to be reviewed and merged.
|
|
137
|
-
|
|
138
|
-
**Next steps:**
|
|
139
|
-
- Wait for code review (if required)
|
|
140
|
-
- Merge when ready
|
|
141
|
-
`;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// Post comment
|
|
145
|
-
github.rest.issues.createComment({
|
|
146
|
-
issue_number: context.issue.number,
|
|
147
|
-
owner: context.repo.owner,
|
|
148
|
-
repo: context.repo.repo,
|
|
149
|
-
body: comment
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
- name: Upload coverage reports
|
|
153
|
-
uses: codecov/codecov-action@v4
|
|
154
|
-
if: matrix.node-version == '20.x'
|
|
155
|
-
with:
|
|
156
|
-
files: ./coverage/lcov.info
|
|
157
|
-
flags: unittests
|
|
158
|
-
name: codecov-umbrella
|
|
159
|
-
fail_ci_if_error: false
|
|
160
|
-
env:
|
|
161
|
-
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
|
|
162
|
-
|
|
163
|
-
publish:
|
|
164
|
-
name: Publish to NPM
|
|
165
|
-
needs: test
|
|
166
|
-
runs-on: ubuntu-latest
|
|
167
|
-
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
|
|
168
|
-
|
|
169
|
-
steps:
|
|
170
|
-
- name: Checkout code
|
|
171
|
-
uses: actions/checkout@v4
|
|
172
|
-
|
|
173
|
-
- name: Setup Node.js
|
|
174
|
-
uses: actions/setup-node@v4
|
|
175
|
-
with:
|
|
176
|
-
node-version: '20.x'
|
|
177
|
-
registry-url: 'https://registry.npmjs.org'
|
|
178
|
-
cache: 'npm'
|
|
179
|
-
|
|
180
|
-
- name: Install dependencies
|
|
181
|
-
run: npm ci
|
|
182
|
-
|
|
183
|
-
- name: Run tests
|
|
184
|
-
run: npm test
|
|
185
|
-
|
|
186
|
-
- name: Check if version changed
|
|
187
|
-
id: version-check
|
|
188
|
-
run: |
|
|
189
|
-
PACKAGE_VERSION=$(node -p "require('./package.json').version")
|
|
190
|
-
NPM_VERSION=$(npm view @happychef/algorithm version 2>/dev/null || echo "0.0.0")
|
|
191
|
-
echo "Package version: $PACKAGE_VERSION"
|
|
192
|
-
echo "NPM version: $NPM_VERSION"
|
|
193
|
-
if [ "$PACKAGE_VERSION" != "$NPM_VERSION" ]; then
|
|
194
|
-
echo "version_changed=true" >> $GITHUB_OUTPUT
|
|
195
|
-
echo "Version changed from $NPM_VERSION to $PACKAGE_VERSION"
|
|
196
|
-
else
|
|
197
|
-
echo "version_changed=false" >> $GITHUB_OUTPUT
|
|
198
|
-
echo "Version unchanged: $PACKAGE_VERSION"
|
|
199
|
-
fi
|
|
200
|
-
|
|
201
|
-
- name: Publish to NPM
|
|
202
|
-
if: steps.version-check.outputs.version_changed == 'true'
|
|
203
|
-
run: |
|
|
204
|
-
npm publish --access public
|
|
205
|
-
echo "## 📦 NPM Package Published" >> $GITHUB_STEP_SUMMARY
|
|
206
|
-
echo "" >> $GITHUB_STEP_SUMMARY
|
|
207
|
-
echo "✅ Successfully published @happychef/algorithm@$(node -p "require('./package.json').version")" >> $GITHUB_STEP_SUMMARY
|
|
208
|
-
echo "" >> $GITHUB_STEP_SUMMARY
|
|
209
|
-
echo "🔗 [View on NPM](https://www.npmjs.com/package/@happychef/algorithm)" >> $GITHUB_STEP_SUMMARY
|
|
210
|
-
env:
|
|
211
|
-
NODE_AUTH_TOKEN: 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
|
|
212
|
-
|
|
213
|
-
- name: Skip publishing (version unchanged)
|
|
214
|
-
if: steps.version-check.outputs.version_changed == 'false'
|
|
215
|
-
run: |
|
|
216
|
-
echo "## ⏭️ Publishing Skipped" >> $GITHUB_STEP_SUMMARY
|
|
217
|
-
echo "" >> $GITHUB_STEP_SUMMARY
|
|
218
|
-
echo "Version $(node -p "require('./package.json').version") is already published" >> $GITHUB_STEP_SUMMARY
|
|
219
|
-
echo "" >> $GITHUB_STEP_SUMMARY
|
|
220
|
-
echo "💡 Bump the version in package.json to trigger publishing" >> $GITHUB_STEP_SUMMARY
|
|
221
|
-
|
|
222
|
-
- name: Create Git Tag
|
|
223
|
-
if: steps.version-check.outputs.version_changed == 'true'
|
|
224
|
-
run: |
|
|
225
|
-
PACKAGE_VERSION=$(node -p "require('./package.json').version")
|
|
226
|
-
git config user.name "github-actions[bot]"
|
|
227
|
-
git config user.email "github-actions[bot]@users.noreply.github.com"
|
|
228
|
-
git tag -a "v$PACKAGE_VERSION" -m "Release v$PACKAGE_VERSION"
|
|
229
|
-
git push origin "v$PACKAGE_VERSION"
|
|
230
|
-
echo "## 🏷️ Git Tag Created" >> $GITHUB_STEP_SUMMARY
|
|
231
|
-
echo "" >> $GITHUB_STEP_SUMMARY
|
|
232
|
-
echo "Created and pushed tag: v$PACKAGE_VERSION" >> $GITHUB_STEP_SUMMARY
|
|
233
|
-
env:
|
|
234
|
-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
1
|
+
name: CI/CD Pipeline
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
pull_request:
|
|
8
|
+
branches:
|
|
9
|
+
- main
|
|
10
|
+
types: [opened, synchronize, reopened]
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
test:
|
|
14
|
+
name: Run Tests
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
|
|
17
|
+
strategy:
|
|
18
|
+
matrix:
|
|
19
|
+
node-version: [18.x, 20.x]
|
|
20
|
+
|
|
21
|
+
steps:
|
|
22
|
+
- name: Checkout code
|
|
23
|
+
uses: actions/checkout@v4
|
|
24
|
+
|
|
25
|
+
- name: Setup Node.js ${{ matrix.node-version }}
|
|
26
|
+
uses: actions/setup-node@v4
|
|
27
|
+
with:
|
|
28
|
+
node-version: ${{ matrix.node-version }}
|
|
29
|
+
cache: 'npm'
|
|
30
|
+
|
|
31
|
+
- name: Install dependencies
|
|
32
|
+
run: npm ci
|
|
33
|
+
|
|
34
|
+
- name: Run tests
|
|
35
|
+
id: test-run
|
|
36
|
+
run: npm test -- --verbose 2>&1 | tee test-output.txt
|
|
37
|
+
continue-on-error: true
|
|
38
|
+
|
|
39
|
+
- name: Run tests with coverage
|
|
40
|
+
if: always()
|
|
41
|
+
run: npm run test:coverage
|
|
42
|
+
continue-on-error: true
|
|
43
|
+
|
|
44
|
+
- name: Generate test summary
|
|
45
|
+
if: always()
|
|
46
|
+
run: |
|
|
47
|
+
echo "## Test Results for Node.js ${{ matrix.node-version }}" >> $GITHUB_STEP_SUMMARY
|
|
48
|
+
echo "" >> $GITHUB_STEP_SUMMARY
|
|
49
|
+
|
|
50
|
+
# Extract test results
|
|
51
|
+
TEST_OUTPUT=$(cat test-output.txt)
|
|
52
|
+
|
|
53
|
+
if echo "$TEST_OUTPUT" | grep -q "Tests:.*failed"; then
|
|
54
|
+
echo "❌ **Tests Failed**" >> $GITHUB_STEP_SUMMARY
|
|
55
|
+
echo "" >> $GITHUB_STEP_SUMMARY
|
|
56
|
+
|
|
57
|
+
# Extract summary line
|
|
58
|
+
SUMMARY=$(echo "$TEST_OUTPUT" | grep "Test Suites:" | tail -1)
|
|
59
|
+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
|
|
60
|
+
echo "$SUMMARY" >> $GITHUB_STEP_SUMMARY
|
|
61
|
+
echo "$TEST_OUTPUT" | grep "Tests:" | tail -1 >> $GITHUB_STEP_SUMMARY
|
|
62
|
+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
|
|
63
|
+
echo "" >> $GITHUB_STEP_SUMMARY
|
|
64
|
+
|
|
65
|
+
# Show failed tests
|
|
66
|
+
echo "### Failed Tests:" >> $GITHUB_STEP_SUMMARY
|
|
67
|
+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
|
|
68
|
+
echo "$TEST_OUTPUT" | grep -A 10 "FAIL" | head -30 >> $GITHUB_STEP_SUMMARY
|
|
69
|
+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
|
|
70
|
+
else
|
|
71
|
+
echo "✅ **All Tests Passed!**" >> $GITHUB_STEP_SUMMARY
|
|
72
|
+
echo "" >> $GITHUB_STEP_SUMMARY
|
|
73
|
+
|
|
74
|
+
# Extract summary line
|
|
75
|
+
SUMMARY=$(echo "$TEST_OUTPUT" | grep "Test Suites:" | tail -1)
|
|
76
|
+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
|
|
77
|
+
echo "$SUMMARY" >> $GITHUB_STEP_SUMMARY
|
|
78
|
+
echo "$TEST_OUTPUT" | grep "Tests:" | tail -1 >> $GITHUB_STEP_SUMMARY
|
|
79
|
+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
|
|
80
|
+
fi
|
|
81
|
+
|
|
82
|
+
- name: Comment PR with test results
|
|
83
|
+
if: always() && github.event_name == 'pull_request' && matrix.node-version == '20.x'
|
|
84
|
+
uses: actions/github-script@v7
|
|
85
|
+
with:
|
|
86
|
+
script: |
|
|
87
|
+
const fs = require('fs');
|
|
88
|
+
const testOutput = fs.readFileSync('test-output.txt', 'utf8');
|
|
89
|
+
|
|
90
|
+
// Check if tests failed
|
|
91
|
+
const hasFailed = testOutput.includes('FAIL');
|
|
92
|
+
const summaryLine = testOutput.match(/Test Suites:.*$/m)?.[0] || '';
|
|
93
|
+
const testsLine = testOutput.match(/Tests:.*$/m)?.[0] || '';
|
|
94
|
+
|
|
95
|
+
let comment = '';
|
|
96
|
+
|
|
97
|
+
if (hasFailed) {
|
|
98
|
+
comment = `## ❌ Tests Failed on Node.js ${{ matrix.node-version }}
|
|
99
|
+
|
|
100
|
+
**Summary:**
|
|
101
|
+
\`\`\`
|
|
102
|
+
${summaryLine}
|
|
103
|
+
${testsLine}
|
|
104
|
+
\`\`\`
|
|
105
|
+
|
|
106
|
+
### 🔴 Failed Tests Details:
|
|
107
|
+
|
|
108
|
+
`;
|
|
109
|
+
|
|
110
|
+
// Extract failed test details
|
|
111
|
+
const failedTests = testOutput.match(/FAIL.*\n(.*\n){0,15}/g) || [];
|
|
112
|
+
failedTests.forEach(fail => {
|
|
113
|
+
const lines = fail.split('\n').slice(0, 10);
|
|
114
|
+
comment += '\`\`\`\n' + lines.join('\n') + '\n\`\`\`\n\n';
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
comment += `
|
|
118
|
+
### 💡 What to do:
|
|
119
|
+
1. Review the failed test(s) above
|
|
120
|
+
2. Fix the issues in your code
|
|
121
|
+
3. Push the changes to this PR
|
|
122
|
+
4. Tests will run automatically again
|
|
123
|
+
|
|
124
|
+
**This PR cannot be merged until all tests pass.**
|
|
125
|
+
`;
|
|
126
|
+
} else {
|
|
127
|
+
comment = `## ✅ All Tests Passed on Node.js ${{ matrix.node-version }}
|
|
128
|
+
|
|
129
|
+
**Summary:**
|
|
130
|
+
\`\`\`
|
|
131
|
+
${summaryLine}
|
|
132
|
+
${testsLine}
|
|
133
|
+
\`\`\`
|
|
134
|
+
|
|
135
|
+
### 🎉 Great work!
|
|
136
|
+
All tests are passing. This PR is ready to be reviewed and merged.
|
|
137
|
+
|
|
138
|
+
**Next steps:**
|
|
139
|
+
- Wait for code review (if required)
|
|
140
|
+
- Merge when ready
|
|
141
|
+
`;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Post comment
|
|
145
|
+
github.rest.issues.createComment({
|
|
146
|
+
issue_number: context.issue.number,
|
|
147
|
+
owner: context.repo.owner,
|
|
148
|
+
repo: context.repo.repo,
|
|
149
|
+
body: comment
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
- name: Upload coverage reports
|
|
153
|
+
uses: codecov/codecov-action@v4
|
|
154
|
+
if: matrix.node-version == '20.x'
|
|
155
|
+
with:
|
|
156
|
+
files: ./coverage/lcov.info
|
|
157
|
+
flags: unittests
|
|
158
|
+
name: codecov-umbrella
|
|
159
|
+
fail_ci_if_error: false
|
|
160
|
+
env:
|
|
161
|
+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
|
|
162
|
+
|
|
163
|
+
publish:
|
|
164
|
+
name: Publish to NPM
|
|
165
|
+
needs: test
|
|
166
|
+
runs-on: ubuntu-latest
|
|
167
|
+
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
|
|
168
|
+
|
|
169
|
+
steps:
|
|
170
|
+
- name: Checkout code
|
|
171
|
+
uses: actions/checkout@v4
|
|
172
|
+
|
|
173
|
+
- name: Setup Node.js
|
|
174
|
+
uses: actions/setup-node@v4
|
|
175
|
+
with:
|
|
176
|
+
node-version: '20.x'
|
|
177
|
+
registry-url: 'https://registry.npmjs.org'
|
|
178
|
+
cache: 'npm'
|
|
179
|
+
|
|
180
|
+
- name: Install dependencies
|
|
181
|
+
run: npm ci
|
|
182
|
+
|
|
183
|
+
- name: Run tests
|
|
184
|
+
run: npm test
|
|
185
|
+
|
|
186
|
+
- name: Check if version changed
|
|
187
|
+
id: version-check
|
|
188
|
+
run: |
|
|
189
|
+
PACKAGE_VERSION=$(node -p "require('./package.json').version")
|
|
190
|
+
NPM_VERSION=$(npm view @happychef/algorithm version 2>/dev/null || echo "0.0.0")
|
|
191
|
+
echo "Package version: $PACKAGE_VERSION"
|
|
192
|
+
echo "NPM version: $NPM_VERSION"
|
|
193
|
+
if [ "$PACKAGE_VERSION" != "$NPM_VERSION" ]; then
|
|
194
|
+
echo "version_changed=true" >> $GITHUB_OUTPUT
|
|
195
|
+
echo "Version changed from $NPM_VERSION to $PACKAGE_VERSION"
|
|
196
|
+
else
|
|
197
|
+
echo "version_changed=false" >> $GITHUB_OUTPUT
|
|
198
|
+
echo "Version unchanged: $PACKAGE_VERSION"
|
|
199
|
+
fi
|
|
200
|
+
|
|
201
|
+
- name: Publish to NPM
|
|
202
|
+
if: steps.version-check.outputs.version_changed == 'true'
|
|
203
|
+
run: |
|
|
204
|
+
npm publish --access public
|
|
205
|
+
echo "## 📦 NPM Package Published" >> $GITHUB_STEP_SUMMARY
|
|
206
|
+
echo "" >> $GITHUB_STEP_SUMMARY
|
|
207
|
+
echo "✅ Successfully published @happychef/algorithm@$(node -p "require('./package.json').version")" >> $GITHUB_STEP_SUMMARY
|
|
208
|
+
echo "" >> $GITHUB_STEP_SUMMARY
|
|
209
|
+
echo "🔗 [View on NPM](https://www.npmjs.com/package/@happychef/algorithm)" >> $GITHUB_STEP_SUMMARY
|
|
210
|
+
env:
|
|
211
|
+
NODE_AUTH_TOKEN: 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
|
|
212
|
+
|
|
213
|
+
- name: Skip publishing (version unchanged)
|
|
214
|
+
if: steps.version-check.outputs.version_changed == 'false'
|
|
215
|
+
run: |
|
|
216
|
+
echo "## ⏭️ Publishing Skipped" >> $GITHUB_STEP_SUMMARY
|
|
217
|
+
echo "" >> $GITHUB_STEP_SUMMARY
|
|
218
|
+
echo "Version $(node -p "require('./package.json').version") is already published" >> $GITHUB_STEP_SUMMARY
|
|
219
|
+
echo "" >> $GITHUB_STEP_SUMMARY
|
|
220
|
+
echo "💡 Bump the version in package.json to trigger publishing" >> $GITHUB_STEP_SUMMARY
|
|
221
|
+
|
|
222
|
+
- name: Create Git Tag
|
|
223
|
+
if: steps.version-check.outputs.version_changed == 'true'
|
|
224
|
+
run: |
|
|
225
|
+
PACKAGE_VERSION=$(node -p "require('./package.json').version")
|
|
226
|
+
git config user.name "github-actions[bot]"
|
|
227
|
+
git config user.email "github-actions[bot]@users.noreply.github.com"
|
|
228
|
+
git tag -a "v$PACKAGE_VERSION" -m "Release v$PACKAGE_VERSION"
|
|
229
|
+
git push origin "v$PACKAGE_VERSION"
|
|
230
|
+
echo "## 🏷️ Git Tag Created" >> $GITHUB_STEP_SUMMARY
|
|
231
|
+
echo "" >> $GITHUB_STEP_SUMMARY
|
|
232
|
+
echo "Created and pushed tag: v$PACKAGE_VERSION" >> $GITHUB_STEP_SUMMARY
|
|
233
|
+
env:
|
|
234
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|