Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.x] Improve bump-version workflow #285

Merged
merged 2 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .ci/update-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

set -ex

IFS='.' read -r -a VERSION_COMPONENTS <<< "$1"
MAJOR="${VERSION_COMPONENTS[0]}"
MINOR="${VERSION_COMPONENTS[1]}"
PATCH="${VERSION_COMPONENTS[2]}"

if [[ -z "$MAJOR" || -z "$MINOR" || -z "$PATCH" ]]; then
echo "Usage: $0 <major>.<minor>.<patch>"
exit 1
fi

VERSION="$MAJOR.$MINOR.$PATCH"

CURRENT_VERSION=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[] | select(.name == "opensearch") | .version')

cargo install cargo-edit \
&& cargo set-version "${VERSION}"

s=$(command -v gsed || command -v sed)

"$s" -i'' -E "s/\/\/\! opensearch =( \{ version =)? \"${CURRENT_VERSION}\"/\/\/\! opensearch =\1 \"${VERSION}\"/" opensearch/src/lib.rs
3 changes: 1 addition & 2 deletions .github/actions/setup-rust-tools/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ runs:
using: composite
steps:
- name: Install latest stable toolchain
uses: actions-rs/toolchain@v1
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
components: rustfmt, clippy, llvm-tools-preview

- name: Install cargo-make
Expand Down
205 changes: 205 additions & 0 deletions .github/workflows/bump-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
name: Bump Version

on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
workflow_dispatch:
inputs:
branch:
description: 'Branch to bump version on'
required: true
version:
description: 'Version to bump to'
required: true

jobs:
bump-version-manual:
name: Bump Version (Manual)
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch'
permissions:
contents: write
pull-requests: write
steps:
- name: GitHub App Token
if: github.repository == 'opensearch-project/opensearch-rs'
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}

- uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.branch }}

- name: Install latest stable toolchain
uses: dtolnay/rust-toolchain@stable

- name: Install cargo-make
uses: davidB/rust-cargo-make@v1

- name: Bump Version
run: cargo make update-version "$VERSION"
env:
VERSION: ${{ github.event.inputs.version }}

- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
token: ${{ steps.app-token.outputs.token || secrets.GITHUB_TOKEN }}
base: ${{ github.event.inputs.branch }}
branch: "feat/${{ github.event.inputs.branch }}/bump-version"
commit-message: Bump version to ${{ github.event.inputs.version }}
signoff: true
delete-branch: true
title: '[AUTO] Bump version on `${{ github.event.inputs.branch }}` to `${{ github.event.inputs.version }}`'
labels: autocut
body: |
Bumping version on `${{ github.event.inputs.branch }}` to `${{ github.event.inputs.version }}`.

bump-version-auto:
name: Bump Version (Auto)
runs-on: ubuntu-latest
if: github.repository == 'opensearch-project/opensearch-rs' && github.event_name == 'push'
steps:
- name: GitHub App Token
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}

- name: Checkout ${{ github.ref }}
uses: actions/checkout@v4
with:
token: ${{ steps.app-token.outputs.token }}

- name: Install latest stable toolchain
uses: dtolnay/rust-toolchain@stable

- name: Install cargo-make
uses: davidB/rust-cargo-make@v1

