Skip to content

Commit

Permalink
🎉 initial source: add project #1
Browse files Browse the repository at this point in the history
  • Loading branch information
pnguyen215 committed Jan 21, 2025
0 parents commit fec04bf
Show file tree
Hide file tree
Showing 15 changed files with 870 additions and 0 deletions.
80 changes: 80 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: Go

on:
push:
branches: ["master"]
tags:
- "v*"
pull_request:
branches: ["master"]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
# Add Go versions as needed
go: ["1.21.x", "1.23.x"] # previous version "1.19", "1.20.x"
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go }}

- name: Build
run: go build -v ./...

- name: Test
run: go test -v ./...

create-release:
runs-on: ubuntu-latest
# Only run this job when a valid tag is pushed
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Check if tag exists
id: check_tag
run: |
if [ -n "$GITHUB_REF" ]; then
TAG=${GITHUB_REF#refs/tags/}
# echo "::set-output name=tag::$TAG"
echo "TAG=${TAG}" >> $GITHUB_ENV
else
# echo "::set-output name=tag::"
echo "TAG=" >> $GITHUB_ENV
fi
shell: bash

- name: Checkout repository
uses: actions/checkout@v3
with:
# Ensure all history is fetched
fetch-depth: 0

- name: Apply changelog
run: chmod +x ./sh/git_changelog.sh

- name: Generate changelog
id: changelog
run: |
CHANGELOG=$(./sh/git_changelog.sh)
echo "CHANGELOG=$CHANGELOG" >> $GITHUB_ENV
- name: Create GitHub Release
id: create_release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ env.TAG }}
body: |
:gem: released new version ${{ env.TAG }}
Changelog:
${{ env.CHANGELOG }}
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
113 changes: 113 additions & 0 deletions .github/workflows/ci_notify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
name: Notify

on:
push:
branches: ["master"]
tags:
- "v*"
pull_request:
branches: ["master"]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3

notify:
runs-on: ubuntu-latest
needs: build
steps:
- name: Check Secrets
id: check
run: |
if [[ -z "${{ secrets.TELEGRAM_CHAT_ID }}" || -z "${{ secrets.TELEGRAM_BOT_TOKEN }}" ]]; then
echo "::set-output name=skip::true"
else
echo "::set-output name=skip::false"
fi
- name: Send Telegram Notification
if: steps.check.outputs.skip == 'false'
uses: appleboy/telegram-action@master
with:
to: ${{ secrets.TELEGRAM_CHAT_ID }}
token: ${{ secrets.TELEGRAM_BOT_TOKEN }}
format: markdown
message: |
🚀 *AI Workflow Administrator (AWA)*
- *username*: `${{ github.actor }}`
- *message*: `${{ github.event.commits[0].message }}`
- *hash*: `${{ github.sha }}`
- *repository*: `${{ github.repository }}`
- *head*: `${{ github.event.head_commit.message }}`
🍀 *See changes*: `https://github.com/${{ github.repository }}/commit/${{github.sha}}`
deploy:
runs-on: ubuntu-latest
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
needs: build
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Check if tag exists
id: check_tag
run: |
if [ -n "$GITHUB_REF" ]; then
TAG=${GITHUB_REF#refs/tags/}
# echo "::set-output name=tag::$TAG"
echo "TAG=${TAG}" >> $GITHUB_ENV
else
# echo "::set-output name=tag::"
echo "TAG=" >> $GITHUB_ENV
fi
shell: bash

- name: Check Secrets
id: check
run: |
if [[ -z "${{ secrets.TELEGRAM_CHAT_ID }}" || -z "${{ secrets.TELEGRAM_BOT_TOKEN }}" ]]; then
echo "::set-output name=skip::true"
else
echo "::set-output name=skip::false"
fi
- name: Generate Changelog
id: changelog
run: |
# Generate your changelog here and set it as an output variable
CHANGELOG=$(git log --pretty=format:"%h - %s" -n 10)
echo "::set-output name=changelog::$CHANGELOG"
- name: Create GitHub Release
id: create_release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ env.TAG }}
body: |
:gem: released new version ${{ env.TAG }}
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Send Telegram Notification
if: steps.check.outputs.skip == 'false'
uses: appleboy/telegram-action@master
with:
to: ${{ secrets.TELEGRAM_CHAT_ID }}
token: ${{ secrets.TELEGRAM_BOT_TOKEN }}
format: markdown
message: |
🚀 *AI Workflow Administrator (AWA)*
- *latest tag*: *${{ env.TAG }}*
- *username*: `${{ github.actor }}`
- *hash*: `${{ github.sha }}`
- *repository*: `${{ github.repository }}`
- *head*: `${{ github.event.head_commit.message }}`
🍀 *See changes*: `https://github.com/${{ github.repository }}/releases/tag/${{ env.TAG }}`
📜 *Changelog*:
`${{ steps.changelog.outputs.changelog }}`
45 changes: 45 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test
*log

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
vendor/

