File: post_push

package info (click to toggle)
mtail 3.0.0~rc24.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 6,944 kB
  • sloc: yacc: 530; makefile: 181; sh: 141; lisp: 77; awk: 17
file content (41 lines) | stat: -rwxr-xr-x 1,093 bytes parent folder | download | duplicates (2)
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
35
36
37
38
39
40
41
#!/bin/bash
# hooks/post_push

# https://docs.docker.com/docker-cloud/builds/advanced/
# https://semver.org/

function add_tag() {
    echo "Adding tag ${1}"
    docker tag $IMAGE_NAME $DOCKER_REPO:$1
    docker push $DOCKER_REPO:$1
}

TAG=`git describe --tag --match "v*"`

MAJOR=`echo ${TAG} | awk -F'-' '{print $1}' | awk -F'.' '{print $1}' | sed 's/v//'`
MINOR=`echo ${TAG} | awk -F'-' '{print $1}' | awk -F'.' '{print $2}' | sed 's/v//'`
PATCH=`echo ${TAG} | awk -F'-' '{print $1}' | awk -F'.' '{print $3}' | sed 's/v//'`
PRLS=`echo ${TAG} | awk -F'-' '{print $2}'`

num='^[0-9]+$'
pre='^[0-9A-Za-z\.]+$'

echo "Current Build: ${TAG}"

if [ ! -z $MAJOR ] && [[ $MAJOR =~ $num ]]; then
    add_tag ${MAJOR}

    if [ ! -z $MINOR ] && [[ $MINOR =~ $num ]]; then
        add_tag ${MAJOR}.${MINOR}

        if [ ! -z $PATCH ] && [[ $PATCH =~ $num ]]; then
            add_tag ${MAJOR}.${MINOR}.${PATCH}

            if [ ! -z $PRLS ] && [[ ! $PRLS =~ $num ]] && [[ $PRLS =~ $pre ]]; then
                add_tag ${MAJOR}.${MINOR}.${PATCH}-${PRLS}
            fi
        fi
    fi
fi

exit $?