Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Infrastructure] Update jquery validate periodically #56725

Merged
merged 17 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Update jquery validate periodically
  • Loading branch information
javiercn committed Jul 10, 2024
commit 475924a620b61a6696a7278b162538e3a80d29f9
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 }}
javiercn marked this conversation as resolved.
Show resolved Hide resolved
body: |
Update jquery.validate to the latest version.
javiercn marked this conversation as resolved.
Show resolved Hide resolved
# The branch name is based on the date in the format YYYY-MM-DD
javiercn marked this conversation as resolved.
Show resolved Hide resolved
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.
javiercn marked this conversation as resolved.
Show resolved Hide resolved

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.
javiercn marked this conversation as resolved.
Show resolved Hide resolved
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"
}
}
Loading