Skip to content

Commit

Permalink
feat(release): Automated post-upgrade tasks by code generating upgrad…
Browse files Browse the repository at this point in the history
…e handler and auto-increasing e2e version (#3100)

* automate post-upgrade tasks by code generating upgrade handler and setting e2e in makefile

* automate post-upgrade tasks by code generating upgrade handler and setting e2e in makefile

* save

* save

* save

* yaml

* save

* save

* save

* save

* save

* save

* save

* save

* save

* save

* save

* save

* save

* save

* save

* save

* save

* save

* save

* save

* save

* save

* save

* save

* save

* save

* save

* save

* On release auto upgrade

* On release auto upgrade

* On release auto upgrade

* On release auto upgrade

* On release auto upgrade

* On release auto upgrade

* On release auto upgrade

* On release auto upgrade

* On release auto upgrade

* On release auto upgrade

* On release auto upgrade

* On release auto upgrade

* docs

* save

* also changes app.go

* also changes app.go

* also changes app.go

* test using ci because will run forever on m1 with qemu

* save

* post release action

* post release github action

* auto postrelease action

* cleanup

* cleanup

* cleanup

* del

* docs

* major

* save

* save

* save

* Save

* save

* save

* save

* save

* save

* save

* save

* save

* save

* save

* save

* save

* save

* save

* save

* save

* save

* save

* save

* save

* save

* save

* save

* save

* save

* save

* save

* save

* save

* save

* save

* save

* save

* s

* s

* s

* s

* s

* only on major upgrades

* docs

Co-authored-by: Ruslan Akhtariev <ruslanakhtariev@Ruslans-MacBook-Air.local>
(cherry picked from commit 8cd07fd)
  • Loading branch information
pysel authored and mergify[bot] committed Nov 1, 2022
1 parent d1be7b5 commit be2d0ce
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/auto-update-upgrade.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# When new major release is created this workflow will be triggered and will do 3 things:
# 1) it will create a directory with an empty upgrade handler in app/upgrades folder
# 2) will increase an E2E_UPGRADE_VERSION variable in Makefile
# 3) create a pull request with these changes to main

name: On Release Auto Upgrade

on:
release:
types: [published]

jobs:
post_release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2.3.4

- name: Run version script
run: bash ./scripts/check_release.sh ${{ github.event.release.tag_name }}

- name: Run post release script
if: env.MAJOR == 1 # 1 means vX of existing upgrade handler is smaller than A in tag vA.B.C
run: bash ./scripts/empty_upgrade_handler_gen.sh

- name: Create PR
if: env.MAJOR == 1
uses: peter-evans/create-pull-request@v4
with:
base: ${{ github.event.repository.default_branch }}
body: |
Update report
- Created a new empty upgrade handler
- Increased E2E_UPGRADE_VERSION in Makefile by 1
labels: |
T:auto
C:e2e
C:app-wiring
21 changes: 21 additions & 0 deletions scripts/check_release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# this script checks if existing upgrade handler's version is not smaller than current release

#!/bin/bash

VERSION=$1
latest_version=0
for f in app/upgrades/*; do
s_f=(${f//// })
version=${s_f[2]}
num_version=${version//[!0-9]/}
if [[ $num_version -gt $latest_version ]]; then
latest_version=$num_version
fi
done

VERSION=${VERSION[@]:1}
VERSION_MAJOR=(${VERSION//./ })
VERSION_MAJOR=${VERSION_MAJOR[0]}
if [[ $VERSION_MAJOR -gt $latest_version ]]; then
echo "MAJOR=1" >> $GITHUB_ENV
fi
92 changes: 92 additions & 0 deletions scripts/empty_upgrade_handler_gen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/bin/bash

# 1) this script creates an empty directory in app/upgrades called "vX" where X is a previous version + 1 with an empty upgrade handler.
# 2) increases E2E_UPGRADE_VERSION in makefile by 1
# 3) adds new version to app.go

# Also insures that all the imports make use of a current module version from go mod:
# (see: module=$(go mod edit -json | jq ".Module.Path") in this script)
# Github workflow which calls this script can be found here: osmosis/.github/workflows/auto-update-upgrade.yml

latest_version=0
for f in app/upgrades/*; do
s_f=(${f//// })
version=${s_f[2]}
num_version=${version//[!0-9]/}
if [[ $num_version -gt $latest_version ]]; then
LATEST_FILE=$f
latest_version=$num_version
fi
done
version_create=$((latest_version+1))
new_file=./app/upgrades/v${version_create}

mkdir $new_file
CONSTANTS_FILE=$new_file/constants.go
UPGRADES_FILE=$new_file/upgrades.go
touch $CONSTANTS_FILE
touch $UPGRADES_FILE

module=$(go mod edit -json | jq ".Module.Path")
module=${module%?}
path=${module%???}

bracks='"'
# set packages
echo -e "package v${version_create}\n" >> $CONSTANTS_FILE
echo -e "package v${version_create}\n" >> $UPGRADES_FILE

# imports
echo "import (" >> $CONSTANTS_FILE
echo "import (" >> $UPGRADES_FILE

# set imports for constants.go
echo -e "\t$module/app/upgrades$bracks\n" >> $CONSTANTS_FILE
echo -e '\tstore "github.com/cosmos/cosmos-sdk/store/types"' >> $CONSTANTS_FILE

# set imports for upgrades.go
echo -e '\tsdk "github.com/cosmos/cosmos-sdk/types"' >> $UPGRADES_FILE
echo -e '\t"github.com/cosmos/cosmos-sdk/types/module"' >> $UPGRADES_FILE
echo -e '\tupgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"\n' >> $UPGRADES_FILE
echo -e "\t$module/app/keepers$bracks" >> $UPGRADES_FILE
echo -e "\t$module/app/upgrades$bracks" >> $UPGRADES_FILE

# close import
echo ")" >> $UPGRADES_FILE
echo -e ")\n" >> $CONSTANTS_FILE

# constants.go logic
echo "// UpgradeName defines the on-chain upgrade name for the Osmosis v$version_create upgrade." >> $CONSTANTS_FILE
echo "const UpgradeName = ${bracks}v$version_create$bracks" >> $CONSTANTS_FILE
echo "
var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateUpgradeHandler,
StoreUpgrades: store.StoreUpgrades{},
}" >> $CONSTANTS_FILE

# upgrades.go logic
echo "
func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
bpm upgrades.BaseAppParamManager,
keepers *keepers.AppKeepers,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
return mm.RunMigrations(ctx, configurator, fromVM)
}
}" >> $UPGRADES_FILE

# change app/app.go file
app_file=./app/app.go
UPGRADES_LINE=$(grep -F upgrades.Upgrade{ $app_file)
UPGRADES_LINE="${UPGRADES_LINE%?}, v${version_create}.Upgrade}"
sed -i "s|.*upgrades.Upgrade{.*|$UPGRADES_LINE|" $app_file

PREV_IMPORT="v$latest_version $module/app/upgrades/v$latest_version$bracks"
NEW_IMPORT="v$version_create $module/app/upgrades/v$version_create$bracks"
sed -i "s|.*$PREV_IMPORT.*|\t$PREV_IMPORT\n\t$NEW_IMPORT|" $app_file

# change e2e version in makefile
sed -i "s/E2E_UPGRADE_VERSION := ${bracks}v$latest_version$bracks/E2E_UPGRADE_VERSION := ${bracks}v$version_create$bracks/" ./Makefile

0 comments on commit be2d0ce

Please sign in to comment.