-
Notifications
You must be signed in to change notification settings - Fork 77
83 lines (79 loc) · 2.86 KB
/
publish.yml
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
name: publish
on:
workflow_dispatch:
inputs:
version-change:
description: Version part
required: true
type: choice
options:
- PATCH
- MINOR
release-candidate:
description: Release candidate
required: true
type: boolean
default: True
permissions:
contents: write
jobs:
publish:
runs-on: ubuntu-latest
env:
VERSION_CHANGE: ${{ github.event.inputs.version-change }}
RELEASE_CANDIDATE: ${{ github.event.inputs.release-candidate }}
VERSION_FILE: internal/version/version.go
CHANGELOG_FILE: CHANGELOG.md
GITHUB_TOKEN: ${{ secrets.YDB_PLATFORM_BOT_TOKEN_REPO }}
steps:
- uses: actions/checkout@v3
with:
token: ${{ secrets.YDB_PLATFORM_BOT_TOKEN_REPO }}
fetch-depth: 0
- run: |
CHANGELOG=$(cat $CHANGELOG_FILE | sed -e '/^## v.*$/,$d')
if [[ -z "$CHANGELOG" ]]
then
echo "CHANGELOG empty"
exit 1;
fi;
MAJOR=$(cat $VERSION_FILE | grep Major | sed -e 's/^.*\ \(=\ \)*\(\"\)*\([0-9]*\)\(\"\)*.*/\3/g');
MINOR=$(cat $VERSION_FILE | grep Minor | sed -e 's/^.*\ \(=\ \)*\(\"\)*\([0-9]*\)\(\"\)*.*/\3/g');
PATCH=$(cat $VERSION_FILE | grep Patch | sed -e 's/^.*\ \(=\ \)*\(\"\)*\([0-9]*\)\(\"\)*.*/\3/g');
LAST_TAG="v$MAJOR.$MINOR.$PATCH";
if [ "$VERSION_CHANGE" = "MINOR" ]
then
MINOR=$((MINOR+1));
PATCH=0;
fi;
if [ "$VERSION_CHANGE" = "PATCH" ]
then
PATCH=$((PATCH+1));
fi;
if [ "$RELEASE_CANDIDATE" = true ]
then
RC=$(git tag | grep "v$MAJOR.$MINOR.$PATCH-rc" | wc -l);
TAG="v$MAJOR.$MINOR.$PATCH-rc$RC";
else
sed -e 's/Minor = "\([0-9]*\)"/Minor = "'$MINOR'"/g' -i $VERSION_FILE;
sed -e 's/Patch = "\([0-9]*\)"/Patch = "'$PATCH'"/g' -i $VERSION_FILE;
git add $VERSION_FILE;
echo "## v$MAJOR.$MINOR.$PATCH" >> $CHANGELOG_FILE.tmp
cat $CHANGELOG_FILE >> $CHANGELOG_FILE.tmp
mv $CHANGELOG_FILE.tmp $CHANGELOG_FILE;
git add $CHANGELOG_FILE;
git config --global user.email "robot@umbrella";
git config --global user.name "robot";
git commit -m "Release v$MAJOR.$MINOR.$PATCH";
TAG="v$MAJOR.$MINOR.$PATCH";
fi;
git tag $TAG
git push --tags && git push
CHANGELOG="$CHANGELOG
Full Changelog: [$LAST_TAG...$TAG](https://github.com/ydb-platform/ydb-go-sdk/compare/$LAST_TAG...$TAG)"
if [ "$RELEASE_CANDIDATE" = true ]
then
gh release create -d $TAG -t "$TAG" --notes "$CHANGELOG"
else
gh release create $TAG -t "$TAG" --notes "$CHANGELOG"
fi;