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

feat(release): Automated post-upgrade tasks by code generating upgrade handler and auto-increasing e2e version #3100

Merged
merged 111 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
111 commits
Select commit Hold shift + click to select a range
7e31144
automate post-upgrade tasks by code generating upgrade handler and se…
Oct 17, 2022
e4c5901
automate post-upgrade tasks by code generating upgrade handler and se…
Oct 17, 2022
5965c1a
save
Oct 18, 2022
b4bface
save
Oct 18, 2022
1531050
save
Oct 18, 2022
ebd3a2d
Merge branch 'osmosis-labs:main' into issue2609_auto_postupgrade
pysel Oct 18, 2022
1783366
yaml
Oct 18, 2022
480931d
save
Oct 18, 2022
d705841
save
Oct 19, 2022
e39aa1e
save
Oct 19, 2022
335e34a
save
Oct 19, 2022
94546ff
save
Oct 19, 2022
cbd2a7e
save
Oct 19, 2022
9a82b4f
save
Oct 19, 2022
1c3571a
save
Oct 19, 2022
d1d194d
save
Oct 19, 2022
3982811
save
Oct 19, 2022
5eb4c2c
save
Oct 19, 2022
59d5717
Merge branch 'osmosis-labs:main' into issue2609_auto_postupgrade
pysel Oct 19, 2022
119ec82
save
Oct 19, 2022
3a32fb8
save
Oct 19, 2022
dca5d4a
save
Oct 19, 2022
eb4aa09
save
Oct 19, 2022
999647a
save
Oct 19, 2022
9a1dec9
save
Oct 19, 2022
015e735
save
Oct 19, 2022
62a103f
save
Oct 19, 2022
63b932e
save
Oct 19, 2022
78c44bb
save
Oct 19, 2022
8981d1e
save
Oct 19, 2022
b92b987
save
Oct 19, 2022
09c001b
save
Oct 19, 2022
b2e8857
save
Oct 19, 2022
406b0a4
save
Oct 19, 2022
4f37b2c
save
Oct 19, 2022
36d3229
save
Oct 19, 2022
453e8f4
On release auto upgrade
Oct 19, 2022
525be31
On release auto upgrade
Oct 19, 2022
5b29f1d
On release auto upgrade
Oct 19, 2022
553acbc
On release auto upgrade
Oct 19, 2022
f600966
On release auto upgrade
Oct 19, 2022
6d5405a
On release auto upgrade
Oct 19, 2022
fc62b8c
On release auto upgrade
Oct 19, 2022
5722177
On release auto upgrade
Oct 19, 2022
42ab2bb
On release auto upgrade
Oct 19, 2022
1a7f5d9
On release auto upgrade
Oct 19, 2022
60b653b
On release auto upgrade
Oct 19, 2022
77cf470
On release auto upgrade
Oct 19, 2022
4e5dc75
docs
Oct 20, 2022
e48f011
save
Oct 21, 2022
0eb3cc8
also changes app.go
Oct 21, 2022
b6218b5
also changes app.go
Oct 21, 2022
447a35c
also changes app.go
Oct 21, 2022
01166f1
Merge branch 'osmosis-labs:main' into issue2609_auto_postupgrade
pysel Oct 22, 2022
5545bfd
test using ci because will run forever on m1 with qemu
Oct 22, 2022
752b037
save
Oct 22, 2022
ffce6d7
post release action
Oct 22, 2022
3d4444d
post release github action
Oct 22, 2022
54f20bd
auto postrelease action
Oct 24, 2022
fd55fe5
Merge branch 'osmosis-labs:main' into issue2609_auto_post
pysel Oct 24, 2022
59b6fe3
cleanup
Oct 24, 2022
9bd65f5
cleanup
Oct 24, 2022
1f6d461
cleanup
Oct 24, 2022
d06b511
del
Oct 24, 2022
8c54d59
docs
Oct 24, 2022
8243cc6
Merge branch 'osmosis-labs:main' into issue2609_auto_post
pysel Oct 25, 2022
e7f3e41
major
Oct 25, 2022
5dcd952
save
Oct 25, 2022
1515062
save
Oct 25, 2022
c2790b9
save
Oct 25, 2022
59076af
Save
Oct 25, 2022
8195dad
save
Oct 25, 2022
93b8d83
save
Oct 25, 2022
1875254
save
Oct 25, 2022
6ba00ea
save
Oct 25, 2022
fd63c09
save
Oct 25, 2022
a0252df
save
Oct 25, 2022
b5d80cc
save
Oct 25, 2022
15175fd
save
Oct 25, 2022
18eb02b
save
Oct 25, 2022
1674b64
save
Oct 25, 2022
0d35e89
save
Oct 25, 2022
0249476
save
Oct 25, 2022
d666711
save
Oct 25, 2022
e5f5723
save
Oct 25, 2022
93e84c8
save
Oct 25, 2022
89ce36c
save
Oct 25, 2022
2c17fab
save
Oct 25, 2022
68e4565
save
Oct 25, 2022
188fd00
save
Oct 25, 2022
ff432aa
save
Oct 25, 2022
26414d7
save
Oct 25, 2022
e49ec37
save
Oct 25, 2022
2cbd422
save
Oct 25, 2022
72e0d6d
save
Oct 25, 2022
7523693
save
Oct 25, 2022
51070f9
save
Oct 25, 2022
804ed59
save
Oct 25, 2022
e6a391a
save
Oct 25, 2022
5cc4830
save
Oct 25, 2022
a0cf161
save
Oct 25, 2022
7345f3f
save
Oct 25, 2022
de49b17
save
Oct 25, 2022
248619b
save
Oct 25, 2022
2f04f1b
s
Oct 25, 2022
4b4ec87
s
Oct 25, 2022
1b44e5a
s
Oct 25, 2022
045f3f4
s
Oct 25, 2022
3bb7234
s
Oct 25, 2022
1f56210
only on major upgrades
Oct 25, 2022
9beb3ae
docs
Oct 25, 2022
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
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

pysel marked this conversation as resolved.
Show resolved Hide resolved
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