Skip to content

Commit

Permalink
Merge pull request #90 from algorandfoundation/v1.1.0
Browse files Browse the repository at this point in the history
release: v1.1.0
  • Loading branch information
PhearZero authored Jan 14, 2025
2 parents 51b8e76 + a5bcf50 commit f4a7254
Show file tree
Hide file tree
Showing 69 changed files with 1,337 additions and 1,088 deletions.
Binary file added .DS_Store
Binary file not shown.
18 changes: 13 additions & 5 deletions .github/workflows/CD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,24 @@ jobs:
- uses: actions/checkout@v4
- name: Install dependencies
run: go get .
- uses: go-semantic-release/action@v1
name: release
id: semver
with:
dry: true
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Add version to env
run: echo "VERSION=${{ steps.semver.outputs.version }}" >> $GITHUB_ENV
- name: Build
env:
GOOS: ${{matrix.goos}}
GOARCH: ${{matrix.goarch}}
CGO_ENABLED: 0
run: go build -o bin/algorun-${{matrix.goarch}}-${{matrix.goos}} *.go
run: go build -ldflags "-X main.version=${VERSION}" -o bin/nodekit-${{matrix.goarch}}-${{matrix.goos}} *.go
- uses: actions/upload-artifact@master
with:
name: algorun-${{matrix.goarch}}-${{matrix.goos}}
path: bin/algorun-${{matrix.goarch}}-${{matrix.goos}}
name: nodekit-${{matrix.goarch}}-${{matrix.goos}}
path: bin/nodekit-${{matrix.goarch}}-${{matrix.goos}}
release:
needs:
- build
Expand All @@ -37,7 +45,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
pattern: algorun*
pattern: nodekit*
path: ./bin
- uses: go-semantic-release/action@v1
name: release
Expand All @@ -47,4 +55,4 @@ jobs:
- name: Upload Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh release upload v${{steps.semver.outputs.version}} bin/**/*
run: gh release upload v${{steps.semver.outputs.version}} bin/**/*
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
VERSION ?= dev

.PHONY: all

build:
CGO_ENABLED=0 go build -o bin/nodekit .
CGO_ENABLED=0 go build -ldflags "-X main.version=${VERSION}" -o bin/nodekit .
test:
go test -coverprofile=coverage.out -coverpkg=./... -covermode=atomic ./...
generate:
Expand Down
36 changes: 36 additions & 0 deletions api/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
)

const ChannelNotFoundMsg = "channel not found"
const NodeKitReleaseNotFoundMsg = "nodekit release not found"

