summaryrefslogtreecommitdiff
path: root/tools/create-release.sh
blob: 7b0ed2d29442b1e9a3e91bc103d0d5d7fad5e514 (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
#!/bin/sh -eux
# tools/create-release.sh -- via GitLab CI and API
# Copyright (C) 2019  Olaf Meeuwissen
#
# License: GPL-3.0+

GROUP=sane-project
PROJECT=backends
PROJECT_ID=$GROUP%2F$PROJECT

API_ENDPOINT=https://gitlab.com/api/v4

# Uploads a file and returns a project relative URL to it.
upload () {
    curl --silent --fail \
         --header "PRIVATE-TOKEN: $PRIVATE_TOKEN" \
         --form "file=@$1" \
         --request POST \
         $API_ENDPOINT/projects/$PROJECT_ID/uploads \
        | jq --raw-output .url \
        | sed "s|^|https://gitlab.com/$GROUP/$PROJECT|"
}

cat << EOF > release.json
{
  "name": "SANE Backends $CI_COMMIT_TAG",
  "tag_name": "$CI_COMMIT_TAG",
  "description": "$(sed '1,3d; //{s/.*//; q}' NEWS \
     | git stripspace \
     | sed 's/"/\\"/g; s/$/\\n/g' \
     | tr -d '\n')",
  "assets": {
    "links": [
EOF

for check in sha256 sha512; do
    ${check}sum sane-backends-$CI_COMMIT_TAG.tar.gz \
            > sane-backends-$CI_COMMIT_TAG.$check.txt
    cat << EOF >> release.json
      {
        "name": "sane-backends-$CI_COMMIT_TAG.$check.txt",
        "url": "$(upload sane-backends-$CI_COMMIT_TAG.$check.txt)"
      },
EOF
done

cat << EOF >> release.json
      {
        "name": "sane-backends-$CI_COMMIT_TAG.tar.gz",
        "url": "$(upload sane-backends-$CI_COMMIT_TAG.tar.gz)"
      }
    ]
  }
}
EOF

echo '=================================================='
cat release.json
echo '=================================================='

curl --silent --fail --write-out "%{http_code}\n"\
     --header "PRIVATE-TOKEN: $PRIVATE_TOKEN" \
     --header "Content-Type: application/json" \
     --data @release.json \
     --request POST $API_ENDPOINT/projects/$PROJECT_ID/releases