update-since-todo.sh 1.1 KB
Newer Older
1 2 3 4 5
#!/bin/bash

# This script is a developer tool, to be used by maintainers
# to update '@since TODO' entries with actual Jenkins release versions.

6 7 8
set -o errexit
set -o nounset
set -o pipefail
9

D
Daniel Beck 已提交
10
me="$( basename "$0" )"
11 12 13 14 15

IFS=$'\n'
for todo in $( git grep --line-number '@since TODO' | grep -v "$me" )
do
    #echo "TODO: $todo"
D
Daniel Beck 已提交
16 17
    file=$( echo "$todo" | cut -d : -f 1 )
    line=$( echo "$todo" | cut -d : -f 2 )
18 19 20

    echo "Analyzing $file:$line"

D
Daniel Beck 已提交
21
    lineSha=$( git blame --porcelain -L "$line,$line" "$file" | head -1 | cut -d ' ' -f 1 )
22 23
    echo -e "\tfirst sha: $lineSha"

24
    firstTag=$( git tag --sort=creatordate --contains "$lineSha" 'jenkins-*' | head -1 )
25

D
Daniel Beck 已提交
26
    if [[ -n $firstTag ]]; then
27 28 29
        echo -e "\tfirst tag was $firstTag"
        echo -e "\tUpdating file in place"
        sedExpr="${line}s/@since TODO/@since ${firstTag//jenkins-/}/"
D
Daniel Beck 已提交
30
        sed -i.bak "$sedExpr" "$file"
D
Daniel Beck 已提交
31
        rm -f "$file.bak"
32
    else
33
        echo -e "\tNot updating file, no tag found. Normal if the associated PR/commit is not merged and released yet; otherwise make sure to fetch tags from jenkinsci/jenkins"
34 35
    fi
done