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 5601605
Show file tree
Hide file tree
Showing 20 changed files with 159 additions and 188 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
89 changes: 89 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: Build

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

permissions:
contents: write

env:
CONTAINER_REGISTRY: ghcr.io/prompt-ops/pops

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: Run lint
run: make lint

- 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/

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- uses: oras-project/setup-oras@v1
- run: oras version

- name: Push latest rad cli binary to GHCR (unix-like)
if: matrix.goos != 'windows'
run: |
cp ./dist/pops-${{ matrix.goos }}-${{ matrix.goarch }} ./pops
oras push ${{ env.CONTAINER_REGISTRY }}/pops/${{ matrix.goos }}-${{ matrix.goarch }}:latest ./pops
- name: Copy cli binaries to release (windows)
if: matrix.goos == 'windows'
run: |
cp ./dist/pops-${{ matrix.goos }}-${{ matrix.goarch }} ./pops.exe
oras push ${{ env.CONTAINER_REGISTRY }}/pops/${{ matrix.goos }}-${{ matrix.goarch }}:latest ./pops.exe
11 changes: 7 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,17 @@ jobs:
- name: Install dependencies
run: go mod tidy

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

- name: Run lint
run: make lint

- 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 Down
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 5601605

Please sign in to comment.