Merge pull request #42 from MewenLeHo/main-mlh-update-export-to-csv-f… #12
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Lint and Minify JavaScript | |
| # Trigger the workflow only on pushes to the main branch, | |
| # ignoring pushes that only affect the minified file. | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths-ignore: | |
| - 'detectAutocomplete.min.js' | |
| jobs: | |
| lint: | |
| name: Lint JavaScript | |
| runs-on: ubuntu-latest | |
| steps: | |
| # Step 1: Checkout the repository code | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| # Step 2: Set up Node.js environment | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| # Step 3: Install project dependencies | |
| - name: Install dependencies | |
| run: npm ci | |
| # Step 4: Run ESLint on the source file | |
| - name: Run ESLint | |
| run: npx eslint detectAutocomplete.js | |
| minify: | |
| name: Minify and Commit JavaScript | |
| runs-on: ubuntu-latest | |
| needs: lint # Ensure minification runs only after linting succeeds | |
| if: ${{ !contains(github.event.head_commit.message, '[auto]') }} # Skip if it's an automated commit | |
| steps: | |
| # Step 1: Checkout the repository with write access | |
| - name: Checkout repository (with write access) | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| # Step 2: Set up Node.js environment | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| # Step 3: Install project dependencies | |
| - name: Install dependencies | |
| run: npm ci | |
| # Step 4: Minify the JavaScript source file | |
| - name: Minify JavaScript | |
| # For now, keep the minification safe for bookmarklets. | |
| # You can add --compress --mangle in the future if needed. | |
| run: | | |
| npx terser detectAutocomplete.js -o detectAutocomplete.min.js | |
| # Step 5: Commit the minified file if there are changes | |
| - name: Commit minified file if changed | |
| run: | | |
| git config --local user.name "GitHub Actions" | |
| git config --local user.email "actions@github.com" | |
| git add detectAutocomplete.min.js | |
| if git diff --cached --quiet; then | |
| echo "No changes to commit." | |
| else | |
| git commit -m "Minify JavaScript file [auto]" | |
| git push | |
| fi |