Skip to content

Commit

Permalink
Prepare for release
Browse files Browse the repository at this point in the history
  • Loading branch information
canack committed Jan 2, 2024
1 parent 80e52fa commit 8983c67
Show file tree
Hide file tree
Showing 20 changed files with 248 additions and 205 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Build and Release

on:
push:
tags:
- 'v*'

jobs:
build_and_release:
name: Build for Multiple Platforms and Create Release
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: '1.21'

- name: Build for Linux, Windows, macOS
run: |
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="-s -w" -o release/gama-linux-amd64 cmd/main.go
GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="-s -w" -o release/gama-windows-amd64.exe cmd/main.go
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="-s -w" -o release/gama-macos-amd64 cmd/main.go
GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 go build -ldflags="-s -w" -o release/gama-macos-arm64 cmd/main.go
- name: Create Release
uses: ncipollo/release-action@v1
with:
artifacts: "release/gama-linux-amd64,release/gama-windows-amd64.exe,release/gama-macos-amd64,release/gama-macos-arm64"
token: ${{ secrets.GITHUB_TOKEN }}
draft: true
17 changes: 6 additions & 11 deletions cmd/gama/main.go → cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
package main

import (
"context"
"fmt"
"os"

tea "github.com/charmbracelet/bubbletea"
gr "github.com/termkit/gama/internal/github/repository"
gu "github.com/termkit/gama/internal/github/usecase"
su "github.com/termkit/gama/internal/setup/usecase"
th "github.com/termkit/gama/internal/terminal/handler"
pkgconfig "github.com/termkit/gama/pkg/config"
)

