Skip to content

Instantly share code, notes, and snippets.

@rusrushal13
Created September 16, 2025 13:59
Show Gist options
  • Save rusrushal13/68562a37deb149f119b8b3dc751a1b32 to your computer and use it in GitHub Desktop.
Save rusrushal13/68562a37deb149f119b8b3dc751a1b32 to your computer and use it in GitHub Desktop.
Gulp build validation action with IIFE logic for syntax checking
var js_list_admin = [
'lib/thirdparty/jquery/jquery.countTo.version.js',
'lib/thirdparty/jquery/jquery.parallax.1.1.3.js',
'lib/thirdparty/jquery/jquery.browser.0.1.0.js',
'lib/thirdparty/datatables/datatables-datetime-moment.1.10.20.js',
'lib/thirdparty/base64/base64.js',
'routing_admin.js',
'components/admin/**/*.component.js',
'components/admin/**/*.service.js',
'controllers/admin*.js',
'controllers/client_admin_*.js',
'controllers/all*.js',
'controllers/tfa*.js',
'app_common.js',
'services/*.js',
'directives/*.js',
'filters/*.js',
'controllers/common*.js',
'components/admin/**/*.js',
'components/common/**/*.js',
'controllers/survey*.js',
'components/payer-expertise/payer_expertise_form.component.js'
].map(function(el) {
return build_path0 + el;
});
// Debug function to test individual files for syntax errors
// to use it, run: gulp debug-js-admin --staging
function debugJS(file_list, callback) {
var fs = require('fs');
var glob = require('glob');
// eslint-disable-next-line no-console
console.log('Debugging JavaScript files for syntax errors...');
file_list.forEach(function(file_pattern) {
// Use glob to expand patterns
var files = glob.sync(file_pattern);
files.forEach(function(file) {
try {
if (fs.existsSync(file)) {
// eslint-disable-next-line no-console
console.log('Testing file: ' + file);
var content = fs.readFileSync(file, 'utf8');
// Try to create a function to test syntax
new Function(content);
// eslint-disable-next-line no-console
console.log('✓ OK: ' + file);
} else {
// eslint-disable-next-line no-console
console.log('⚠ File not found: ' + file);
}
} catch (err) {
// eslint-disable-next-line no-console
console.log('✗ SYNTAX ERROR in file: ' + file);
// eslint-disable-next-line no-console
console.log('Error:', err.message);
// eslint-disable-next-line no-console
console.log('Line:', err.lineNumber || 'unknown');
// eslint-disable-next-line no-console
console.log('Column:', err.columnNumber || 'unknown');
// eslint-disable-next-line no-console
console.log('---');
}
});
});
if (callback) callback();
}
// Debug task to identify syntax errors in admin JS files
gulp.task('debug-js-admin', ['deploy-step0'], function(callback) {
debugJS(js_list_admin, callback);
});
name: JavaScript Build Validation
on:
pull_request:
env:
NODE_VERSION: '8.12.0'
jobs:
validate-js-build:
runs-on: ubuntu-latest
if: |
!contains(github.event.pull_request.labels.*.name, 'nojsvalidation')
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- uses: actions/cache@v4
id: npm-cache
with:
path: ~/.npm
key: ${{ runner.os }}-npm-${{ hashFiles('portal/package.json') }}
restore-keys: |
${{ runner.os }}-npm-
- name: Install NPM dependencies
run: |
cd portal
npm install -g [email protected]
npm install
- name: Run JavaScript syntax validation
run: |
cd portal
gulp debug-js-admin --staging
- name: Test JavaScript build process
run: |
cd portal
gulp deploy-step0 --staging
- name: Validate admin JS concatenation
run: |
cd portal
gulp pack-js-admin --staging
- name: Comment on PR with success
if: success()
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body: '✅ **JavaScript Build Validation Passed**\n\nAll JavaScript files passed syntax validation and build tests.'
});
- name: Comment on PR with failure details
if: failure()
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body: '❌ **JavaScript Build Validation Failed**\n\nThere are JavaScript syntax errors that will cause the build to fail. Please check the workflow logs for details and fix the syntax errors before deploying.'
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment