aboutsummaryrefslogtreecommitdiffstats
path: root/integration/src/release_scripts/getReleaseData.sh
blob: 4afd1bd987323a422928302943ddb105357bce88 (plain)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#!/bin/bash

#
# ============LICENSE_START================================================
# ONAP
# =========================================================================
# Copyright (C) 2021-2022 Nordix Foundation.
# =========================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============LICENSE_END==================================================
#

set -e

SCRIPT_NAME=$(basename "$0")
repo_location="./"
release_data_file="./pf_release_data.csv"
branch="master"

# Use the bash internal OSTYPE variable to check for MacOS
if [[ "$OSTYPE" == "darwin"* ]]
then
    SED="gsed"
else
    SED="sed"
fi

declare -a pf_repos=(
    "policy/parent"
    "policy/docker"
    "policy/common"
    "policy/models"
    "policy/api"
    "policy/pap"
    "policy/apex-pdp"
    "policy/drools-pdp"
    "policy/xacml-pdp"
    "policy/distribution"
    "policy/clamp"
    "policy/gui"
    "policy/drools-applications"
)

usage()
{
    echo ""
    echo "$SCRIPT_NAME - gets information from the checked out Policy Framework repos for the release process"
    echo ""
    echo "       usage:  $SCRIPT_NAME [-options]"
    echo ""
    echo "       options"
    echo "         -h           - this help message"
    echo "         -b branch    - the branch to release on, defaults to '$branch'"
    echo "         -d data_file - the policy release data file to create, defaults to '$release_data_file'"
    echo "         -l location  - the location of the policy framework repos on the file system,"
    echo "                        defaults to '$repo_location'"
    exit 255;
}

while getopts "hb:d:l:" opt
do
    case $opt in
    h)
        usage
        ;;
    b)
        branch=$OPTARG
        ;;
    d)
        release_data_file=$OPTARG
        ;;
    l)
        repo_location=$OPTARG
        ;;
    \?)
        usage
        exit 1
        ;;
    esac
done

if [[ -z "$repo_location" ]]
then
    echo "policy repo location not specified on -l flag"
    exit 1
fi

if [[ -z "$branch" ]]
then
    echo "policy branch not specified on -b flag"
    exit 1
fi

if ! [ -d "$repo_location" ]
then
    echo "policy repo location '$repo_location' not found"
    exit 1
fi

if [[ -z "$release_data_file" ]]
then
    echo "policy release data file not specified on -d flag"
    exit 1
fi

update_repos() {
    echo "updating the policy framework data from '$repo_location' to data file '$release_data_file' . . ."

    for repo in "${pf_repos[@]}"
    do
        echo "updating data from repo $repo branch $branch to data file '$release_data_file' . . ."

        if [ -d "$repo_location/$repo" ]
        then
            echo "updating repository '$repo' . . ."
            git -C "$repo_location/$repo" checkout -- .
            git -C "$repo_location/$repo" checkout "$branch"
            git -C "$repo_location/$repo" pull
            git -C "$repo_location/$repo" rebase
            git -C "$repo_location/$repo" fetch --tags
        else
            echo "repo $repo does not exist"
            exit 1
        fi
        echo "data from repo $repo updated to data file '$release_data_file' . . ."
    done

    echo "policy framework data from '$repo_location' updated to data file '$release_data_file' . . ."
}

get_tags() {
    echo "Repo, Last Tag Version,Snapshot Version,Changed Files,Docker Images"
    echo "repo, Last Tag Version,Snapshot Version,Changed Files,Docker Images" > "$release_data_file"
    for repo in "${pf_repos[@]}"
    do
        latest_snapshot_tag=$(mvn -f "$repo_location/$repo" clean | \
            grep "SNAPSHOT" | \
            tail -1 | \
            $SED -r 's/^.* ([0-9]*\.[0-9]*\.[0-9]*-SNAPSHOT).*$/\1/')

        if [[ $branch == *master ]]
        then
            latest_released_tag=$(git -C "$repo_location/$repo" tag | \
                grep '^[0-9]*\.[0-9]*\.[0-9]*$' | \
                sort -V | \
                tail -1)
        else
            # shellcheck disable=SC2001
            latest_snapshot_major_minor=$(echo "$latest_snapshot_tag" | sed 's/\.[0-9]*-SNAPSHOT$//')
            latest_released_tag=$(git -C "$repo_location/$repo" tag | \
                grep '^[0-9]*\.[0-9]*\.[0-9]*$' | \
                grep "$latest_snapshot_major_minor" | \
                sort -V | \
                tail -1)
        fi

        changed_files=$(git -C "$repo_location/$repo" diff --name-only "$latest_released_tag" "$branch" | \
            grep -v 'pom.xml$' | \
            grep -v '^version.properties$' | \
            grep -v "^releases/$latest_released_tag.yaml$" | \
            grep -cv "^releases/$latest_released_tag-container.yaml$" | \
            $SED 's/^[[:space:]]*//g')

        latest_container_yaml=$(find "$repo_location/$repo/releases" -name "*container.yaml" | sort | tail -1)
        if [ "$latest_container_yaml" != "" ]
        then
            docker_images=$(grep '\- name:' "$latest_container_yaml" | \
            $SED -e 's/\- //g' -e 's/\://g' -e "s/\'//g" -e 's/^[[:space:]]*//g' -e 's/^name //' | \
            tr '\n' ':' | \
            $SED 's/:$//')
        else
            docker_images=""
        fi

        echo "$repo,$latest_released_tag,$latest_snapshot_tag,$changed_files,$docker_images"
        echo "$repo,$latest_released_tag,$latest_snapshot_tag,$changed_files,$docker_images" >> "$release_data_file"
    done
}

update_repos
get_tags