Skip to content

Instantly share code, notes, and snippets.

@CatChen
Created July 7, 2023 05:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CatChen/57e73b685459cf19c6524564e21a2bb8 to your computer and use it in GitHub Desktop.
Save CatChen/57e73b685459cf19c6524564e21a2bb8 to your computer and use it in GitHub Desktop.
GitHub Actions Workflow for Updating browserlist db
name: Update browserslist
on:
schedule:
- cron: '0 0 1 */3 *'
workflow_dispatch:
jobs:
update:
runs-on: ubuntu-latest
permissions: write-all
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
check-latest: true
- name: Update browserslist
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
npx browserslist@latest --update-db
if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=$(git hash-object -t tree /dev/null)
fi
git add -AN
if test $(git diff --name-only $against | wc -l) == 0
then
exit 0
fi
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
CANIUSE_LITE_VERSION=$(npm ls caniuse-lite | grep caniuse-lite@ | grep -v deduped | sed 's/.*caniuse-lite@\(.*\)$/\1/')
BRANCH_NAME="workflow/browserslist/caniuse-lite@$CANIUSE_LITE_VERSION"
git checkout -b "$BRANCH_NAME"
git commit yarn.lock -m 'npx browserslist@latest --update-db'
git push -f --set-upstream origin "$BRANCH_NAME"
gh pr create --base "master" --title "Bump caniuse-lite to $CANIUSE_LITE_VERSION" --body "#accept2ship" --assignee "CatChen" --reviewer "CatChen"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment