Skip to content

publish

publish #427

Workflow file for this run

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@v4
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 && git push --tags
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;