From be2d0ceaf526e92d182d462346adc79f5cce7dd3 Mon Sep 17 00:00:00 2001 From: Ruslan Akhtariev <46343690+RusAkh@users.noreply.github.com> Date: Tue, 1 Nov 2022 08:41:52 +0700 Subject: [PATCH] feat(release): Automated post-upgrade tasks by code generating upgrade 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 (cherry picked from commit 8cd07fdd28a968ed75895f6c7d4a48b0b6494c93) --- .github/workflows/auto-update-upgrade.yml | 38 ++++++++++ scripts/check_release.sh | 21 ++++++ scripts/empty_upgrade_handler_gen.sh | 92 +++++++++++++++++++++++ 3 files changed, 151 insertions(+) create mode 100644 .github/workflows/auto-update-upgrade.yml create mode 100644 scripts/check_release.sh create mode 100755 scripts/empty_upgrade_handler_gen.sh diff --git a/.github/workflows/auto-update-upgrade.yml b/.github/workflows/auto-update-upgrade.yml new file mode 100644 index 00000000000..aee6de935b8 --- /dev/null +++ b/.github/workflows/auto-update-upgrade.yml @@ -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 \ No newline at end of file diff --git a/scripts/check_release.sh b/scripts/check_release.sh new file mode 100644 index 00000000000..befaeaf8ed8 --- /dev/null +++ b/scripts/check_release.sh @@ -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 \ No newline at end of file diff --git a/scripts/empty_upgrade_handler_gen.sh b/scripts/empty_upgrade_handler_gen.sh new file mode 100755 index 00000000000..1ca78fcbcab --- /dev/null +++ b/scripts/empty_upgrade_handler_gen.sh @@ -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 \ No newline at end of file