Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .github/workflows/update-jquery-validate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Update jquery-validation

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

permissions:
contents: write
issues: write
pull-requests: write

jobs:
update-jquery-validate:
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
uses: dotnet/actions-create-pull-request@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: Update jquery.validate to ${{ env.JQUERY_VALIDATE_VERSION }}
title: [Templates][Identity] Update jquery-validation to ${{ env.JQUERY_VALIDATE_VERSION }}
body: |
Updates the jquery-validation scripts to ${{ env.JQUERY_VALIDATE_VERSION }}
# The branch name is based on the date in the format YYYY-MM-DD
branch: update-jquery-validate-to-${{ env.JQUERY_VALIDATE_VERSION }}
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"
}
}