👷 misc(deps): automate KaTeX/mermaid upgrades
This commit is contained in:
parent
47a94d3d01
commit
fc04ab4e40
74
.github/workflows/upgrade-deps.yml
vendored
Normal file
74
.github/workflows/upgrade-deps.yml
vendored
Normal file
@ -0,0 +1,74 @@
|
||||
name: Dependency upgrade
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
dependency:
|
||||
description: 'Dependency to upgrade'
|
||||
required: true
|
||||
type: choice
|
||||
options:
|
||||
- all
|
||||
- mermaid
|
||||
- katex
|
||||
schedule:
|
||||
- cron: '32 4 * * *'
|
||||
|
||||
jobs:
|
||||
upgrade-dependency:
|
||||
name: Upgrade dependency
|
||||
runs-on: ubuntu-22.04
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
strategy:
|
||||
matrix:
|
||||
dependency: ${{ github.event_name == 'schedule' && fromJson('["mermaid", "katex"]') || fromJson(format('["{0}"]', github.event.inputs.dependency)) }}
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up environment
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y jq npm curl git
|
||||
npm install uglify-js -g
|
||||
uglifyjs --version
|
||||
|
||||
- name: Configure GPG key
|
||||
run: |
|
||||
echo -n ${{ secrets.GPG_PRIVATE_KEY }} | base64 --decode | gpg --import
|
||||
|
||||
- name: Configure Git
|
||||
run: |
|
||||
git config --global user.signingkey 33EACFE956484C3940BFEEDCE4EC28F8DFB57474
|
||||
git config --global commit.gpgsign true
|
||||
git config --global user.name "welpo"
|
||||
git config --global user.email "welpo@users.noreply.github.com"
|
||||
|
||||
- name: Create and switch to new branch
|
||||
run: |
|
||||
git checkout -b deps/upgrade-${{ matrix.dependency }}
|
||||
|
||||
- name: Run upgrade script
|
||||
shell: bash
|
||||
run: |
|
||||
if [[ "${{ matrix.dependency }}" == "all" ]]; then
|
||||
bash scripts/upgrade-deps --all
|
||||
else
|
||||
bash scripts/upgrade-deps --${{ matrix.dependency }}
|
||||
fi
|
||||
|
||||
- name: Push changes and create PR
|
||||
shell: bash
|
||||
run: |
|
||||
if git diff --quiet HEAD origin/main; then
|
||||
echo "No changes to push for ${{ matrix.dependency }}"
|
||||
exit 0
|
||||
fi
|
||||
git push -u origin deps/upgrade-${{ matrix.dependency }}
|
||||
gh pr create --fill --base main --head deps/upgrade-${{ matrix.dependency }}
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
@ -361,17 +361,22 @@ main() {
|
||||
|
||||
echo "Updating local repository…"
|
||||
git fetch origin
|
||||
local git_status
|
||||
git_status=$(git status -uno)
|
||||
if echo "$git_status" | grep -q "Your branch is behind"; then
|
||||
exit_with_message "Your local branch is behind the remote. Pull the latest changes before running this script."
|
||||
elif echo "$git_status" | grep -q "Your branch is ahead"; then
|
||||
echo "Your local branch is ahead of the remote. Checking if local changes can be pushed…"
|
||||
if ! git push --dry-run &> /dev/null; then
|
||||
exit_with_message "Unable to push local changes. Resolve any conflicts before running this script."
|
||||
current_branch=$(git rev-parse --abbrev-ref HEAD)
|
||||
echo "Current branch: $current_branch"
|
||||
# Check if the branch exists on the remote
|
||||
if git ls-remote --exit-code --heads origin "$current_branch" >/dev/null 2>&1; then
|
||||
# Branch exists on remote, compare with local.
|
||||
local_commit=$(git rev-parse HEAD)
|
||||
remote_commit=$(git rev-parse origin/"$current_branch")
|
||||
if [ "$local_commit" = "$remote_commit" ]; then
|
||||
echo "Branch is up to date with origin/$current_branch"
|
||||
elif git merge-base --is-ancestor "$remote_commit" "$local_commit"; then
|
||||
echo "Local branch is ahead of origin/$current_branch"
|
||||
else
|
||||
exit_with_message "Your local branch is behind origin/$current_branch. Pull the latest changes before running this script."
|
||||
fi
|
||||
elif ! echo "$git_status" | grep -q "Your branch is up to date"; then
|
||||
exit_with_message "Unable to determine if branch is up to date. Check your git status manually."
|
||||
else
|
||||
echo "Branch $current_branch does not exist on remote. Assuming it's a new branch."
|
||||
fi
|
||||
echo "Local repository is ready."
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user