Skip to content

Commit

Permalink
A new start
Browse files Browse the repository at this point in the history
  • Loading branch information
sammcj committed Jun 1, 2024
0 parents commit 0cc2d8c
Show file tree
Hide file tree
Showing 21 changed files with 1,770 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[Makefile]
indent_style = tab
indent_size = 8
83 changes: 83 additions & 0 deletions .github/workflows/build-and-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Build and release
on:
workflow_dispatch:
push:
branches:
- main
- dev
- ".github/workflows/build-and-release.yml"
tags:
- v*
pull_request:
branches:
- main

permissions:
contents: write
checks: write
pull-requests: write
packages: write

concurrency:
group: build-and-release
cancel-in-progress: true

jobs:
build-and-release:
timeout-minutes: 15
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4
- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5
with:
go-version: 1.22.1

# Install dependencies
- name: Install dependencies
run: go mod download

# Build
- name: Build
shell: bash
run: |
set -x
make ci
echo "🎉 Builds completed" >> "$GITHUB_STEP_SUMMARY"
- name: Upload artefacts
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4
with:
name: gollama
path: |
dist/macos/gollama
dist/linux_amd64/gollama
dist/linux_arm64/gollama
# Bump version
- name: Bump version and push tag
id: tag_version
if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads/main') && !contains(github.event.head_commit.message, '[skip ci]')
uses: mathieudutour/github-tag-action@a22cf08638b34d5badda920f9daf6e72c477b07b # v6.2
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
release_branches: main
pre_release_branches: dev

# Publish
- name: Create a GitHub release
uses: ncipollo/release-action@2c591bcc8ecdcd2db72b97d6147f871fcd833ba5 # v1
if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads/main') && !contains(github.event.head_commit.message, '[skip ci]')
with:
tag: ${{ steps.tag_version.outputs.new_tag }}
name: Release ${{ steps.tag_version.outputs.new_tag }}
body: ${{ steps.tag_version.outputs.changelog }}
generateReleaseNotes: true
allowUpdates: true
prerelease: ${{ startsWith(github.ref, 'refs/heads/dev') }}
draft: ${{ startsWith(github.ref, 'refs/heads/dev') }}
artifacts: |
dist/macos/gollama
dist/linux_amd64/gollama
dist/linux_arm64/gollama
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
gollama
**/.swp
**/.tmp
**/.trash
**/*.log
dist/
.selected*
dist/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Sam McLeod

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
67 changes: 67 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#### Dynamically Generated Interactive Menu ####

# Error Handling
SHELL := /bin/bash
.SHELLFLAGS := -o pipefail -c

# Name of this Makefile
MAKEFILE_NAME := $(lastword $(MAKEFILE_LIST))

# Special targets that should not be listed
EXCLUDE_LIST := menu all .PHONY

# Function to extract targets from the Makefile
define extract_targets
$(shell awk -F: '/^[a-zA-Z0-9_-]+:/ {print $$1}' $(MAKEFILE_NAME) | grep -v -E '^($(EXCLUDE_LIST))$$')
endef

TARGETS := $(call extract_targets)

.PHONY: $(TARGETS) menu all

menu: ## Makefile Interactive Menu
@# Check if fzf is installed
@if command -v fzf >/dev/null 2>&1; then \
echo "Using fzf for selection..."; \
echo "$(TARGETS)" | tr ' ' '\n' | fzf > .selected_target; \
target_choice=$$(cat .selected_target); \
else \
echo "fzf not found, using numbered menu:"; \
echo "$(TARGETS)" | tr ' ' '\n' > .targets; \
awk '{print NR " - " $$0}' .targets; \
read -p "Enter choice: " choice; \
target_choice=$$(awk 'NR == '$$choice' {print}' .targets); \
fi; \
if [ -n "$$target_choice" ]; then \
$(MAKE) $$target_choice; \
else \
echo "Invalid choice"; \
fi

# Default target
all: menu

help: ## This help function
@egrep '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'

# Targets (example targets listed below)
lint: ## Run lint
gofmt -w .
find . -type f -name "*.go" -exec sed -i '' 's/\t/ /g' {} +

test: ## Run test
go test -v ./...

build: ## Run build
go build .
echo "Build completed, run ./gollama"

ci: ## build for linux and macOS
mkdir -p ./dist/macos ./dist/linux_amd64 ./dist/linux_arm64
GOOS=darwin GOARCH=arm64 go build . -o ./dist/macos/gollama
GOOS=linux GOARCH=amd64 go build . -o ./dist/linux_amd64/gollama
GOOS=linux GOARCH=arm64 go build . -o ./dist/linux_arm64/gollama
echo "Build completed, run ./dist/macos/gollama or ./dist/linux_amd64/gollama or ./dist/linux_arm64/gollama"

run: ## Run
go run *.go
Loading

0 comments on commit 0cc2d8c

Please sign in to comment.