Skip to content

Commit

Permalink
Beta Release (#7)
Browse files Browse the repository at this point in the history
* add version cmd, ignore bin dir

* add init command, embed all config, started on binary download

* output path for downloaded binaries ignored

* working downloading and file extraction

* added mprocs config as a stop gap, readme

* small readme updates, skip download if bin already present

* use localized data dir for sequencer and cometbft data

* added run command, renamed bin to astria-dev

* readme updates, run cmd init checking print improvements

* typo fix

* readme updates

* revert module naming

* reorg of commands to be sub commands of dev

* move embedded files to config dir

* status prints added to embedded file recreation

* conditional compilation for different os and arch

* removed just and mprocs deps

* add run check for rollup rpc port for composer

* small error print and readme updates

* cleanup of initialize check, added linux support

* add fmt to justfile

* default dir changed to ~/.astria

* env cleanup

* force stdout for sequencer

* initial tview ui

* add default just command

* added running cometbft to tview ui

* added conductor and composer to tview ui

* cmd definitions moved outside of go routines to allow for sigint capture

* removed sleeps, added channel waits

* added clean cmd for removing local cometbft and sequencer data

* added clear all command

* added word wrap and removal of ansi escape characters view toggle

* remove testing text color print

* ansi escape character now parsed

* cleanup and comment updates

* added basic help bar at bottom

* added ability to select app and jump in and out of fullscreen

* prevent focus change when in fullscreen

* typo fixes

* update just commands

* readme updates, disable completion command

* small readme update, added fullscreen specific help bar

* added arrow key and mouse scrolling to fullscreen view

* updates to autoscroll setting, add stderr capture to sequencer

* cleaned up appendText function, updated justfile to capture tview logs, added pskill command to justfile

* add stderr capture to output

* justfile comments

* App and ProcessRunner structs

* todo

* settings status display updated, added basic help page

* filled out main help page

* action keys are no longer case sensitive

* added more to help window

* added boarderless logs option

* fixed border typo

* comment

* slight reorg. comments.

* refactor processrunner. contexts.

* getters

* SetInputCapture, stop, word wrap

* keyboard shortcuts for selecting panes, fullscreen, exit

* comment

* more clear pattern for ui state

* autoscroll and notes

* comments. cruft.

* words

* add command for sequencer create account (#6)

* add command for sequencer create account

* name devtools package

* move error handling to command code. test.

* descriptions and comment cleanup.

* justfile help docstrings. test command.

* remove autocorrect fail

* add github action to test go code

* remove cruft

* Feature: gh actions (#2)

* gh actions

* fix github actions

* fix package name

* Feat/adds tests (#9)

* add "t" as alias for "test" in justfile

* refactor to be more testable. ProcessRunner interface and mock.

* "pscheck" just command to check for leftover astria processes

* more tests

* merge main

* cleanup func. doc comment.

* move version to root of cmd

* reorganize clean command

* naming conventions

* Relocate Cometbft Initialization (#10)

* moved cometbft setup from run cmd to init cmd

* fmt.Println formating fix

* added borderless logs toggle when in full screen

* added borderless logs toggle when in full screen (#16)

---------

Co-authored-by: Sam Bukowski <[email protected]>
  • Loading branch information
steezeburger and sambukowski authored Mar 26, 2024
1 parent 600e8ff commit c65c3ed
Show file tree
Hide file tree
Showing 29 changed files with 1,756 additions and 288 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/project.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Project

on:
issues:
types:
- opened

jobs:
add-to-project:
name: Add new issues
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
with:
project-url: https://github.com/orgs/astriaorg/projects/1
github-token: ${{ secrets.ASTRIA_PROJECT_TOKEN }}
28 changes: 28 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
on:
release:
types: [created]

permissions:
contents: write
packages: write

jobs:
releases-matrix:
name: Release Go Binary
runs-on: ubuntu-latest
strategy:
matrix:
goos: [linux, darwin]
goarch: [amd64, arm64]
exclude:
- goarch: "arm64"
goos: "linux"
steps:
- uses: actions/checkout@v4
- uses: wangyoucao577/go-release-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
goos: ${{ matrix.goos }}
goarch: ${{ matrix.goarch }}
project_path: "./"
binary_name: "astria-cli"
20 changes: 20 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Test

on:
pull_request:
push:
branches:
- "main"

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Use Go 1.21.3
uses: actions/setup-go@v4
with:
go-version: 1.21.3
cache-dependency-path: ./go.sum
- name: Test
run: go test ./...
50 changes: 0 additions & 50 deletions cmd/devtools/all.go

This file was deleted.

2 changes: 1 addition & 1 deletion cmd/devtools/binaries_config_darwin_amd64.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//go:build darwin && amd64

package cmd
package devtools

// Your code here
type Binary struct {
Expand Down
2 changes: 1 addition & 1 deletion cmd/devtools/binaries_config_darwin_arm64.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//go:build darwin && arm64

package cmd
package devtools

// Your code here
type Binary struct {
Expand Down
2 changes: 1 addition & 1 deletion cmd/devtools/binaries_config_linux_amd64.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//go:build linux && amd64

package cmd
package devtools

// Your code here
type Binary struct {
Expand Down
39 changes: 29 additions & 10 deletions cmd/devtools/clean.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cmd
package devtools

import (
"fmt"
Expand Down Expand Up @@ -39,16 +39,35 @@ func runClean() {
}
}

func init() {
devCmd.AddCommand(cleanCmd)
var allCmd = &cobra.Command{
Use: "all",
Short: "Clean all local data including binaries and config files.",
Long: "Clean all local data including binaries and config files. `dev init` will need to be run again to get the binaries and config files back.",
Run: func(cmd *cobra.Command, args []string) {
runCleanAll()
},
}

// Here you will define your flags and configuration settings.
func runCleanAll() {
homePath, err := os.UserHomeDir()
if err != nil {
fmt.Println("error getting home dir:", err)
return
}

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// cleanCmd.PersistentFlags().String("foo", "", "A help for foo")
// TODO: allow for configuration of this directory
defaultDataDir := filepath.Join(homePath, ".astria")

cleanCmd := exec.Command("rm", "-rf", defaultDataDir)
if err := cleanCmd.Run(); err != nil {
panic(err)
}
}

func init() {
// top level command
devCmd.AddCommand(cleanCmd)

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// cleanCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
// subcommands
cleanCmd.AddCommand(allCmd)
}
5 changes: 3 additions & 2 deletions cmd/devtools/dev.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package cmd
package devtools

import (
"fmt"

"github.com/astria/astria-cli-go/cmd"
"github.com/spf13/cobra"
)

Expand All @@ -20,7 +21,7 @@ var devCmd = &cobra.Command{
// TODO: add a func here to print out an explanation for how to use the dev command

func init() {
rootCmd.AddCommand(devCmd)
cmd.RootCmd.AddCommand(devCmd)

// Here you will define your flags and configuration settings.

Expand Down
108 changes: 106 additions & 2 deletions cmd/devtools/init.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cmd
package devtools

import (
"archive/tar"
Expand All @@ -10,6 +10,7 @@ import (
"log"
"net/http"
"os"
"os/exec"
"path/filepath"
"strings"

Expand Down Expand Up @@ -48,10 +49,11 @@ func runInitialization() {
recreateCometbftAndSequencerGenesisData(fullPath)

for _, bin := range Binaries {

downloadAndUnpack(bin.Url, fullPath, bin.Name)
}

initCometbft(defaultDir)

}

//go:embed config/genesis.json
Expand Down Expand Up @@ -254,6 +256,108 @@ func downloadAndUnpack(url string, placePath string, packageName string) {
fmt.Printf("%s downloaded and extracted successfully.\n", packageName)
}

func initCometbft(defaultDir string) {
fmt.Println("Initializing CometBFT:")
cometbftDataPath := filepath.Join(defaultDir, "data/.cometbft")

// verify that cometbft was downloaded and extracted to the correct location
cometbftBin := filepath.Join(defaultDir, "local-dev-astria/cometbft")
if !exists(cometbftBin) {
fmt.Println("Error: cometbft binary not found here", cometbftBin)
fmt.Println("\tCannot continue with initialization.")
return
}

cometbftCmdPath := filepath.Join(defaultDir, "local-dev-astria/cometbft")

initCmdArgs := []string{"init", "--home", cometbftDataPath}
initCmd := exec.Command(cometbftCmdPath, initCmdArgs...)

fmt.Println("Running:", initCmd)

_, err := initCmd.CombinedOutput()
if err != nil {
fmt.Println("Error executing command", initCmd, ":", err)
return
} else {
fmt.Println("\tSuccess")
}

// create the comand to replace the defualt genesis.json with the
// configured one
initGenesisJsonPath := filepath.Join(defaultDir, "local-dev-astria/genesis.json")
endGenesisJsonPath := filepath.Join(defaultDir, "data/.cometbft/config/genesis.json")
copyArgs := []string{initGenesisJsonPath, endGenesisJsonPath}
copyCmd := exec.Command("cp", copyArgs...)

_, err = copyCmd.CombinedOutput()
if err != nil {
fmt.Println("Error executing command", copyCmd, ":", err)
return
}
fmt.Println("Copied genesis.json to", endGenesisJsonPath)

// create the comand to replace the defualt priv_validator_key.json with the
// configured one
initPrivValidatorJsonPath := filepath.Join(defaultDir, "local-dev-astria/priv_validator_key.json")
endPrivValidatorJsonPath := filepath.Join(defaultDir, "data/.cometbft/config/priv_validator_key.json")
copyArgs = []string{initPrivValidatorJsonPath, endPrivValidatorJsonPath}
copyCmd = exec.Command("cp", copyArgs...)

_, err = copyCmd.CombinedOutput()
if err != nil {
fmt.Println("Error executing command", copyCmd, ":", err)
return
}
fmt.Println("Copied priv_validator_key.json to", endPrivValidatorJsonPath)

// update the cometbft config.toml file to have the proper block time
cometbftConfigPath := filepath.Join(defaultDir, "data/.cometbft/config/config.toml")
oldValue := `timeout_commit = "1s"`
newValue := `timeout_commit = "2s"`

if err := replaceInFile(cometbftConfigPath, oldValue, newValue); err != nil {
fmt.Println("Error updating the file:", cometbftConfigPath, ":", err)
return
} else {
fmt.Println("Successfully updated", cometbftConfigPath)
}
}

// replaceInFile replaces oldValue with newValue in the file at filename.
// it is used here to update the block time in the cometbft config.toml file.
func replaceInFile(filename, oldValue, newValue string) error {
// Read the original file.
content, err := os.ReadFile(filename)
if err != nil {
return fmt.Errorf("failed to read the file: %w", err)
}

// Perform the replacement.
modifiedContent := strings.ReplaceAll(string(content), oldValue, newValue)

// Write the modified content to a new temporary file.
tmpFilename := filename + ".tmp"
if err := os.WriteFile(tmpFilename, []byte(modifiedContent), 0666); err != nil {
return fmt.Errorf("failed to write to temporary file: %w", err)
}

// Rename the original file to filename.bak.
backupFilename := filename + ".bak"
if err := os.Rename(filename, backupFilename); err != nil {
return fmt.Errorf("failed to rename original file to backup: %w", err)
}

// Rename the temporary file to the original file name.
if err := os.Rename(tmpFilename, filename); err != nil {
// Attempt to restore the original file if renaming fails.
os.Rename(backupFilename, filename)
return fmt.Errorf("failed to rename temporary file to original: %w", err)
}

return nil
}

func init() {
devCmd.AddCommand(initCmd)

Expand Down
41 changes: 0 additions & 41 deletions cmd/devtools/root.go

This file was deleted.

Loading

0 comments on commit c65c3ed

Please sign in to comment.