Skip to content

Commit

Permalink
Automated version increment [Part 1] (Stride-Labs#770)
Browse files Browse the repository at this point in the history
  • Loading branch information
sampocs authored May 11, 2023
1 parent 2c40654 commit 778ed92
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 0 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Update Stride Version

on:
workflow_dispatch:
inputs:
old_version:
description: "Specify the old version (e.g. 8.0.0)"
new_version:
description: "Specify the new version (e.g. 9.0.0)"

jobs:
increment-stride-version:
runs-on: ubuntu-latest

steps:
- name: Get versions
run: |
old_version=${{ github.event.inputs.old_version }}
new_version=${{ github.event.inputs.new_version }}
new_major_version=v$(echo $new_version | cut -d '.' -f 1)
branch_name=update-stride-version-${new_major_version}
echo "old_version=$old_version" >> $GITHUB_ENV
echo "new_version=$new_version" >> $GITHUB_ENV
echo "branch_name=$branch_name" >> $GITHUB_ENV
- name: Checkout main
uses: actions/checkout@v3
with:
ref: main

- name: Create branch
run: git checkout -b update-stride-version-${{ env.new_major_version }}

- name: Update versions in files
run: |
OLD_VERSION=${{ env.old_version }} NEW_VERSION=${{ env.new_version }} bash scripts/version.sh
- name: Push changes
uses: ad-m/github-push-action@v0.6.0
with:
branch: ${{ env.branch_name }}

- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ env.branch_name }}
base: main
title: Update Stride Version to ${{ env.new_version }}
body: |
This is an automatically generated pull request.
Please review and merge the changes.
## Context
Increments Stride version for the ${{ env.new_major_version }} upgrade
## Brief Changelog
* Increments Stride version in cmd/strided/config/config.go and app/app.go
* Updates module name to ${{ env.new_major_version }}
* Re-generates protos
63 changes: 63 additions & 0 deletions scripts/version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash

set -eu

VERSION_REGEX='[0-9]{1,2}\.[0-9]{1}\.[0-9]{1}$'

# Validate script parameters
if [ -z "$OLD_VERSION" ]; then
echo "OLD_VERSION must be set (e.g. 8.0.0). Exiting..."
exit 1
fi

if [ -z "$NEW_VERSION" ]; then
echo "NEW_VERSION must be set (e.g. 8.0.0). Exiting..."
exit 1
fi

if ! echo $OLD_VERSION | grep -Eq $VERSION_REGEX; then
echo "OLD_VERSION must be of form {major}.{minor}.{patch} (e.g. 8.0.0). Exiting..."
fi

if ! echo $NEW_VERSION | grep -Eq $VERSION_REGEX; then
echo "NEW_VERSION must be of form {major}.{minor}.{patch} (e.g. 8.0.0). Exiting..."
fi

if [ "$(basename "$PWD")" != "stride" ]; then
echo "The script must be run from the project home directory. Exiting..."
fi

# Update version
CONFIG_FILE=cmd/strided/config/config.go
APP_FILE=app/app.go

sed -i '' "s/$OLD_VERSION/$NEW_VERSION/g" $CONFIG_FILE
sed -i '' "s/$OLD_VERSION/$NEW_VERSION/g" $APP_FILE

git add $CONFIG_FILE $APP_FILE
git commit -m "updated version from $OLD_VERSION to $NEW_VERSION"


# Update package name
OLD_MAJOR_VERSION=v$(echo "$OLD_VERSION" | cut -d '.' -f 1)
NEW_MAJOR_VERSION=v$(echo "$NEW_VERSION" | cut -d '.' -f 1)

for parent_directory in "app" "cmd" "proto" "testutil" "third_party" "utils" "x"; do
for file in $(find $parent_directory -type f \( -name "*.go" -o -name "*.proto" \)); do
echo "Updating version in $file"
sed -i '' "s|github.com/Stride-Labs/stride/$OLD_MAJOR_VERSION|github.com/Stride-Labs/stride/$NEW_MAJOR_VERSION|g" $file
done
done

sed -i '' "s|github.com/Stride-Labs/stride/$OLD_MAJOR_VERSION|github.com/Stride-Labs/stride/$NEW_MAJOR_VERSION|g" go.mod

git add .
git commit -m "updated package from $OLD_MAJOR_VERSION -> $NEW_MAJOR_VERSION"


# Re-generate protos
make proto-all

git add .
git commit -m 'generated protos'

0 comments on commit 778ed92

Please sign in to comment.