Commit a1cf504b authored by Pierre Smeyers's avatar Pierre Smeyers
Browse files

refactor: remove 'preferred tag pattern' as now the desired version pattern is...

refactor: remove 'preferred tag pattern' as now the desired version pattern is an interactive choice in Kicker
parent 87c8d463
Loading
Loading
Loading
Loading
Loading
+0 −22
Original line number Diff line number Diff line
@@ -22,30 +22,8 @@ It can be configured with the following variables:

* `GITLAB_TOKEN`: a [group access token](https://docs.gitlab.com/ee/user/group/settings/group_access_tokens.html) with at least scopes `api,read_repository`
  and `Developer` role,
* `PREF_TAG_PATTERN`: preferred tag pattern.
* `KICKER_RESOURCE_GROUPS`: JSON configuration of GitLab groups to crawl.

### Details about `PREF_TAG_PATTERN`

The algorithm to determine which template latest version to include in Kicker is the following:

1. get all published (Git) tags, 
2. sort them (using [Version sort](https://www.gnu.org/software/coreutils/manual/html_node/Version-sort-overview.html)),
3. among this list, filter all tags matching a _preferred pattern_ (regex)
    * one or more matches: return the latest one from the filtered list
    * none matches (fallback): simply pick the latest one from the unfiltered list

The `PREF_TAG_PATTERN` variable allows to define the preferred version pattern to be used as the latest version to include in Kicker.

By default it is set as `^v?[0-9]+\.[0-9]+$`. In other words, Kicker will propose the latest published 
minor version alias (ex `2.4`), when present.

If your want another behavior in your self-managed GitLab, simply override this variable in your local copy 
of the `to-be-continuous/doc` project. Example values:

* full semver version (incuding fix part): `^v?[0-9]+\.[0-9]+\.[0-9]+$`
* simply the latest tag (whichever the format): `.*`

### Details about `KICKER_RESOURCE_GROUPS`

Here is an example of `KICKER_RESOURCE_GROUPS` content:
+7 −18
Original line number Diff line number Diff line
@@ -59,15 +59,13 @@ function maybe_process_template() {

  # get tags (latest first, oldest last)
  all_tags=$(curl -sSf -H "$AUTH_HEADER" "$API_URL/projects/$project_id/repository/tags?per_page=100" | jq -r '.[].name' | sort -rV)
  # filter tags matching preferred pattern, or all tags if none matches
  matching_tags=$(echo "$all_tags" | grep -E "$PREF_TAG_PATTERN" || echo "$all_tags")
  tag=$(echo "$matching_tags" | head -n 1)
  if [[ -n "$tag" ]] && [[ "$tag" != "null" ]]
  latest_tag=$(echo "$all_tags" | head -n 1)
  tags_array_json=$(echo "$all_tags" | jq --raw-input . | jq --slurp --compact-output .)
  if [[ -n "$latest_tag" ]] && [[ "$latest_tag" != "null" ]]
  then
    project_path_enc=${project_path//\//%2f}
    web_url=$(echo "$project_json" | jq -r .web_url)
    tags_array_json=$(echo "$all_tags" | jq --raw-input . | jq --slurp --compact-output .)
    add_info_json="{extension_id: $extension_json, project: {tag: \"$tag\", tags: $tags_array_json, name: \"$project_name\", path: \"$project_path\", web_url: \"$web_url\", avatar: \"$web_url/-/avatar\"}}"
    add_info_json="{extension_id: $extension_json, project: {tag: \"$latest_tag\", tags: $tags_array_json, name: \"$project_name\", path: \"$project_path\", web_url: \"$web_url\", avatar: \"$web_url/-/avatar\"}}"

    # get kicker.json file from default branch
    if template_json=$(curl -sf -H "$AUTH_HEADER" "$API_URL/projects/$project_id/repository/files/kicker.json/raw?ref=$project_default_branch")
@@ -95,7 +93,7 @@ function maybe_process_template() {
        echo
        echo "    $template_desc"
        echo
        echo "    Version: \`$tag\`"
        echo "    Version: \`$latest_tag\`"
        echo
      } >> "$DOC_OUT/ref/templates-grid.part.html"

@@ -104,7 +102,7 @@ function maybe_process_template() {
      template_path_encoded=$(echo -n "$template_path" | jq -sRr @uri)
      mkdir -p $(dirname "$target_dir/$template_path")
      log_info " ... downloading $template_path as $template_path_encoded to \\e[33;1m$target_dir/$template_path\\e[0m..."
      curl -sS -H "$AUTH_HEADER" --output "$target_dir/$template_path" "$API_URL/projects/$project_id/repository/files/$template_path_encoded/raw?ref=$tag"
      curl -sS -H "$AUTH_HEADER" --output "$target_dir/$template_path" "$API_URL/projects/$project_id/repository/files/$template_path_encoded/raw?ref=$latest_tag"
      # write stages row
      {
        echo -n "<!-- $template_name --><tr>" # for alphabetical sort
@@ -149,7 +147,7 @@ function maybe_process_template() {
    then
      project_path_enc=${project_path//\//%2f}
      web_url=$(echo "$project_json" | jq -r .web_url)
      add_info_json="{extension_id: $extension_json, project: {tag: \"$tag\", name: \"$project_name\", path: \"$project_path\", web_url: \"$web_url\"}}"
      add_info_json="{extension_id: $extension_json, project: {tag: \"$latest_tag\", tags: $tags_array_json, name: \"$project_name\", path: \"$project_path\", web_url: \"$web_url\"}}"

      log_info "Project \\e[32m${project_path}\\e[0m declares extra kicker resource(s) on latest tag \\e[33;1m${tag}\\e[0m..."

@@ -326,9 +324,6 @@ DOC_OUT=./docs

KICKER_RESOURCE_GROUPS=${KICKER_RESOURCE_GROUPS:-'[{"path": "to-be-continuous", "visibility": "public"}]'}

# preferred tag pattern to include: minor version alias by default (X.Y)
PREF_TAG_PATTERN='^v?[0-9]+\.[0-9]+$'

log_info parse params

# parse arguments
@@ -398,11 +393,6 @@ case $key in
    shift # past argument
    shift # past value
    ;;
    --tag-pattern)
    PREF_TAG_PATTERN="$2"
    shift # past argument
    shift # past value
    ;;
    *) # unknown option
    POSITIONAL="$POSITIONAL $1" # save it in an array for later
    shift # past argument
@@ -419,7 +409,6 @@ log_info "- GitLab API url (--api) : \\e[33;1m${API_URL}\\e[0m"
log_info "- kicker output file (--json-out)  : \\e[33;1m${JSON_OUT}\\e[0m"
log_info "- readme output dir  (--doc-out)   : \\e[33;1m${DOC_OUT}\\e[0m"
log_info "- groups to process  (--groups)    : \\e[33;1m${KICKER_RESOURCE_GROUPS}\\e[0m"
log_info "- pref. tag pattern (--tag-pattern): \\e[33;1m${PREF_TAG_PATTERN}\\e[0m"

# create a temporary directory to download individual kicker files
tmp_dir=$(mktemp -d)