diff --git a/workflow-templates/eslint.properties.json b/workflow-templates/eslint.properties.json new file mode 100644 index 0000000..9c4b232 --- /dev/null +++ b/workflow-templates/eslint.properties.json @@ -0,0 +1,13 @@ +{ + "name": "ESLint Check", + "description": "This template runs ESLint to check for linting errors in the project.", + "iconName": "octicon-lint", + "categories": [ + "JavaScript", + "TypeScript" + ], + "filePatterns": [ + "src/**/*.js", + "src/**/*.ts" + ] +} diff --git a/workflow-templates/eslint.yml b/workflow-templates/eslint.yml new file mode 100644 index 0000000..ce42635 --- /dev/null +++ b/workflow-templates/eslint.yml @@ -0,0 +1,46 @@ +name: Linting # This can include other types of linting later on + +on: + push: + branches: + - main + - master + - develop + pull_request: + branches: + - main + - master + - develop + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up Node.js + uses: actions/setup-node@v2 + with: + node-version: '16' + - name: Install dependencies + run: npm install + + # Get the list of changed files in the PR + - name: Get list of changed files + id: changed-files + run: | + git fetch origin ${{ github.base_ref }} + git diff --name-only origin/${{ github.base_ref }}...${{ github.sha }} > changed_files.txt + cat changed_files.txt + + + # Run linter only on changed JavaScript/TypeScript files + - name: Run linter on changed JavaScript/TypeScript files + run: | + CHANGED_FILES=$(cat changed_files.txt | grep '\.js\|\.jsx\|\.ts\|\.tsx' || true) + if [ -n "$CHANGED_FILES" ]; then + echo "Linting the following files:" + echo "$CHANGED_FILES" + npx eslint $CHANGED_FILES + else + echo "No JavaScript/TypeScript files to lint." + fi diff --git a/workflow-templates/npm-audit.properties.json b/workflow-templates/npm-audit.properties.json new file mode 100644 index 0000000..2c2cd7e --- /dev/null +++ b/workflow-templates/npm-audit.properties.json @@ -0,0 +1,13 @@ +{ + "name": "NPM Audit", + "description": "This template runs npm audit to check for vulnerabilities in dependencies.", + "iconName": "octicon-security", + "categories": [ + "Security", + "JavaScript" + ], + "filePatterns": [ + "package.json$", + "package-lock.json$" + ] +} diff --git a/workflow-templates/npm-audit.yml b/workflow-templates/npm-audit.yml new file mode 100644 index 0000000..314266f --- /dev/null +++ b/workflow-templates/npm-audit.yml @@ -0,0 +1,30 @@ +name: npm Audit + +on: + pull_request: + paths: + - 'package.json' + - 'package-lock.json' + +jobs: + audit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install dependencies + run: npm install + + - name: Run npm audit (Allow skipping unfixed vulnerabilities) + run: npm audit + continue-on-error: true # Allow PR to pass even if vulnerabilities are found + + - name: Check for fixable vulnerabilities + run: | + npm audit --json > audit-report.json + FIXABLE=$(grep -c '"fixAvailable": true' audit-report.json) + if [ "$FIXABLE" -gt 0 ]; then + echo "$FIXABLE fixable vulnerabilities found." + exit 1 # Block PR if there are fixable vulnerabilities + else + echo "No fixable vulnerabilities found." + fi