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 Feb 16, 2025
0 parents commit 0fb42f8
Show file tree
Hide file tree
Showing 12 changed files with 690 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 }}`
42 changes: 42 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# 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/
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
Loading

0 comments on commit 0fb42f8

Please sign in to comment.