type GithubVersionResponse struct {
HTTPResponse *http.Response
Expand Down Expand Up @@ -66,3 +67,38 @@ func GetGoAlgorandReleaseWithResponse(http HttpPkgInterface, channel string) (*G
versions.JSON200 = *versionResponse
return &versions, nil
}

func GetNodeKitReleaseWithResponse(http HttpPkgInterface) (*GithubVersionResponse, error) {
var versions GithubVersionResponse
resp, err := http.Get("https://api.github.com/repos/algorandfoundation/nodekit/releases/latest")
versions.HTTPResponse = resp
if resp == nil || err != nil {
return nil, err
}
// Update Model
versions.ResponseCode = resp.StatusCode
versions.ResponseStatus = resp.Status

// Exit if not 200
if resp.StatusCode != 200 {
return &versions, nil
}

defer resp.Body.Close()

// Parse the versions to a map
var releaseMap map[string]interface{}
if err = json.NewDecoder(resp.Body).Decode(&releaseMap); err != nil {
return &versions, err
}

version := releaseMap["tag_name"]

if version == nil {
return &versions, errors.New(NodeKitReleaseNotFoundMsg)
}

// Update the JSON200 data and return
versions.JSON200 = strings.Replace(version.(string), "v", "", 1)
return &versions, nil
}
44 changes: 34 additions & 10 deletions cmd/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package cmd
import (
"context"
"fmt"
"time"

"github.com/algorandfoundation/nodekit/api"
cmdutils "github.com/algorandfoundation/nodekit/cmd/utils"
"github.com/algorandfoundation/nodekit/cmd/utils/explanations"
Expand All @@ -18,7 +20,6 @@ import (
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/log"
"github.com/spf13/cobra"
"time"
)

// bootstrapCmdShort provides a brief description of the "bootstrap" command to initialize a fresh Algorand node.
Expand All @@ -40,7 +41,7 @@ var bootstrapCmdLong = lipgloss.JoinVertical(

var tutorial = `# Welcome!
This is the beginning of your adventure into running the an Algorand node!
This is the beginning of your adventure into running an Algorand node!
`

Expand All @@ -51,6 +52,17 @@ var bootstrapCmd = &cobra.Command{
Long: bootstrapCmdLong,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
// Exit the application in an invalid state
if algod.IsInstalled() && !algod.IsService() {
dataDir, _ := algod.GetDataDir("")
if dataDir == "" {
dataDir = "<Path to data directory>"
}
log.Warn("algorand is installed, but not running as a service. Continue at your own risk!")
log.Warn(fmt.Sprintf("try connecting to the node with: ./nodekit -d %s", dataDir))
log.Fatal("invalid state, exiting")
}

ctx := context.Background()
httpPkg := new(api.HttpPkg)
r, _ := glamour.NewTermRenderer(
Expand Down Expand Up @@ -84,23 +96,36 @@ var bootstrapCmd = &cobra.Command{
if _, err := p.Run(); err != nil {
log.Fatal(err)
}

if msg == nil {
return nil
}

log.Warn(style.Yellow.Render(explanations.SudoWarningMsg))
if msg.Install && !algod.IsInstalled() {
if msg.Install {
log.Warn(style.Yellow.Render(explanations.SudoWarningMsg))

err := algod.Install()
if err != nil {
return err
}
}

// Wait for algod
time.Sleep(10 * time.Second)
// Wait for algod
time.Sleep(10 * time.Second)

if !algod.IsRunning() {
log.Fatal("algod is not running")
if !algod.IsRunning() {
log.Fatal("algod is not running. Something went wrong with installation")
}
} else {
if !algod.IsRunning() {
log.Info(style.Green.Render("Starting Algod 🚀"))
log.Warn(style.Yellow.Render(explanations.SudoWarningMsg))
err := algod.Start()
if err != nil {
log.Fatal(err)
}
log.Info(style.Green.Render("Algorand started successfully 🎉"))
time.Sleep(2 * time.Second)
}
}

dataDir, err := algod.GetDataDir("")
Expand All @@ -114,7 +139,6 @@ var bootstrapCmd = &cobra.Command{
}

if msg.Catchup {

network, err := utils.GetNetworkFromDataDir(dataDir)
if err != nil {
return err
Expand Down
18 changes: 9 additions & 9 deletions cmd/configure/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func configureNode() error {

// Check systemctl first
if algod.IsService() {
if promptWrapperYes("Algorand is installed as a service. Do you wish to edit the service file to change the data directory? (y/n)") {
if promptWrapperYes("Algorand is installed as a service. Do you wish to edit the service file to change the data directory? (y/N)") {
// Edit the service file with the user's new data directory
systemServiceConfigure = true
} else {
Expand Down Expand Up @@ -84,18 +84,18 @@ func configureNode() error {
fmt.Println("Found valid Algorand Data Directory: " + algorandData)

if systemServiceConfigure {
if promptWrapperYes("Would you like to set the ALGORAND_DATA env variable as the data directory for the systemd Algorand service? (y/n)") {
if promptWrapperYes("Would you like to set the ALGORAND_DATA env variable as the data directory for the systemd Algorand service? (y/N)") {
editAlgorandServiceFile(algorandData)
os.Exit(0)
}
}

if promptWrapperNo("Do you want to set a completely new data directory? (y/n)") {
if promptWrapperNo("Do you want to set a completely new data directory? (y/N)") {
fmt.Println("User chose not to set a completely new data directory.")
os.Exit(0)
}

if promptWrapperYes("Do you want to manually input the new data directory? (y/n)") {
if promptWrapperYes("Do you want to manually input the new data directory? (y/N)") {
newPath := promptWrapperInput("Enter the new data directory path")

if !validateAlgorandDataDir(newPath) {
Expand Down Expand Up @@ -130,7 +130,7 @@ func configureNode() error {
}

if len(paths) == 1 {
if promptWrapperYes("Do you want to set this directory as the new data directory? (y/n)") {
if promptWrapperYes("Do you want to set this directory as the new data directory? (y/N)") {
if systemServiceConfigure {
// Edit the service file
editAlgorandServiceFile(paths[0])
Expand All @@ -142,7 +142,7 @@ func configureNode() error {

} else {

if promptWrapperYes("Do you want to set one of these directories as the new data directory? (y/n)") {
if promptWrapperYes("Do you want to set one of these directories as the new data directory? (y/N)") {

selectedPath := promptWrapperSelection("Select an Algorand data directory", paths)

Expand All @@ -158,12 +158,12 @@ func configureNode() error {
}

// Deep search
if promptWrapperNo("Do you want NodeKit to do a deep search for pre-existing Algorand Data directories? (y/n)") {
fmt.Println("User chose not to search for more pre-existing Algorand Data directories. Exiting...")
if promptWrapperNo("Do you want NodeKit to do a deep search for pre-existing Algorand data directories? (y/N)") {
fmt.Println("User chose not to search for more pre-existing Algorand data directories. Exiting...")
os.Exit(0)
}

fmt.Println("Searching for pre-existing Algorand Data directories in HOME directory...")
fmt.Println("Searching for pre-existing Algorand data directories in HOME directory...")
paths = deepSearchAlgorandDataDirs()

if len(paths) == 0 {
Expand Down
1 change: 1 addition & 0 deletions cmd/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ var debugCmd = cmdutils.WithAlgodFlags(&cobra.Command{
return err
}
folderDebug, err := utils.ToDataFolderConfig(dataDir)
folderDebug.Token = folderDebug.Token[:3] + "..."
if err != nil {
return err
}
Expand Down
18 changes: 10 additions & 8 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"context"
"fmt"
"github.com/algorandfoundation/nodekit/api"
"github.com/algorandfoundation/nodekit/cmd/catchup"
"github.com/algorandfoundation/nodekit/cmd/configure"
Expand All @@ -21,12 +22,11 @@ import (
var (
Name = "nodekit"

NeedsUpgrade = false

// algodEndpoint defines the URI address of the Algorand node, including the protocol (http/https), for client communication.
algodData string

// Version represents the application version string, which is set during build or defaults to "unknown".
Version = ""

// force indicates whether actions should be performed forcefully, bypassing checks or confirmations.
force bool = false

Expand All @@ -45,10 +45,9 @@ var (
)
// RootCmd is the primary command for managing Algorand nodes, providing CLI functionality and TUI for interaction.
RootCmd = utils.WithAlgodFlags(&cobra.Command{
Use: Name,
Version: Version,
Short: short,
Long: long,
Use: Name,
Short: short,
Long: long,
CompletionOptions: cobra.CompletionOptions{
DisableDefaultCmd: true,
},
Expand Down Expand Up @@ -128,6 +127,7 @@ func NeedsToBeStopped(cmd *cobra.Command, args []string) {
// init initializes the application, setting up logging, commands, and version information.
func init() {
log.SetReportTimestamp(false)
RootCmd.SetVersionTemplate(fmt.Sprintf("nodekit-%s-%s@{{.Version}}\n", runtime.GOARCH, runtime.GOOS))
// Add Commands
if runtime.GOOS != "windows" {
RootCmd.AddCommand(bootstrapCmd)
Expand All @@ -143,6 +143,8 @@ func init() {
}

// Execute executes the root command.
func Execute() error {
func Execute(version string, needsUpgrade bool) error {
RootCmd.Version = version
NeedsUpgrade = needsUpgrade
return RootCmd.Execute()
}
19 changes: 14 additions & 5 deletions cmd/upgrade.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package cmd

import (
"github.com/algorandfoundation/nodekit/api"
"github.com/algorandfoundation/nodekit/cmd/utils/explanations"
"github.com/algorandfoundation/nodekit/internal/algod"
"github.com/algorandfoundation/nodekit/internal/system"
"github.com/algorandfoundation/nodekit/ui/style"
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/log"
Expand Down Expand Up @@ -30,12 +32,19 @@ var upgradeLong = lipgloss.JoinVertical(

// upgradeCmd is a Cobra command used to upgrade Algod, utilizing the OS-specific package manager if applicable.
var upgradeCmd = &cobra.Command{
Use: "upgrade",
Short: upgradeShort,
Long: upgradeLong,
SilenceUsage: true,
PersistentPreRun: NeedsToBeStopped,
Use: "upgrade",
Short: upgradeShort,
Long: upgradeLong,
SilenceUsage: true,
Run: func(cmd *cobra.Command, args []string) {
if NeedsUpgrade {
log.Info(style.Green.Render("Upgrading NodeKit"))
err := system.Upgrade(new(api.HttpPkg))
if err != nil {
log.Fatal(err)
}
}

// TODO: get expected version and check if update is required
log.Info(style.Green.Render(UpgradeMsg))
// Warn user for prompt
Expand Down
1 change: 1 addition & 0 deletions docs/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v20.11.0
Loading

0 comments on commit f4a7254

Please sign in to comment.