Skip to content

Commit

Permalink
Cleaning up the code, adding lint and build workflows, adding makefil…
Browse files Browse the repository at this point in the history
…es for build, lint, and test.

Signed-off-by: ytimocin <ytimocin@microsoft.com>
  • Loading branch information
ytimocin committed Jan 4, 2025
1 parent 5414b0c commit 7e0f856
Show file tree
Hide file tree
Showing 20 changed files with 133 additions and 193 deletions.
2 changes: 1 addition & 1 deletion .github/scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ARCH=$(uname -m)

if [[ "$ARCH" == "x86_64" ]]; then
ARCH="amd64"
elif [[ "$ARCH" == "aarch64" ]]; then
elif [[ "$ARCH" == "arm64" || "$ARCH" == "aarch64" ]]; then
ARCH="arm64"
else
echo "Unsupported architecture: $ARCH"
Expand Down
61 changes: 61 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Build

on:
push:
branches:
- main
- release/*
tags:
- "v*.*.*"
pull_request:
branches:
- main
- release/*

permissions:
contents: write

jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
goos: [linux, darwin, windows]
goarch: [amd64, arm64]

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.22
cache: false

- name: Install dependencies
run: go mod tidy

- name: Run tests
run: go test -v ./...

- name: Build binaries
run: |
echo "Building for GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }}"
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} \
make build
- name: Rename Windows binaries with .exe
if: matrix.goos == 'windows'
run: mv dist/pops-windows-${{ matrix.goarch }} dist/pops-windows-${{ matrix.goarch }}.exe

- name: Validate binary
run: |
file dist/pops-${{ matrix.goos }}-${{ matrix.goarch }}*
- name: Upload binaries as artifact
uses: actions/upload-artifact@v4
with:
name: pops-${{ matrix.goos }}-${{ matrix.goarch }}
path: dist/*
18 changes: 9 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ jobs:
- name: Install dependencies
run: go mod tidy

- name: Create dist directory
run: mkdir -p dist
- name: Run tests
run: go test -v ./...

- name: Build binaries
run: |
echo "Building for GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }}"
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} CGO_ENABLED=0 GO111MODULE=on \
go build -ldflags="-s -w" -o dist/pops-${{ matrix.goos }}-${{ matrix.goarch }}
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} \
make build
- name: Rename Windows binaries with .exe
if: matrix.goos == 'windows'
Expand All @@ -51,7 +51,7 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: pops-${{ matrix.goos }}-${{ matrix.goarch }}
path: dist/
path: dist/pops-${{ matrix.goos }}-${{ matrix.goarch }}*

release:
runs-on: ubuntu-latest
Expand All @@ -64,11 +64,11 @@ jobs:
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
path: release
path: dist/
pattern: pops-*

- name: List release folder
run: ls -R release
- name: List dist folder
run: ls -R dist/

- name: Create GitHub Release
id: create_release
Expand All @@ -77,6 +77,6 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
repository: prompt-ops/pops
files: release/*
files: dist/pops-*
draft: false
prerelease: false
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ Thumbs.db

# `pops` binary
pops

# dist directory
dist/
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Include all make files in the make directory
include $(wildcard make/*.mk)
3 changes: 2 additions & 1 deletion ai/ai.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,11 @@ func parseResponse(response string) (ParsedResponse, error) {
// parseSuggestions extracts the suggestions from the response.
func parseSuggestions(lines []string) []string {
var suggestions []string
re := regexp.MustCompile(`^\d+\.\s+`)
for _, line := range lines {
line = strings.TrimSpace(line)
// Match numbered suggestions (e.g., "1. Describe one of the pods")
if matched, _ := regexp.MatchString(`^\d+\.\s+`, line); matched {
if matched := re.MatchString(line); matched {
suggestions = append(suggestions, line)
}
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/connection/cloud/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ func (m *createModel) Init() tea.Cmd {
}

func (m *createModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg.(type) {
switch msg := msg.(type) {
case ui.TransitionToShellMsg:
shellModel := ui.NewShellModel(msg.(ui.TransitionToShellMsg).Connection)
shellModel := ui.NewShellModel(msg.Connection)
m.current = shellModel
return m, shellModel.Init()
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/connection/cloud/open.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ func (m *openModel) Init() tea.Cmd {
}

func (m *openModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg.(type) {
switch msg := msg.(type) {
case ui.TransitionToShellMsg:
m.current = ui.NewShellModel(msg.(ui.TransitionToShellMsg).Connection)
m.current = ui.NewShellModel(msg.Connection)
return m, m.current.Init()
}
var cmd tea.Cmd
Expand Down
4 changes: 2 additions & 2 deletions cmd/connection/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ func (m *createModel) Init() tea.Cmd {
func (m *createModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch m.currentStep {
case createStepTypeSelection:
switch msg.(type) {
switch msg := msg.(type) {
case ui.TransitionToCreateMsg:
fmt.Println("Transitioning to create")
connectionType := msg.(ui.TransitionToCreateMsg).ConnectionType
connectionType := msg.ConnectionType
createModel, err := factory.GetCreateModel(connectionType)
if err != nil {
return m, tea.Quit
Expand Down
4 changes: 2 additions & 2 deletions cmd/connection/db/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ func (m *createModel) Init() tea.Cmd {
}

func (m *createModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg.(type) {
switch msg := msg.(type) {
case ui.TransitionToShellMsg:
shellModel := ui.NewShellModel(msg.(ui.TransitionToShellMsg).Connection)
shellModel := ui.NewShellModel(msg.Connection)
m.current = shellModel
return m, shellModel.Init()
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/connection/db/open.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ func (m *openModel) Init() tea.Cmd {
}

func (m *openModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg.(type) {
switch msg := msg.(type) {
case ui.TransitionToShellMsg:
m.current = ui.NewShellModel(msg.(ui.TransitionToShellMsg).Connection)
m.current = ui.NewShellModel(msg.Connection)
return m, m.current.Init()
}
var cmd tea.Cmd
Expand Down
164 changes: 0 additions & 164 deletions cmd/connection/kubernetes/ai.go

This file was deleted.

4 changes: 2 additions & 2 deletions cmd/connection/kubernetes/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ func (m *createModel) Init() tea.Cmd {
}

func (m *createModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg.(type) {
switch msg := msg.(type) {
case ui.TransitionToShellMsg:
shellModel := ui.NewShellModel(msg.(ui.TransitionToShellMsg).Connection)
shellModel := ui.NewShellModel(msg.Connection)
return shellModel, shellModel.Init()
}
var cmd tea.Cmd
Expand Down
4 changes: 2 additions & 2 deletions cmd/connection/kubernetes/open.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ func (m *openModel) Init() tea.Cmd {
}

func (m *openModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg.(type) {
switch msg := msg.(type) {
case ui.TransitionToShellMsg:
m.current = ui.NewShellModel(msg.(ui.TransitionToShellMsg).Connection)
m.current = ui.NewShellModel(msg.Connection)
return m, m.current.Init()
}
var cmd tea.Cmd
Expand Down
Loading

0 comments on commit 7e0f856

Please sign in to comment.