Skip to content

Merge pull request #40 from MewenLeHo/main-mlh-add-changelog-and-roadmap #10

Merge pull request #40 from MewenLeHo/main-mlh-add-changelog-and-roadmap

Merge pull request #40 from MewenLeHo/main-mlh-add-changelog-and-roadmap #10

Workflow file for this run

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