80fc652863f09b35f5baccb9a3b3896bb7a77b25
[releng/builder.git] / scripts / branch_cut / branch_cutter.sh
1 #!/bin/bash
2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2017 The Linux Foundation and others.
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Eclipse Public License v1.0
8 # which accompanies this distribution, and is available at
9 # http://www.eclipse.org/legal/epl-v10.html
10 #
11 ##############################################################################
12
13 # List of directories, files to exclude
14 declare -a excludes=("defaults.yaml"
15                      "releng-macros.yaml"
16                      "global-jjb"
17                      "lf-infra"
18                      "-macros.yaml"
19                      "validate-autorelease"
20                      "opflex-dependencies.yaml")
21
22 TEMP="/tmp/tmp.yaml"
23 mod=0
24 count=0
25
26 function usage {
27     echo "Usage: $(basename "$0") options (-c [current release]) (-n [next release]) (-p [previous release]) -h for help";
28     echo "example:"
29     echo "branch_cutter.sh -n oxygen -c nitrogen -p carbon"
30     exit 0;
31 }
32
33 if ( ! getopts ":n:c:p:h" opt ); then
34     usage;
35 fi
36
37 while getopts ":n:c:p:h" opt; do
38     case $opt in
39         n)
40             new_reltag=$OPTARG
41             ;;
42         c)
43             curr_reltag=$OPTARG
44             ;;
45         p)
46             prev_reltag=$OPTARG
47             ;;
48         \?)
49             echo "Invalid option: -$OPTARG" >&2
50             exit 1
51             ;;
52         h)
53             usage
54             ;;
55         :)
56             echo "Option -$OPTARG requires an argument." >&2
57             exit 1
58             ;;
59     esac
60 done
61
62 echo "Start Branch Cutting:"
63
64 while IFS="" read -r file; do
65     found=0
66     for exclude in "${excludes[@]}"; do
67         if [[ $file =~ $exclude && $found -eq 0 ]]; then
68             found=1
69             break
70         fi
71     done
72     if [[ $found -eq 1 ]]; then
73         echo "Ignore file $file found in excludes list"
74     else
75         ./branch_cut.awk -v new_reltag="$new_reltag" -v curr_reltag="$curr_reltag" -v prev_reltag="$prev_reltag" "$file" > "$TEMP"
76         [[ ! -s "$TEMP" ]] && echo "$file: excluded"
77         [[ -s "$TEMP" ]] && mv "$TEMP" "$file" && echo "$file: Done" && (( mod++ ))
78         (( count++ ))
79     fi
80 done < <(find ../../jjb -name "*.yaml")
81
82 echo "Modified $mod out of $count files"
83 echo "Completed"