From e22e02515547b9ec9a9fbdd2f6003066c1863f8c Mon Sep 17 00:00:00 2001 From: samuel orji Date: Thu, 28 Sep 2023 10:24:24 +0100 Subject: [PATCH 1/2] feature: add auto version bump after release Signed-off-by: samuel orji --- .github/workflows/version.yml | 50 +++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 .github/workflows/version.yml diff --git a/.github/workflows/version.yml b/.github/workflows/version.yml new file mode 100644 index 00000000..427b8460 --- /dev/null +++ b/.github/workflows/version.yml @@ -0,0 +1,50 @@ +name: Increment Version + +on: + push: + tags: + - '*.*.*' + +permissions: {} +jobs: + build: + if: github.repository == 'opensearch-project/opensearch-rs' + runs-on: ubuntu-latest + steps: + - name: GitHub App token + id: github_app_token + uses: tibdex/github-app-token@v2.1.0 + with: + app_id: ${{ secrets.APP_ID }} + private_key: ${{ secrets.APP_PRIVATE_KEY }} + installation_id: 22958780 + + - uses: actions/checkout@v4 + - name: Fetch and Update Version Information + run: | + TAG=$(echo "${GITHUB_REF#refs/*/}") + CURRENT_VERSION_ARRAY=($(echo "$TAG" | tr . '\n')) + CURRENT_VERSION=$(IFS=. ; echo "${CURRENT_VERSION_ARRAY[*]:0:3}") + CURRENT_VERSION_ARRAY[2]=$((CURRENT_VERSION_ARRAY[2]+1)) + NEXT_VERSION=$(IFS=. ; echo "${CURRENT_VERSION_ARRAY[*]:0:3}") + echo "TAG=$TAG" >> $GITHUB_ENV + echo "CURRENT_VERSION=$CURRENT_VERSION" >> $GITHUB_ENV + echo "NEXT_VERSION=$NEXT_VERSION" >> $GITHUB_ENV + sed -i '' -e "s/^version = \"$CURRENT_VERSION\"/version = \"$NEXT_VERSION\"/g" opensearch/Cargo.toml + sed -i '' -e "s/^version = \"$CURRENT_VERSION\"/version = \"$NEXT_VERSION\"/g" api_generator/Cargo.toml + sed -i '' -e "s/^version = \"$CURRENT_VERSION\"/version = \"$NEXT_VERSION\"/g" yaml_test_runner/Cargo.toml + + - name: Create Pull Request + uses: peter-evans/create-pull-request@v3 + with: + token: ${{ steps.github_app_token.outputs.token }} + base: main + branch: 'create-pull-request/patch-main' + commit-message: Increment version to ${{ env.NEXT_VERSION }} + signoff: true + delete-branch: true + labels: | + autocut + title: '[AUTO] Increment version to ${{ env.NEXT_VERSION }}.' + body: | + I've noticed that a new tag ${{ env.TAG }} was pushed, and incremented the version from ${{ env.CURRENT_VERSION }} to ${{ env.NEXT_VERSION }}. \ No newline at end of file From 7a0b41a1a38433b0e567c3f8662f43508156913a Mon Sep 17 00:00:00 2001 From: samuel orji Date: Fri, 29 Sep 2023 10:23:40 +0100 Subject: [PATCH 2/2] review feedback Signed-off-by: samuel orji --- .github/workflows/version.yml | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/.github/workflows/version.yml b/.github/workflows/version.yml index 427b8460..a2924b7a 100644 --- a/.github/workflows/version.yml +++ b/.github/workflows/version.yml @@ -3,7 +3,7 @@ name: Increment Version on: push: tags: - - '*.*.*' + - 'v*.*.*' permissions: {} jobs: @@ -22,14 +22,25 @@ jobs: - uses: actions/checkout@v4 - name: Fetch and Update Version Information run: | - TAG=$(echo "${GITHUB_REF#refs/*/}") + TAG=$(echo "${GITHUB_REF#refs/*/v}") CURRENT_VERSION_ARRAY=($(echo "$TAG" | tr . '\n')) + BASE=$(IFS=. ; echo "${CURRENT_VERSION_ARRAY[*]:0:2}") CURRENT_VERSION=$(IFS=. ; echo "${CURRENT_VERSION_ARRAY[*]:0:3}") CURRENT_VERSION_ARRAY[2]=$((CURRENT_VERSION_ARRAY[2]+1)) NEXT_VERSION=$(IFS=. ; echo "${CURRENT_VERSION_ARRAY[*]:0:3}") echo "TAG=$TAG" >> $GITHUB_ENV echo "CURRENT_VERSION=$CURRENT_VERSION" >> $GITHUB_ENV echo "NEXT_VERSION=$NEXT_VERSION" >> $GITHUB_ENV + echo "BASE=$BASE" >> $GITHUB_ENV + + - uses: actions/checkout@v4 + with: + ref: ${{ env.BASE }} + token: ${{ steps.github_app_token.outputs.token }} + + - name: Increment Patch Version + run: | + echo Incrementing $CURRENT_VERSION to $NEXT_VERSION sed -i '' -e "s/^version = \"$CURRENT_VERSION\"/version = \"$NEXT_VERSION\"/g" opensearch/Cargo.toml sed -i '' -e "s/^version = \"$CURRENT_VERSION\"/version = \"$NEXT_VERSION\"/g" api_generator/Cargo.toml sed -i '' -e "s/^version = \"$CURRENT_VERSION\"/version = \"$NEXT_VERSION\"/g" yaml_test_runner/Cargo.toml @@ -38,8 +49,8 @@ jobs: uses: peter-evans/create-pull-request@v3 with: token: ${{ steps.github_app_token.outputs.token }} - base: main - branch: 'create-pull-request/patch-main' + base: ${{ env.BASE }} + branch: 'create-pull-request/patch- ${{ env.BASE }}' commit-message: Increment version to ${{ env.NEXT_VERSION }} signoff: true delete-branch: true