github.com/mstephano/gqlgen-schemagen@v0.0.0-20230113041936-dd2cd4ea46aa/docs/build.sh (about)

     1  #!/bin/bash
     2  #
     3  # This was adapted from https://github.com/dgraph-io/dgraph/blob/master/wiki/scripts/build.sh
     4  #
     5  
     6  set -e
     7  
     8  GREEN='\033[32;1m'
     9  RESET='\033[0m'
    10  HOST=https://gqlgen.com
    11  
    12  IFS=$'\n' read -r -d '' -a VERSIONS_ARRAY < <(curl -s -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/99designs/gqlgen/releases?per_page=20" | jq -r '.[].tag_name' ) || true
    13  
    14  VERSIONS_ARRAY+=( "origin/master" )
    15  
    16  joinVersions() {
    17  	versions=$(printf ",%s" "${VERSIONS_ARRAY[@]}" | sed 's/origin\/master/master/')
    18  	echo "${versions:1}"
    19  }
    20  
    21  function version { echo "$@" | gawk -F. '{ printf("%03d%03d%03d\n", $1,$2,$3); }'; }
    22  
    23  rebuild() {
    24  	VERSION_STRING=$(joinVersions)
    25  	export CURRENT_VERSION=${1}
    26  	if [[ $CURRENT_VERSION == 'origin/master' ]] ; then
    27  	    CURRENT_VERSION="master"
    28      fi
    29  
    30  	export VERSIONS=${VERSION_STRING}
    31  
    32      hugo --quiet --destination="public/$CURRENT_VERSION" --baseURL="$HOST/$CURRENT_VERSION/"
    33  
    34      if [[ $1 == "${VERSIONS_ARRAY[0]}" ]]; then
    35          hugo --quiet --destination=public/ --baseURL="$HOST/"
    36      fi
    37  }
    38  
    39  
    40  currentBranch=$(git rev-parse --abbrev-ref HEAD)
    41  
    42  if ! git remote  | grep -q origin ; then
    43      git remote add origin https://github.com/mstephano/gqlgen-schemagen
    44  fi
    45  git fetch origin --tags
    46  
    47  for version in "${VERSIONS_ARRAY[@]}" ; do
    48      echo -e "$(date) $GREEN Updating docs for $version.$RESET"
    49      rm -rf content
    50      git checkout $version -- content
    51      rebuild "$version"
    52  done
    53  
    54  rm -rf content
    55  git checkout "$currentBranch" -- content
    56