# Go workspace file
go.work

# vscode
.vscode/settings.json
.vscode/extensions.json

# GoLand
.idea

# MacOS
.DS_Store

# Config
.env
.env.test
.env.dev
logs/
upload/
dir/
config/conf-local.yaml

# Main
main/
main.go
45 changes: 45 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
.PHONY: run build test tidy deps-upgrade deps-clean-cache

# ==============================================================================
# Running the main application
# Executes the main.go file, useful for development and quick testing
run:
go run main/main.go

# Building the application
# Compiles the main.go file into an executable, for production deployment
build:
go build main/main.go

# ==============================================================================
# Module support and testing
# Runs tests across all packages in the project, showing code coverage
test:
go test -cover ./...

# Cleaning and maintaining dependencies
# Cleans up the module by removing unused dependencies
# Copies all dependencies into the vendor directory, ensuring reproducibility
tidy:
go mod tidy
go mod vendor

# Upgrading dependencies
# Updates all dependencies to their latest minor or patch versions
# Cleans up the module after upgrade
# Re-vendors dependencies after upgrade
deps-upgrade:
# go get $(go list -f '{{if not (or .Main .Indirect)}}{{.Path}}{{end}}' -m all)
go get -u -t -d -v ./...
go mod tidy
go mod vendor

# Cleaning up the module cache
# Removes all items from the Go module cache
deps-clean-cache:
go clean -modcache

# Running code coverage
# Generates code coverage report and logs the results
coverage:
sh ./sh/go_deps.sh
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<h1>cachify</h1>

`cachify` is a lightweight, high-performance, thread-safe **Least Recently Used (LRU)** cache library for Go. It is designed for in-memory caching with optional support for expiration, eviction callbacks, and dynamic capacity adjustment.

Whether you're optimizing resource usage, caching frequently accessed data, or adding session management, `cachify` simplifies your task with an intuitive and flexible API.

---

# Getting Started

## Requirements

Go version **1.19** or higher

## Installation

To start using `cachify`, run `go get`:

- For a specific version:

```bash
go get https://github.com/pnguyen215/[email protected]
```

- For the latest version (globally):
```bash
go get -u https://github.com/pnguyen215/cachify@latest
```
1 change: 1 addition & 0 deletions const.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package cachify
53 changes: 53 additions & 0 deletions docs/RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Version Releases

## Semantic Versioning (SemVer): `vMAJOR.MINOR.PATCH`

Example:

- v1.0.0
- v1.0.1
- v1.1.1

## Pre-release versions: `vMAJOR.MINOR.PATCH-<BETA/RC/SNAPSHOT>.<number>`

Example:

- v1.0.0-beta.1
- v1.0.0-beta.2
- v1.2.3-rc1
- v1.2.3-SNAPSHOT

## Post-release versions: `vMAJOR.MINOR.PATCH-POST.<number>`

Example:

- v1.2.3-post.1
- v1.2.3-post.2

## Local versions: `vMAJOR.MINOR.PATCH+LOCAL`

Example:

- v1.0.0+local
- v1.1.0+local

## Caret range versions: `^MAJOR.MINOR.PATCH`

Example:

- ^1.2.3 (similar `>=1.2.3 < 2.0.0`)

## Tilde range versions: `~MAJOR.MINOR.PATCH`

Example:

- ~1.2.3 (similar `>=1.2.3 <1.3.0`)

---

Notes:

- `MAJOR`: major version.
- `MINOR`: Minor version, often adding new features.
- `PATCH`: Patch version, typically fixing bugs.
- `SNAPSHOT`: Indicates a version under development or in progress. It is often used to represent the latest state of the codebase and may include ongoing changes and features that are not yet finalized. This allows developers to work with the most recent developments in a project.
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/pnguyen215/cachify

go 1.23.1
Empty file added go.sum
Empty file.
Loading

0 comments on commit fec04bf

Please sign in to comment.