File: release

package info (click to toggle)
lua-cliargs 3.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 388 kB
  • sloc: sh: 118; javascript: 14; makefile: 5
file content (91 lines) | stat: -rwxr-xr-x 2,343 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/env bash

[ -f ".env"       ] && source ".env"
[ -f ".env.local" ] && source ".env.local"

function abort {
  echo -e "\e[00;31m[ FAILED ]\e[00m ${1}"
  exit 1
}

function confirm {
  echo "${1} [y/N]"
  read confirmation

  if [ "${confirmation}" != "y" ]; then
    exit 0
  fi
}

[ -z "${GITHUB_TOKEN}"      ] && abort "Missing GITHUB_TOKEN env variable."
[ -z "${GITHUB_USER}"       ] && abort "Missing GITHUB_USER env variable."
[ -z "${GITHUB_REPO}"       ] && abort "Missing GITHUB_REPO env variable."
[ -z "${LUAROCKS_API_KEY}"  ] && abort "Missing LUAROCKS_API_KEY env variable."

VERSION=$1
SRC_FILE="src/cliargs.lua"
SRC_VERSION=$(grep "VERSION" src/cliargs.lua | sed -e 's/.*=//' -e 's/.* //' -e 's/"//g')

NEW_ROCKSPEC="lua_cliargs-${VERSION}.rockspec"
OLD_ROCKSPEC="lua_cliargs-${SRC_VERSION}.rockspec"

if [ "${VERSION}" == "${SRC_VERSION}" ]; then
  abort "Version specified is the same as the current one in rockspec"
fi

# Publish to GitHub
JSON_PAYLOAD=$(
  printf '{
    "tag_name": "v%s",
    "target_commitish": "master",
    "name": "v%s",
    "body": "Release of version %s",
    "draft": false,
    "prerelease": false
  }' $VERSION $VERSION $VERSION
)

echo $JSON_PAYLOAD
echo "Releasing version ${VERSION}..."

if [ ! -f $OLD_ROCKSPEC ]; then
  abort "Version in ${SRC_FILE} does not match the rockspec file!"
fi

# rename rockspec file
mv $OLD_ROCKSPEC $NEW_ROCKSPEC

# bump version in rockspec
perl -p -i -e "s/${SRC_VERSION}/${VERSION}/g" $NEW_ROCKSPEC

# bump version in src
perl -p -i -e "s/${SRC_VERSION}/${VERSION}/"  $SRC_FILE

confirm "rockspec and source file have been modified, please confirm the changes. Proceed?"

echo "Creating git release v${VERSION}..."

git add $NEW_ROCKSPEC
git rm  $OLD_ROCKSPEC
git add $SRC_FILE
git commit -m "Release v${VERSION}"
git push origin master

echo "Done."
confirm "Create a new GitHub release?"

# the API will automatically create the tag for us, no need to do it manually!
curl \
  --data "$JSON_PAYLOAD" \
  -X POST \
  -H "Content-Type: application/json; charset=utf-8" \
  -H "Accept: application/json" \
  "https://api.github.com/repos/${GITHUB_USER}/${GITHUB_REPO}/releases?access_token=${GITHUB_TOKEN}"

echo "Done."

confirm "Publish to luarocks?"

luarocks --api-key=$LUAROCKS_API_KEY upload $NEW_ROCKSPEC

echo -e "\e[00;32m[ SUCCESS ]\e[00m"