publish #6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/meta/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 VersionMajor | sed -e 's/^.*\ \(=\ \)*\(\"\)*\([0-9]*\)\(\"\)*.*/\3/g'); | |
MINOR=$(cat $VERSION_FILE | grep VersionMinor | sed -e 's/^.*\ \(=\ \)*\(\"\)*\([0-9]*\)\(\"\)*.*/\3/g'); | |
PATCH=$(cat $VERSION_FILE | grep VersionPatch | 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/VersionMinor = "\([0-9]*\)"/VersionMinor = "'$MINOR'"/g' -i $VERSION_FILE; | |
sed -e 's/VersionPatch = "\([0-9]*\)"/VersionPatch = "'$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/gorm-driver/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; |