Skip to content

Commit 475924a

Browse files
committed
Update jquery validate periodically
1 parent a78ef02 commit 475924a

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Update jquery.validate
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 1 * *' # Run on the first day of the month
6+
workflow_dispatch: # Allow manual runs
7+
8+
jobs:
9+
update:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v2
15+
16+
- name: Setup Node.js
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version: '20.x'
20+
21+
- name: Set RepoRoot
22+
run: echo "RepoRoot=$(pwd)" >> $GITHUB_ENV
23+
24+
- name: Update dependencies
25+
working-directory: ${{ env.RepoRoot }}/src/Mvc/build
26+
run: |
27+
npm install --no-lockfile
28+
npm run build
29+
echo "JQUERY_VALIDATE_VERSION=$(npm ls jquery-validation --json | jq -r '.dependencies["jquery-validation"].version')" >> $GITHUB_ENV
30+
31+
- name: Create Pull Request
32+
id: cpr
33+
uses: peter-evans/create-pull-request@v6
34+
with:
35+
token: ${{ secrets.GITHUB_TOKEN }}
36+
commit-message: Update jquery.validate to ${{ env.JQUERY_VALIDATE_VERSION }}
37+
title: Update jquery.validate to ${{ env.JQUERY_VALIDATE_VERSION }}
38+
body: |
39+
Update jquery.validate to the latest version.
40+
# The branch name is based on the date in the format YYYY-MM-DD
41+
branch: update-jquery-validate-$(date +'%Y-%m-%d')
42+
base: main
43+
paths: |
44+
**/jquery.validate.js
45+
**/jquery.validate.min.js

src/Mvc/build/copy-files.mjs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import * as fs from 'fs';
2+
import * as path from 'path';
3+
4+
const repoRoot = process.env.RepoRoot;
5+
if (!repoRoot) {
6+
throw new Error('RepoRoot environment variable is not set')
7+
}
8+
9+
// Search all the folders in the src directory for the files "jquery.validate.js" and "jquery.validate.min.js" but skip this
10+
// folder as well as the "node_modules" folder, the "bin" folder, and the "obj" folder. Recurse over subfolders.
11+
12+
const srcDir = path.join(repoRoot, 'src');
13+
const files = [];
14+
const search = (dir) => {
15+
const entries = fs.readdirSync(dir, { withFileTypes: true });
16+
for (const entry of entries) {
17+
if (entry.isDirectory() && entry.name !== 'node_modules' && entry.name !== 'bin' && entry.name !== 'obj') {
18+
search(path.join(dir, entry.name));
19+
} else if (entry.isFile() && (entry.name === 'jquery.validate.js' || entry.name === 'jquery.validate.min.js')) {
20+
files.push(path.join(dir, entry.name));
21+
}
22+
}
23+
}
24+
25+
search(srcDir);
26+
27+
// Replace the files found with the versions from <<current-folder>>/node_modules/jquery-validation/dist.
28+
// Note that <<current-folder>>/node_modules/jquery-validation/dist/jquery.validate.js needs to override the
29+
// jquery.validate.js file found in the files array and the same for jquery.validate.min.js.
30+
const nodeModulesDir = path.join(import.meta.dirname, 'node_modules', 'jquery-validation', 'dist');
31+
32+
for (const file of files) {
33+
const source = path.join(nodeModulesDir, path.basename(file));
34+
const target = file;
35+
fs.copyFileSync(source, target);
36+
console.log(`Copied ${path.basename(file)} to ${target}`);
37+
}

src/Mvc/build/package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "jquery-validation-dependency",
3+
"version": "1.0.0",
4+
"private": true,
5+
"scripts": {
6+
"build": "node copy-files.mjs"
7+
},
8+
"devDependencies": {
9+
"jquery-validation": "^1.20.1"
10+
}
11+
}

0 commit comments

Comments
 (0)