From 1214c3d0e76b76a4432c0ca38aa9baed09b90adc Mon Sep 17 00:00:00 2001 From: amitz Date: Thu, 21 Mar 2024 20:46:07 +0200 Subject: [PATCH] added bot integ --- .github/scripts/create-release.sh | 41 +++++++++++++++++++++++++++ .github/workflows/create-release.yaml | 32 +++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 .github/scripts/create-release.sh create mode 100644 .github/workflows/create-release.yaml diff --git a/.github/scripts/create-release.sh b/.github/scripts/create-release.sh new file mode 100644 index 0000000000..e7e135e899 --- /dev/null +++ b/.github/scripts/create-release.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +set -ue + +SEMVER_REGEX='^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$' + +REL_VERSION=`echo $1 | sed -r 's/^[vV]?([0-9].+)$/\1/'` + +if [ `echo $REL_VERSION | pcre2grep "$SEMVER_REGEX"` ]; then + echo "$REL_VERSION is a valid semantic version." +else + echo "$REL_VERSION is not a valid semantic version." + exit 1 +fi + +MAJOR_MINOR_VERSION=`echo $REL_VERSION | cut -d. -f1,2` +RELEASE_BRANCH="release-$MAJOR_MINOR_VERSION" +RELEASE_TAG="v$REL_VERSION" + +if [ `git rev-parse --verify origin/$RELEASE_BRANCH 2>/dev/null` ]; then + echo "$RELEASE_BRANCH branch already exists, checking it out ..." + git checkout $RELEASE_BRANCH +else + echo "$RELEASE_BRANCH does not exist, creating ..." + git checkout -b $RELEASE_BRANCH + git push origin $RELEASE_BRANCH +fi +echo "$RELEASE_BRANCH branch is ready." + +if [ `git rev-parse --verify $RELEASE_TAG 2>/dev/null` ]; then + echo "$RELEASE_TAG tag already exists, aborting ..." + exit 2 +fi + +echo "Tagging $RELEASE_TAG ..." +git tag $RELEASE_TAG +echo "$RELEASE_TAG is tagged." + +echo "Pushing $RELEASE_TAG tag ..." +git push origin $RELEASE_TAG +echo "$RELEASE_TAG tag is pushed." \ No newline at end of file diff --git a/.github/workflows/create-release.yaml b/.github/workflows/create-release.yaml new file mode 100644 index 0000000000..5511d9639e --- /dev/null +++ b/.github/workflows/create-release.yaml @@ -0,0 +1,32 @@ +name: Create a release + +on: + workflow_dispatch: + inputs: + rel_version: + description: 'Release version (examples: v1.3.0-rc.1, v1.3.0)' + required: true + type: string + +jobs: + create-release: + name: Creates release branch and tag + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Install required packages + run: | + sudo apt-get update + sudo apt-get install pcre2-utils + - name: Create release branch and tag + env: + GITHUB_TOKEN: ${{ secrets.LAVANET_BOT_TOKEN }} + run: | + git config user.email "bot@lavanet.xyz" + git config user.name "LavaNet Bot" + # Update origin with token + git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git + ./.github/scripts/create-release.sh ${{ inputs.rel_version }} \ No newline at end of file