File: tag_modules.sh

package info (click to toggle)
golang-github-go-openapi-swag 1%3A0.25.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,200 kB
  • sloc: sh: 30; makefile: 3
file content (34 lines) | stat: -rwxr-xr-x 984 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#! /bin/bash
set -euo pipefail

if [[ "$#" -ne 2 ]] ; then
  echo "Usage: ${0##*/} {remote} {tag}"
  echo "This command tags all modules as {module_name}/{tag} then pushes these tags to the selected remote."
  echo "This is used whenever we want to level all modules at the same version."
  exit 1
fi

remote="$1"
tag="$2"
root="$(git rev-parse --show-toplevel)"
declare -a all_tags

cd "${root}"
echo "Tagging all modules in repo ${root##*/}..."

while read module_location ; do
  relative_location=${module_location#"$root"/}
  relative_location=${relative_location#"$root"}
  module_dir=${relative_location%"/go.mod"}
  base_tag="${module_dir#"./"}"
  if [[ "${base_tag}" ==  "" ]] ; then
    module_tag="${tag}" # e.g. "v0.24.0"
  else
    module_tag="${base_tag}/${tag}" # e.g. "mangling/v0.24.0"
  fi
  all_tags+=("${module_tag}")
  git tag "${module_tag}"
done < <(go list -f '{{.Dir}}' -m)

echo "Pushing tags to ${remote}: ${all_tags[@]}"
git push "${remote}" ${all_tags[@]}