Skip to content

Commit

Permalink
Remove Temporary Cadence 1.0 Migration Features (#1725)
Browse files Browse the repository at this point in the history
  • Loading branch information
jribbink authored Sep 4, 2024
1 parent 77c54f4 commit 46f37b0
Show file tree
Hide file tree
Showing 27 changed files with 12 additions and 5,425 deletions.
6 changes: 0 additions & 6 deletions cmd/flow/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
"github.com/onflow/flow-cli/internal/events"
evm "github.com/onflow/flow-cli/internal/evm"
"github.com/onflow/flow-cli/internal/keys"
"github.com/onflow/flow-cli/internal/migrate"
"github.com/onflow/flow-cli/internal/project"
"github.com/onflow/flow-cli/internal/quick"
"github.com/onflow/flow-cli/internal/scripts"
Expand Down Expand Up @@ -88,7 +87,6 @@ func main() {
cmd.AddCommand(super.FlixCmd)
cmd.AddCommand(super.GenerateCommand)
cmd.AddCommand(dependencymanager.Cmd)
cmd.AddCommand(migrate.Cmd)
cmd.AddCommand(evm.Cmd)

command.InitFlags(cmd)
Expand Down Expand Up @@ -120,10 +118,6 @@ func main() {
ID: "manager",
Title: "🔗 Dependency Manager",
})
cmd.AddGroup(&cobra.Group{
ID: "migrate",
Title: "📦 Migration to 1.0",
})

cmd.SetUsageTemplate(command.UsageTemplate)

Expand Down
20 changes: 2 additions & 18 deletions install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
The destination path to install to.
.Parameter Version
The version to install.
.Parameter C1Version
The Cadence 1 version to install.
.Parameter AddToPath
Add the absolute destination path to the 'User' scope environment variable 'Path'.
.Parameter GitHubToken
Expand All @@ -25,7 +23,6 @@
#>
param (
[string] $version="",
[string] $c1Version="",
[string] $directory = "$env:APPDATA\Flow",
[bool] $addToPath = $true,
[string] $githubToken = ""
Expand Down Expand Up @@ -121,14 +118,6 @@ if (-not $version) {

Install-FlowCLI -version $version -destinationFileName "flow.exe"

if (-not $c1version) {
Write-Output "Getting version of latest Cadence 1.0 preview release ..."

$c1version = Get-Version -searchTerm "cadence-v1.0.0" -prerelease $true
}

Install-FlowCLI -version $c1Version -destinationFileName "flow-c1.exe"

# Check if the directory is already in the PATH
$existingPaths = [Environment]::GetEnvironmentVariable("PATH", [System.EnvironmentVariableTarget]::User).Split(';')

Expand All @@ -140,12 +129,7 @@ if ($addToPath -and $existingPaths -notcontains $directory) {
[System.Environment]::SetEnvironmentVariable("PATH", $userPath, [System.EnvironmentVariableTarget]::User)
}

Write-Output ""
Write-Output "Successfully installed Flow CLI $version as 'flow'."
Write-Output "Use the 'flow' command to interact with the Flow CLI compatible with versions of Cadence before 1.0 (only)."
Write-Output ""
Write-Output "Successfully installed Flow CLI $c1Version as 'flow-c1'."
Write-Output "Use the 'flow-c1' command to interact with the Flow CLI preview compatible with Cadence 1.0 (only)."
Write-Output ""
Write-Output "Successfully installed Flow CLI $version"
Write-Output "Use the 'flow' command to interact with the Flow CLI"

Start-Sleep -Seconds 1
50 changes: 0 additions & 50 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ REPO="onflow/flow-cli"
ASSETS_URL="https://github.com/$REPO/releases/download/"
# The version to install (defaults to args[1])
VERSION="$1"
# The Cadence 1.0 version to install (defaults to args[2])
C1VERSION="$2"
# The architecture string, set by get_architecture
ARCH=""

Expand Down Expand Up @@ -61,38 +59,6 @@ get_architecture() {
TARGET_PATH="${_targetpath}"
}

get_version() {
local search_term="$1"
local page="$2"

local version=""

response=$(curl -H "$github_token_header" -s "https://api.github.com/repos/$REPO/releases?per_page=10&page=$page" -w "%{http_code}")

status=$(echo "$response" | tail -n 1)
if [ "$status" -eq "403" ] && [ -n "$github_token_header" ]
then
echo "Failed to get releases from Github API, is your GITHUB_TOKEN valid? Re-trying without authentication ..."
github_token_header=""
get_version "$search_term" "$page"
fi

if [ "$status" -ne "200" ]
then
echo "Failed to get releases from Github API, please manually specify a version to install as an argument to this script."
return 1
fi

version=$(echo "$response" | grep -E 'tag_name' | grep -E "$search_term" | head -n 1 | cut -d '"' -f 4)

if [ -z "$version" ]
then
get_version "$search_term" "$((page+1))"
fi

echo "$version"
}

get_latest() {
local version=""

Expand Down Expand Up @@ -155,24 +121,8 @@ main() {

install_version "$VERSION" "flow"

if [ -z "$C1VERSION" ]
then
echo "Getting version of latest Cadence 1.0 preview release ..."

C1VERSION=$(get_version "cadence-v1.0.0" 1 || exit 1)
fi

install_version "$C1VERSION" "flow-c1"

echo ""
echo "Successfully installed Flow CLI $VERSION as 'flow' in $TARGET_PATH."
echo "Use the 'flow' command to interact with the Flow CLI compatible with versions of Cadence before 1.0 (only)."
echo ""
echo "Successfully installed Flow CLI $C1VERSION as 'flow-c1' in $TARGET_PATH."
echo "Use the 'flow-c1' command to interact with the Flow CLI preview compatible with Cadence 1.0 (only)."
echo ""
echo "Make sure $TARGET_PATH is in your \$PATH environment variable."
echo ""
}

main
108 changes: 10 additions & 98 deletions internal/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import (

"github.com/dukex/mixpanel"
"github.com/getsentry/sentry-go"
"github.com/google/go-github/github"
"github.com/spf13/afero"
"github.com/spf13/cobra"

Expand All @@ -48,7 +47,6 @@ import (
"github.com/onflow/flowkit/v2/output"

"github.com/onflow/flow-cli/build"
"github.com/onflow/flow-cli/internal/migrate/validator"
"github.com/onflow/flow-cli/internal/settings"
"github.com/onflow/flow-cli/internal/util"
)
Expand Down Expand Up @@ -130,11 +128,6 @@ func (c Command) AddToParent(parent *cobra.Command) {
checkVersion(logger)
}

// check contract migrations if flag is set
if !Flags.SkipContractMigrationCheck {
checkContractMigrations(state, logger, flow)
}

// record command usage
wg := sync.WaitGroup{}
go UsageMetrics(c.Cmd, &wg)
Expand Down Expand Up @@ -275,12 +268,6 @@ func checkVersion(logger output.Logger) {
return // avoid warning in local development
}

// If using cadence-v1.0.0 pre-release, check for cadence-v1.0.0 releases instead
if strings.Contains(currentVersion, "cadence-v1.0.0") {
checkVersionCadence1(logger)
return
}

resp, err := http.Get("https://formulae.brew.sh/api/formula/flow-cli.json")
if err != nil || resp.StatusCode >= 400 {
return
Expand Down Expand Up @@ -322,52 +309,6 @@ func checkVersion(logger output.Logger) {
}
}

// checkVersionCadence1 fetches latest version of cadence-v1.0.0 and compares it to local.
// This is a special case for cadence-v1.0.0 pre-release & should be removed when cadence-v1.0.0 branch is merged.
func checkVersionCadence1(logger output.Logger) {
resp, err := http.Get("https://api.github.com/repos/onflow/flow-cli/tags?per_page=100")
if err != nil || resp.StatusCode >= 400 {
return
}

defer func(Body io.ReadCloser) {
err := Body.Close()
if err != nil {
logger.Error("error closing request")
}
}(resp.Body)

body, _ := io.ReadAll(resp.Body)
var tags []map[string]interface{}
err = json.Unmarshal(body, &tags)
if err != nil {
return
}

var latestVersion string
for _, tag := range tags {
tagName, ok := tag["name"].(string)
if !ok {
continue
}

if strings.Contains(tagName, "cadence-v1.0.0") {
latestVersion = tagName
break
}
}

currentVersion := build.Semver()
if currentVersion != latestVersion && latestVersion != "" {
logger.Info(fmt.Sprintf(
"\n%s Version warning: a new version of Flow CLI is available (%s).\n"+
" Read the installation guide for upgrade instructions: https://cadence-lang.org/docs/cadence-migration-guide#install-cadence-10-cli\n",
output.WarningEmoji(),
strings.ReplaceAll(latestVersion, "\n", ""),
))
}
}

func isDevelopment() bool {
return build.Semver() == "undefined"
}
Expand Down Expand Up @@ -435,43 +376,14 @@ func UsageMetrics(command *cobra.Command, wg *sync.WaitGroup) {

// GlobalFlags contains all global flags definitions.
type GlobalFlags struct {
Filter string
Format string
Save string
Host string
HostNetworkKey string
Log string
Network string
Yes bool
ConfigPaths []string
SkipVersionCheck bool
SkipContractMigrationCheck bool
}

const migrationDataURL = "https://github.com/onflow/cadence/tree/master/migrations_data"

func checkContractMigrations(state *flowkit.State, logger output.Logger, flow flowkit.Services) {
contractStatuses, err := validator.NewValidator(github.NewClient(nil).Repositories, flow.Network(), state, logger).GetContractStatuses()
if err != nil {
// if we can't get the contract statuses, we don't check them
return
}

var failedContracts []validator.ContractUpdateStatus

for _, contract := range contractStatuses {
if contract.IsFailure() {
failedContracts = append(failedContracts, contract)
}
}

if len(failedContracts) > 0 {
fmt.Fprintf(
os.Stderr, "\n%s Heads up: We ran a check in the background to verify that your contracts are still valid for the Cadence 1.0 migration. We found %d contract(s) that have failed to migrate. \n", output.ErrorEmoji(), len(failedContracts),
)
fmt.Fprintf(
os.Stderr, "\n Please visit %s for the latest migration snapshot and information about the failure. \n", migrationDataURL,
)
}
return
Filter string
Format string
Save string
Host string
HostNetworkKey string
Log string
Network string
Yes bool
ConfigPaths []string
SkipVersionCheck bool
}
Loading

0 comments on commit 46f37b0

Please sign in to comment.