Skip to content

Commit

Permalink
Update jquery validate periodically
Browse files Browse the repository at this point in the history
  • Loading branch information
javiercn committed Jul 10, 2024
1 parent a78ef02 commit 475924a
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/update-jquery-validate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Update jquery.validate

on:
schedule:
- cron: '0 0 1 * *' # Run on the first day of the month
workflow_dispatch: # Allow manual runs

jobs:
update:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'

- name: Set RepoRoot
run: echo "RepoRoot=$(pwd)" >> $GITHUB_ENV

- name: Update dependencies
working-directory: ${{ env.RepoRoot }}/src/Mvc/build
run: |
npm install --no-lockfile
npm run build
echo "JQUERY_VALIDATE_VERSION=$(npm ls jquery-validation --json | jq -r '.dependencies["jquery-validation"].version')" >> $GITHUB_ENV
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: Update jquery.validate to ${{ env.JQUERY_VALIDATE_VERSION }}
title: Update jquery.validate to ${{ env.JQUERY_VALIDATE_VERSION }}
body: |
Update jquery.validate to the latest version.
# The branch name is based on the date in the format YYYY-MM-DD
branch: update-jquery-validate-$(date +'%Y-%m-%d')
base: main
paths: |
**/jquery.validate.js
**/jquery.validate.min.js
37 changes: 37 additions & 0 deletions src/Mvc/build/copy-files.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import * as fs from 'fs';
import * as path from 'path';

const repoRoot = process.env.RepoRoot;
if (!repoRoot) {
throw new Error('RepoRoot environment variable is not set')
}

// Search all the folders in the src directory for the files "jquery.validate.js" and "jquery.validate.min.js" but skip this
// folder as well as the "node_modules" folder, the "bin" folder, and the "obj" folder. Recurse over subfolders.

const srcDir = path.join(repoRoot, 'src');
const files = [];
const search = (dir) => {
const entries = fs.readdirSync(dir, { withFileTypes: true });
for (const entry of entries) {
if (entry.isDirectory() && entry.name !== 'node_modules' && entry.name !== 'bin' && entry.name !== 'obj') {
search(path.join(dir, entry.name));
} else if (entry.isFile() && (entry.name === 'jquery.validate.js' || entry.name === 'jquery.validate.min.js')) {
files.push(path.join(dir, entry.name));
}
}
}

search(srcDir);

// Replace the files found with the versions from <<current-folder>>/node_modules/jquery-validation/dist.
// Note that <<current-folder>>/node_modules/jquery-validation/dist/jquery.validate.js needs to override the
// jquery.validate.js file found in the files array and the same for jquery.validate.min.js.
const nodeModulesDir = path.join(import.meta.dirname, 'node_modules', 'jquery-validation', 'dist');

for (const file of files) {
const source = path.join(nodeModulesDir, path.basename(file));
const target = file;
fs.copyFileSync(source, target);
console.log(`Copied ${path.basename(file)} to ${target}`);
}
11 changes: 11 additions & 0 deletions src/Mvc/build/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "jquery-validation-dependency",
"version": "1.0.0",
"private": true,
"scripts": {
"build": "node copy-files.mjs"
},
"devDependencies": {
"jquery-validation": "^1.20.1"
}
}

0 comments on commit 475924a

Please sign in to comment.