- name: Fetch Version Information
run: |
echo "GITHUB_REF=${GITHUB_REF}"
VERSION=$(echo "${GITHUB_REF#refs/*/v}")
VERSION_COMPONENTS=(${VERSION//./ })
MAJOR="${VERSION_COMPONENTS[0]}"
MINOR="${VERSION_COMPONENTS[1]}"
PATCH="${VERSION_COMPONENTS[2]}"
BASE="${MAJOR}.${MINOR}"
BASE_X="${MAJOR}.x"

IS_MAJOR_BUMP=false
IS_MINOR_BUMP=false

if [ "${PATCH}" = "0" ]; then
IS_MINOR_BUMP=true
if [ "${MINOR}" = "0" ]; then
IS_MAJOR_BUMP=true
fi
fi

NEXT_MAJOR="$((MAJOR + 1)).0.0"
NEXT_MINOR="${MAJOR}.$((MINOR + 1)).0"
NEXT_PATCH="${MAJOR}.${MINOR}.$((PATCH + 1))"

{
echo "VERSION=${VERSION}"
echo "MAJOR=${MAJOR}"
echo "MINOR=${MINOR}"
echo "PATCH=${PATCH}"
echo "BASE=${BASE}"
echo "BASE_X=${BASE_X}"
echo "IS_MAJOR_BUMP=${IS_MAJOR_BUMP}"
echo "IS_MINOR_BUMP=${IS_MINOR_BUMP}"
echo "NEXT_MAJOR=${NEXT_MAJOR}"
echo "NEXT_MINOR=${NEXT_MINOR}"
echo "NEXT_PATCH=${NEXT_PATCH}"
} | tee -a "${GITHUB_ENV}"

- name: Create ${{ env.BASE_X }} branch
if: env.IS_MAJOR_BUMP == 'true'
run: git branch ${BASE_X} && git push origin ${BASE_X}

- name: Create ${{ env.BASE }} branch
if: env.IS_MINOR_BUMP == 'true'
run: git branch ${BASE} && git push origin ${BASE}

- name: Checkout ${{ env.BASE }} branch
uses: actions/checkout@v4
with:
ref: ${{ env.BASE }}
token: ${{ steps.app-token.outputs.token }}

- name: Bump Patch Version
run: cargo make update-version "$NEXT_PATCH"

- name: Create Patch Version Pull Request
uses: peter-evans/create-pull-request@v5
with:
token: ${{ steps.app-token.outputs.token }}
base: ${{ env.BASE }}
branch: 'feat/${{ env.BASE }}/bump-version'
commit-message: Bump version to ${{ env.NEXT_PATCH }}
signoff: true
delete-branch: true
title: '[AUTO] Bump version on `${{ env.BASE }}` to `${{ env.NEXT_PATCH }}`'
labels: autocut
body: |
Bumping version on `${{ env.BASE }}` to `${{ env.NEXT_PATCH }}`.

- name: Checkout ${{ env.BASE_X }} branch
if: env.IS_MINOR_BUMP == 'true'
uses: actions/checkout@v4
with:
ref: ${{ env.BASE_X }}
token: ${{ steps.app-token.outputs.token }}

- name: Bump Minor Version
if: env.IS_MINOR_BUMP == 'true'
run: cargo make update-version "$NEXT_MINOR"

- name: Create Minor Version Pull Request
if: env.IS_MINOR_BUMP == 'true'
uses: peter-evans/create-pull-request@v5
with:
token: ${{ steps.app-token.outputs.token }}
base: ${{ env.BASE_X }}
branch: 'feat/${{ env.BASE_X }}/bump-version'
commit-message: Bump version to ${{ env.NEXT_MINOR }}
signoff: true
delete-branch: true
title: '[AUTO] Bump version on `${{ env.BASE_X }}` to `${{ env.NEXT_MINOR }}`'
labels: autocut
body: |
Bumping version on `${{ env.BASE_X }}` to `${{ env.NEXT_MINOR }}`.

- name: Checkout main branch
if: env.IS_MAJOR_BUMP == 'true'
uses: actions/checkout@v4
with:
ref: main
token: ${{ steps.app-token.outputs.token }}

- name: Bump Major Version
if: env.IS_MAJOR_BUMP == 'true'
run: cargo make update-version "$NEXT_MAJOR"

- name: Create Major Version Pull Request
if: env.IS_MAJOR_BUMP == 'true'
uses: peter-evans/create-pull-request@v5
with:
token: ${{ steps.app-token.outputs.token }}
base: main
branch: 'feat/main/bump-version'
commit-message: Bump version to ${{ env.NEXT_MAJOR }}
signoff: true
delete-branch: true
title: '[AUTO] Bump version on `main` to `${{ env.NEXT_MAJOR }}`'
labels: autocut
body: |
Bumping version on `main` to `${{ env.NEXT_MAJOR }}`.
2 changes: 1 addition & 1 deletion .github/workflows/changelog_verifier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
verify-changelog:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
ref: ${{ github.event.pull_request.head.sha }}
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/clippy_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ jobs:
runs-on: ubuntu-latest
if: github.actor != 'dependabot[bot]'
steps:
- uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
with:
toolchain: nightly
components: clippy
override: true
- uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dependabot_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
installation_id: 22958780

- name: Check out code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
token: ${{ steps.github_app_token.outputs.token }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: lychee Link Checker
id: lychee
uses: lycheeverse/lychee-action@v1.5.0
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
issues: write
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- id: get_data
run: |
echo "approvers=$(cat .github/CODEOWNERS | grep @ | tr -d '* ' | sed 's/@/,/g' | sed 's/,//1')" >> $GITHUB_OUTPUT
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Checkout Rust Client
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
path: client

Expand Down Expand Up @@ -57,7 +57,7 @@ jobs:
- name: Upload Coverage Data
uses: codecov/codecov-action@v4
with:
files: ./test_results/opensearch.lcov
files: ./client/test_results/opensearch.lcov
flags: unit
use_oidc: true

Expand Down Expand Up @@ -92,7 +92,7 @@ jobs:
secured: [true, false]
steps:
- name: Checkout Rust Client
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
path: client

Expand Down Expand Up @@ -148,15 +148,15 @@ jobs:
installation_id: 22958780

- name: Checkout Rust Client
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
path: client

- name: Setup Rust tools
uses: ./client/.github/actions/setup-rust-tools

- name: Checkout OpenSearch
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: opensearch-project/opensearch
ref: ${{ matrix.opensearch_ref }}
Expand Down
Loading
Loading