Skip to content

Commit

Permalink
Update check-material-insiders-version.sh to match mkdocs, fix workfl…
Browse files Browse the repository at this point in the history
…ow (#1427)

* Update check-material-insiders-version.sh to match mkdocs

* Update check-material-insiders-version.sh

* Update check-material-insiders-version.sh

* Adding some debug and extra conditional.

* Added else if latest tag is empty.

* Hardcoding GH_TOKEN and repo URL into the git ls-remote command.

* Revert "Hardcoding GH_TOKEN and repo URL into the git ls-remote command."

This reverts commit a2915e8.

* Disabling persist-credentials from checkout.

* Removed symlink and debug log.

* Updated branch strategy for pull request.
  • Loading branch information
dmundra authored Sep 3, 2024
1 parent 05aa2b0 commit 3acd3c8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
33 changes: 28 additions & 5 deletions .config/mkdocs/check-material-insiders-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,45 @@ if [ -z "${GH_TOKEN:-}" ]; then
echo "Github token for material-insiders access needed. Ask in #docs channel for access." 1>&2
exit 1
fi
if ! gh --version &> /dev/null; then
echo "Github CLI is required: https://cli.github.com/" 1>&2
exit 2
fi
if ! poetry --version &> /dev/null; then
echo "Poetry is required: https://python-poetry.org/" 1>&2
exit 3
fi

# Register gh as a git credential helper, so we can use GH_TOKEN securely.
gh auth setup-git

# Install packages.
poetry -C .config/mkdocs/ --quiet install

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" \
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)

#echo $latest_tag

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

#echo $installed_tag

# Compare tags
if [ "$latest_tag" = "$installed_tag" ]; then
echo "Latest material-insiders version $latest_tag already installed."
if [ ! -z "$latest_tag" ]; then
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
else
echo "Newer material-insiders version available: $latest_tag. Installing..."
poetry -C .config/mkdocs/ add git+$material_insiders_repo#"$latest_tag"
echo "Check material insiders version script failed." 1>&2
exit 4
fi
2 changes: 2 additions & 0 deletions .github/workflows/material-insiders-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
- uses: actions/setup-python@v5
with:
python-version: "3.11"
Expand All @@ -31,3 +32,4 @@ jobs:
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
branch-suffix: timestamp

0 comments on commit 3acd3c8

Please sign in to comment.