Skip to content

Commit

Permalink
Created a bash script to lookup the material insiders latest version …
Browse files Browse the repository at this point in the history
…and compare it to the installed version and install the newer version if it is different. Adding a github action to do that automatically with a pull request. (#1405)
  • Loading branch information
dmundra authored Aug 30, 2024
1 parent 59b34aa commit e79fad0
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .config/mkdocs/check-material-insiders-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

# Source an env file if it exists.
if [ -f .env ]; then
source .env
fi

# Check environment.
if [ -z "${GH_TOKEN:-}" ]; then
echo "Github token for material-insiders access needed. Ask in #docs channel for access." 1>&2
exit 1
fi

material_insiders_repo="https://github.com/squidfunk/mkdocs-material-insiders.git"

# Get latest tag from material-insiders git repo.
# Got solution from https://stackoverflow.com/questions/29780641/how-to-clone-latest-tag-in-a-git-repo.
latest_tag=$(git ls-remote --tags --exit-code --refs "$material_insiders_repo" \
| sed -E 's/^[[:xdigit:]]+[[:space:]]+refs\/tags\/(.+)/\1/g' \
| sort --version-sort | tail -n1)

# Get latest installed tag from poetry.
installed_tag=$(poetry -C .config/mkdocs/ show mkdocs-material | awk '/version/ { print $3 }' | sed 's/+insiders./-insiders-/')

# Compare tags
if [ "$latest_tag" = "$installed_tag" ]; then
echo "Latest material-insiders version $latest_tag already installed."
else
echo "Newer material-insiders version available: $latest_tag. Installing..."
poetry -C .config/mkdocs/ add git+$material_insiders_repo#"$latest_tag"
fi
33 changes: 33 additions & 0 deletions .github/workflows/material-insiders-update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Checking material insiders update

on:
# Automatic check monthly
schedule:
- cron: "0 10 1 * *"
# Manually triggered using GitHub's UI
workflow_dispatch:

jobs:
mkdocs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- uses: snok/install-poetry@v1
with:
version: 1.3.2
- name: Run material insiders script to check version.
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
run: ./.config/mkdocs/check-material-insiders-version.sh
- name: Create pull request if there is a new version
uses: peter-evans/create-pull-request@v6
with:
commit-message: Update material insiders version to latest version
title: Update material insiders version to latest version
body: Verify the new version works and there are no side effects (theme color reverting). Confirm all checks are passing.
branch: update-material-insiders

0 comments on commit e79fad0

Please sign in to comment.