Skip to content

Commit

Permalink
Merge pull request #2 from janpreet/refator
Browse files Browse the repository at this point in the history
Refactored code
  • Loading branch information
janpreet authored Aug 2, 2024
2 parents 9a04259 + 786868f commit 4dd75af
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 59 deletions.
131 changes: 86 additions & 45 deletions .github/workflows/docker-release.yaml
Original file line number Diff line number Diff line change
@@ -1,61 +1,102 @@
name: Build, Docker, and Release

on:
push:
branches:
- main
- 'feature/*'
- 'fix/*'

env:
VERSION_FILE: VERSION
DOCKER_IMAGE: ghcr.io/${{ github.repository }}

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
goos: [linux, windows, darwin]
goarch: [amd64, arm64]
exclude:
- goos: windows
goarch: arm64
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.22.x'

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Log in to GitHub Container Registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin

- name: Bump version
run: make version-bump

- name: Read version
id: version
run: echo "::set-output name=version::$(cat $(VERSION_FILE))"

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

- name: Build for ${{ matrix.goos }}-${{ matrix.goarch }}
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
run: |
go build -o kado-${{ matrix.goos }}-${{ matrix.goarch }}
if [ "${{ matrix.goos }}" = "windows" ]; then
mv kado-${{ matrix.goos }}-${{ matrix.goarch }} kado-${{ matrix.goos }}-${{ matrix.goarch }}.exe
fi
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: kado-${{ matrix.goos }}-${{ matrix.goarch }}
path: kado-${{ matrix.goos }}-${{ matrix.goarch }}*

docker:
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.22.x'

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Log in to GitHub Container Registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin

- name: Bump version
run: make version-bump

- name: Read version
id: version
run: echo "::set-output name=version::$(cat $(VERSION_FILE))"

- name: Run tests
run: |
go test ./...
- name: Build Docker image
run: make docker-build

- name: Push Docker image to GitHub Packages
run: |
docker push ${{ env.DOCKER_IMAGE }}:latest
#docker push ${{ env.DOCKER_IMAGE }}:${{ steps.version.outputs.version }}
- name: Create GitHub release
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ steps.version.outputs.version }}
name: Release ${{ steps.version.outputs.version }}
files: kado
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout repository
uses: actions/checkout@v2

- name: Build Docker image
run: make docker-build

- name: Push Docker image to GitHub Packages
run: |
docker push ${{ env.DOCKER_IMAGE }}:latest
#docker push ${{ env.DOCKER_IMAGE }}:${{ steps.version.outputs.version }}
release:
needs: [build, docker]
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Download all artifacts
uses: actions/download-artifact@v2

- name: Create GitHub release
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ steps.version.outputs.version }}
name: Release ${{ steps.version.outputs.version }}
files: |
kado-linux-amd64
kado-linux-arm64
kado-windows-amd64.exe
kado-darwin-amd64
kado-darwin-arm64
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41 changes: 27 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
# Makefile

# Variables
BINARY_NAME = kado
VERSION_FILE = VERSION
PYTHON_SCRIPT = bump_version.py
VERSION := $(shell cat $(VERSION_FILE))

# Define your GitHub username and repository name
GITHUB_USERNAME = janpreet
GITHUB_REPOSITORY = kado
DOCKER_IMAGE = ghcr.io/janpreet/kado

# Build the binary
GOARCHES = amd64 arm64

build-all:
@for os in $(GOOSES); do \
for arch in $(GOARCHES); do \
if [ "$$os" != "windows" ] || [ "$$arch" != "arm64" ]; then \
echo "Building for $$os/$$arch"; \
GOOS=$$os GOARCH=$$arch go build -o $(BINARY_NAME)-$$os-$$arch$(if $(filter windows,$$os),.exe,) .; \
fi; \
done; \
done

build:
GOOS=linux GOARCH=amd64 go build -o $(BINARY_NAME) main.go
go build -o $(BINARY_NAME) .

# Build the Docker image
docker-build: build
docker build -t $(DOCKER_IMAGE):latest -t $(DOCKER_IMAGE):$(VERSION) .

# Push the Docker image to GitHub Packages
docker-push:
docker push $(DOCKER_IMAGE):latest
docker push $(DOCKER_IMAGE):$(VERSION)

# Bump version, tag, and push
version-bump:
python3 $(PYTHON_SCRIPT)

Expand All @@ -34,9 +37,19 @@ tag-and-push: version-bump
git tag v$(VERSION)
git push origin main --tags

# Clean up the build
clean:
rm -f $(BINARY_NAME)
rm -f $(BINARY_NAME)*

test:
go test ./...

all: clean build-all docker-build docker-push tag-and-push

github-release:
@echo "Creating GitHub release for v$(VERSION)"
@gh release create v$(VERSION) \
--title "Release $(VERSION)" \
--notes "Release notes for version $(VERSION)" \
$(BINARY_NAME)-*

# Default target
all: clean build docker-build docker-push tag-and-push
.PHONY: build-all build docker-build docker-push version-bump tag-and-push clean test all github-release
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ bead "terragrunt" {
- `kado fmt [dir]`: Formats `.kd` files in the specified directory.
- `kado ai`: Runs AI-based recommendations if enabled in the `~/.kdconfig` configuration.
- `kado config`: Displays the current configuration and order of execution.
- `kado -debug`: Runs Kado with debug output enabled, providing detailed information about the execution process.

### Getting Started

Expand Down

0 comments on commit 4dd75af

Please sign in to comment.