hugo-theme-readable

Fork of https://github.com/cjtheham/hugo-theme-readable
git clone https://git.eamoncaddigan.net/hugo-theme-readable.git
Log | Files | Refs | README | LICENSE

update-readable-css.sh (2730B)


      1 #!/bin/bash
      2 set -o errexit
      3 set -o pipefail
      4 set -o nounset
      5 
      6 # Query the codeberg.org API (see
      7 #   https://codeberg.org/api/swagger#/repository/repoListReleases
      8 # ) and use jq to get the tag name of the
      9 # latest release (i.e. the first element of the
     10 # array in the JSON output, that is not a
     11 # prerelease).
     12 # The '-r' option will give us "raw" output,
     13 # i.e. without surrounding double-quotes.
     14 # We use 'map' and 'select' in combination,
     15 # because jq won't return a list otherwise.
     16 # Only using 'select' returns just the matching
     17 # elements, which is not a valid json that we
     18 # can process further.
     19 TAG_VERSION=$(curl -s \
     20     -H 'accept: application/json' \
     21     https://codeberg.org/api/v1/repos/Freedom-to-Write/readable.css/releases \
     22     | jq -r '.|map(select(.prerelease==false))[0].tag_name')
     23 
     24 echo "Latest tag: ${TAG_VERSION}"
     25 
     26 # Get the current version.
     27 # The '-o' option will only output the match grep found.
     28 # We look for readable.min.css and a set of three numbers seperated by dots,
     29 # i.e. a semantic version. readable.min.css is used to make sure that we match
     30 # the right numbers in the file.
     31 # We use sed to get rid of the readable.min.css prefix.
     32 CURRENT_VERSION=$(grep -o \
     33     'readable.min.css?v=v[[:digit:]]\+\.[[:digit:]]\+\.[[:digit:]]\+' \
     34     layouts/partials/head.html \
     35     | sed 's/readable.min.css?v=//')
     36 echo "Current version: ${CURRENT_VERSION}"
     37 
     38 if [[ $TAG_VERSION == $CURRENT_VERSION ]]
     39 then
     40     echo "Nothing to do. The current version is already up to date."
     41     # Inform the next script that it can exit early.
     42     echo "READABLE_CSS_CHANGED=false" >> envvars
     43     exit 0
     44 fi
     45 
     46 # Update CSS files
     47 curl -s "https://codeberg.org/Freedom-to-Write/readable.css/raw/tag/${TAG_VERSION}/readable.css" > static/css/readable.css
     48 curl -s "https://codeberg.org/Freedom-to-Write/readable.css/raw/tag/${TAG_VERSION}/readable.min.css" > static/css/readable.min.css
     49 
     50 # Replace version in head.html
     51 sed -i "s/readable.min.css?v=${CURRENT_VERSION}/readable.min.css?v=${TAG_VERSION}/" layouts/partials/head.html
     52 
     53 # Create a new commit on a new branch.
     54 git checkout -b "${PULL_REQUEST_BRANCH}"
     55 git config --global user.name 'Codeberg CI'
     56 git config --global user.email 'noreply@codeberg.org'
     57 git commit -a -m "Update readable.css to ${TAG_VERSION}" -m "See the changelog here:" -m "https://codeberg.org/Freedom-to-Write/readable.css/src/tag/${TAG_VERSION}/CHANGELOG.md"
     58 git remote set-url origin "https://$CB_TOKEN@codeberg.org/$CI_REPO_OWNER/$CI_REPO_NAME.git"
     59 git push --force --set-upstream origin "${PULL_REQUEST_BRANCH}"
     60 
     61 # Add the latest tag version to the workflow environment, so we can access
     62 # it in later steps.
     63 echo "READABLE_CSS_TAG=${TAG_VERSION}" >> envvars
     64 echo "READABLE_CSS_CHANGED=true" >> envvars