aboutsummaryrefslogtreecommitdiff
path: root/thirdparty/ryml/ext/c4core/.github/release.sh
blob: 68d24d3d0b9e92c99d41a5098bae3239d4b85a52 (plain) (blame)
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
#!/bin/bash


# useful to iterate when fixing the release:
# ver=0.2.1 ; ( set -x ; git tag -d v$ver ; git push origin :v$ver ) ; (set -x ; set -e ; tbump --only-patch --non-interactive $ver ; git add -u ; git commit --amend --no-edit ; git tag --annotate --message "v$ver" "v$ver" ; git push -f --tags origin )


function c4_release_create()
{
    ( \
      set -euxo pipefail ; \
      ver=$(_c4_validate_ver $1) ; \
      branch=$(_c4_validate_branch) ; \
      c4_release_bump $ver ; \
      c4_release_commit $ver $branch \
      )
}

function c4_release_redo()
{
    ( \
      set -euxo pipefail ; \
      ver=$(_c4_validate_ver $1) ; \
      branch=$(_c4_validate_branch) ; \
      c4_release_delete $ver ; \
      c4_release_bump $ver ; \
      c4_release_amend $ver $branch \
    )
}

function c4_release_bump()
{
    ( \
      set -euxo pipefail ; \
      ver=$(_c4_validate_ver $1) ; \
      tbump --non-interactive --only-patch $ver \
      )
}

function c4_release_commit()
{
    ( \
      set -euxo pipefail ; \
      ver=$(_c4_validate_ver $1) ; \
      branch=$(_c4_validate_branch) ; \
      tag=v$ver ; \
      git add -u ; \
      git commit -m $tag ; \
      git tag --annotate --message $tag $tag ; \
      )
}

function c4_release_amend()
{
    ( \
      set -euxo pipefail ; \
      ver=$(_c4_validate_ver $1) ; \
      branch=$(_c4_validate_branch) ; \
      tag=v$ver ; \
      git add -u ; \
      git commit --amend -m $tag ; \
      git tag --annotate --message $tag $tag ; \
    )
}

function c4_release_delete()
{
    ( \
      set -euxo pipefail ; \
      ver=$(_c4_validate_ver $1) ; \
      git tag -d v$ver ; \
      git push origin :v$ver \
    )
}

function c4_release_push()
{
    ( \
      set -euxo pipefail ; \
      ver=$(_c4_validate_ver $1) ; \
      branch=$(_c4_validate_branch) ; \
      tag=v$ver ; \
      git push origin $branch ; \
      git push --tags origin $tag \
      )
}

function c4_release_force_push()
{
    ( \
      set -euxo pipefail ; \
      ver=$(_c4_validate_ver $1) ; \
      branch=$(_c4_validate_branch) ; \
      tag=v$ver ; \
      git push -f origin $branch ; \
      git push -f --tags origin $tag \
    )
}

function _c4_validate_ver()
{
    ver=$1
    if [ -z "$ver" ] ; then \
        exit 1
    fi
    ver=$(echo $ver | sed "s:v\(.*\):\1:")
    #sver=$(echo $ver | sed "s:\([0-9]*\.[0-9]*\..[0-9]*\).*:\1:")
    if [ ! -f changelog/$ver.md ] ; then \
        if [ -f changelog/current.md ] ; then
            git mv changelog/current.md changelog/$ver.md
            touch changelog/current.md
            git add changelog/current.md
        else
            echo "ERROR: could not find changelog/$ver.md or changelog/current.md"
            exit 1
        fi
    fi
    echo $ver
}

function _c4_validate_branch()
{
    branch=$(git rev-parse --abbrev-ref HEAD)
    if [ "$branch" != "master" ] ; then
        echo "ERROR: release branch must be master"
        exit 1
    fi
    echo $branch
}