func main() {
var ctx = context.Background()

githubRepository := gr.New()
githubRepository.Initialize(ctx, gr.GithubConfig{Token: os.Getenv("GITHUB_TOKEN")})

setupUseCase := su.New(githubRepository)

if err := setupUseCase.Setup(ctx); err != nil {
panic(fmt.Sprintf("failed to setup gama: %v", err))
cfg, err := pkgconfig.LoadConfig()
if err != nil {
panic(fmt.Sprintf("failed to load config: %v", err))
}

githubRepository := gr.New(cfg)

githubUseCase := gu.New(githubRepository)

terminal := th.SetupTerminal(githubUseCase)
Expand Down
3 changes: 1 addition & 2 deletions internal/github/repository/ports.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
)

type Repository interface {
Initialize(ctx context.Context, config GithubConfig, opts ...InitializeOptions)
TestConnection(ctx context.Context) error
ListRepositories(ctx context.Context) ([]GithubRepository, error)
GetRepository(ctx context.Context, repository string) (*GithubRepository, error)
Expand All @@ -14,7 +13,7 @@ type Repository interface {
TriggerWorkflow(ctx context.Context, repository string, branch string, workflowName string, workflow any) error
GetWorkflows(ctx context.Context, repository string) ([]Workflow, error)
GetTriggerableWorkflows(ctx context.Context, repository string) ([]Workflow, error)
InspectWorkflowContent(ctx context.Context, repository string, workflowFile string) ([]byte, error)
InspectWorkflowContent(ctx context.Context, repository string, branch string, workflowFile string) ([]byte, error)
GetWorkflowRunLogs(ctx context.Context, repository string, runId int64) (GithubWorkflowRunLogs, error)
ReRunFailedJobs(ctx context.Context, repository string, runId int64) error
ReRunWorkflow(ctx context.Context, repository string, runId int64) error
Expand Down
13 changes: 7 additions & 6 deletions internal/github/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"strconv"
"time"

pkgconfig "github.com/termkit/gama/pkg/config"
"gopkg.in/yaml.v3"
)

Expand All @@ -23,18 +24,15 @@ type Repo struct {

var githubAPIURL = "https://api.github.com"

func New() *Repo {
func New(cfg *pkgconfig.Config) *Repo {
return &Repo{
Client: &http.Client{
Timeout: 20 * time.Second,
},
githubToken: cfg.Github.Token,
}
}

func (r *Repo) Initialize(ctx context.Context, config GithubConfig, opts ...InitializeOptions) {
r.githubToken = config.Token
}

func (r *Repo) TestConnection(ctx context.Context) error {
// List repositories for the authenticated user
var repositories []GithubRepository
Expand Down Expand Up @@ -191,13 +189,16 @@ func (r *Repo) GetTriggerableWorkflows(ctx context.Context, repository string) (
return triggerableWorkflows, nil
}

func (r *Repo) InspectWorkflowContent(ctx context.Context, repository string, workflowFile string) ([]byte, error) {
func (r *Repo) InspectWorkflowContent(ctx context.Context, repository string, branch string, workflowFile string) ([]byte, error) {
// Get the content of the workflow file
var githubFile githubFile
err := r.do(ctx, nil, &githubFile, requestOptions{
method: http.MethodGet,
path: githubAPIURL + "/repos/" + repository + "/contents/" + workflowFile,
contentType: "application/vnd.github.VERSION.raw",
queryParams: map[string]string{
"ref": branch,
},
})
if err != nil {
return nil, err
Expand Down
10 changes: 7 additions & 3 deletions internal/github/repository/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ package repository

import (
"context"
"os"
"testing"

pkgconfig "github.com/termkit/gama/pkg/config"
)

func newRepo(ctx context.Context) *Repo {
repo := New()
cfg, err := pkgconfig.LoadConfig()
if err != nil {
panic(err)
}

repo.Initialize(ctx, GithubConfig{Token: os.Getenv("GITHUB_TOKEN")})
repo := New(cfg)
return repo
}

Expand Down
2 changes: 1 addition & 1 deletion internal/github/usecase/usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (u useCase) GetTriggerableWorkflows(ctx context.Context, input GetTriggerab
}

func (u useCase) InspectWorkflow(ctx context.Context, input InspectWorkflowInput) (*InspectWorkflowOutput, error) {
workflowData, err := u.githubRepository.InspectWorkflowContent(ctx, input.Repository, input.WorkflowFile)
workflowData, err := u.githubRepository.InspectWorkflowContent(ctx, input.Repository, input.Branch, input.WorkflowFile)
if err != nil {
return nil, err
}
Expand Down
23 changes: 16 additions & 7 deletions internal/github/usecase/usecase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@ package usecase

import (
"context"
"os"
"testing"

"github.com/termkit/gama/internal/github/repository"
pkgconfig "github.com/termkit/gama/pkg/config"
)

func TestUseCase_ListRepositories(t *testing.T) {
ctx := context.Background()
cfg, err := pkgconfig.LoadConfig()
if err != nil {
t.Fatal(err)
}

githubRepo := repository.New()
githubRepo.Initialize(ctx, repository.GithubConfig{Token: os.Getenv("GITHUB_TOKEN")})
githubRepo := repository.New(cfg)

githubUseCase := New(githubRepo)

Expand All @@ -25,9 +28,12 @@ func TestUseCase_ListRepositories(t *testing.T) {

func TestUseCase_InspectWorkflow(t *testing.T) {
ctx := context.Background()
cfg, err := pkgconfig.LoadConfig()
if err != nil {
t.Fatal(err)
}

githubRepo := repository.New()
githubRepo.Initialize(ctx, repository.GithubConfig{Token: os.Getenv("GITHUB_TOKEN")})
githubRepo := repository.New(cfg)

githubUseCase := New(githubRepo)

Expand All @@ -43,9 +49,12 @@ func TestUseCase_InspectWorkflow(t *testing.T) {

func TestUseCase_TriggerWorkflow(t *testing.T) {
ctx := context.Background()
cfg, err := pkgconfig.LoadConfig()
if err != nil {
t.Fatal(err)
}

githubRepo := repository.New()
githubRepo.Initialize(ctx, repository.GithubConfig{Token: os.Getenv("GITHUB_TOKEN")})
githubRepo := repository.New(cfg)

githubUseCase := New(githubRepo)

Expand Down
10 changes: 0 additions & 10 deletions internal/setup/repository/ports.go

This file was deleted.

22 changes: 0 additions & 22 deletions internal/setup/repository/repository.go

This file was deleted.

9 changes: 0 additions & 9 deletions internal/setup/repository/types.go

This file was deleted.

9 changes: 0 additions & 9 deletions internal/setup/usecase/ports.go

This file was deleted.

49 changes: 0 additions & 49 deletions internal/setup/usecase/usecase.go

This file was deleted.

Loading

0 comments on commit 8983c67

Please sign in to comment.