release.sh 2.21 KB
Newer Older
RAMET Pierre's avatar
RAMET Pierre committed
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
#!/bin/bash

changelog=""

function gen_changelog()
{
    local firstline=$( grep -n "^# " ChangeLog.md | head -n 1 | cut -d ':' -f 1 )
    firstline=$(( firstline + 1 ))
    #echo $firstline
    local lastline=$( grep -n "^# " ChangeLog.md | head -n 2 | tail -n 1 | cut -d ':' -f 1 )
    lastline=$(( lastline - 1 ))
    #echo $lastline

    for i in `seq $firstline $lastline`
    do
        local line=$( head -n $i ChangeLog.md | tail -n 1 )
        changelog="$changelog$line\\n"
        #echo $line
    done
}

release=""
function get_release()
{
    local firstline=$( grep -n "^# " ChangeLog.md | head -n 1 | cut -d ':' -f 1 )
Mathieu Faverge's avatar
Mathieu Faverge committed
26
    release=$( head -n $firstline ChangeLog.md | tail -n 1 | sed 's/# pastix\-//' )
RAMET Pierre's avatar
RAMET Pierre committed
27
28
29
30
31
32
33
}

# Get the release name through the branch name, and through the ChangeLog file.
# Both have to match to be correct
RELEASE_NAME=`echo $CI_COMMIT_REF_NAME | cut -d - -f 2`
get_release

Mathieu Faverge's avatar
Mathieu Faverge committed
34
if [ -z "$RELEASE_NAME" -o -z "$release" -o "$RELEASE_NAME" != "$release" ]
RAMET Pierre's avatar
RAMET Pierre committed
35
36
then
    echo "Commit name $RELEASE_NAME is different from ChangeLog name $release"
Mathieu Faverge's avatar
Mathieu Faverge committed
37
    exit 1
RAMET Pierre's avatar
RAMET Pierre committed
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
fi

wget https://raw.githubusercontent.com/Kentzo/git-archive-all/master/git_archive_all.py
mv git_archive_all.py git-archive-all
chmod +x git-archive-all
./git-archive-all --force-submodules pastix-$RELEASE_NAME.tar.gz

GETURL=`echo curl --request POST --header \"PRIVATE-TOKEN: $RELEASE_TOKEN\" --form \"file=\@pastix-$RELEASE_NAME.tar.gz\" https://gitlab.inria.fr/api/v4/projects/$CI_PROJECT_ID/uploads`
MYURL=`eval $GETURL | jq .url | tr -d '"'`
# could be replaced by : | cut -d , -f 2 | cut -d : -f 2
# new tag "v$RELEASE_NAME" should have been commited

# extract the change log from ChangeLog.md
gen_changelog

# Generate the curl command that create the release
COMMAND=`echo curl --header \"Content-Type: application/json\" --header \"PRIVATE-TOKEN: $RELEASE_TOKEN\" \
  --data \'{ \"name\": \"v$RELEASE_NAME\", \
            \"tag_name\": \"v$RELEASE_NAME\", \
            \"ref\": \"$CI_COMMIT_REF_NAME\", \
            \"description\": \"$changelog\", \
            \"assets\": { \"links\": [{ \"name\": \"Download release\", \"url\": \"$CI_PROJECT_URL/$MYURL\" }] } }\' \
  --request POST https://gitlab.inria.fr/api/v4/projects/$CI_PROJECT_ID/releases`
eval $COMMAND