Skip to content

Commit 40a0a49

Browse files
authored
feat: first version (#1)
* feat: first version * fix: github workflows and files * feat: update the go version * fix: install scc tools from binary * fix: workflows steps name
1 parent 1064525 commit 40a0a49

32 files changed

Lines changed: 8599 additions & 1 deletion

.github/FUNDING.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# These are supported funding model platforms
2+
github: [christiangda]
3+
liberapay: christiangda
4+
patreon: christiangda
5+
custom: ["https://paypal.me/slashdevops"]

.github/codeql/codeql-config.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: CodeQL config
2+
# queries:
3+
# - name: Run custom queries
4+
# uses: ./queries
5+
# # Run all extra query suites, both because we want to
6+
# # and because it'll act as extra testing. This is why
7+
# # we include both even though one is a superset of the
8+
# # other, because we're testing the parsing logic and
9+
# # that the suites exist in the codeql bundle.
10+
# - uses: security-extended
11+
# - uses: security-and-quality
12+
paths-ignore:
13+
- mocks

.github/copilot-instructions.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Development Guidelines
2+
3+
This document contains the critical information about working with the project codebase.
4+
Follows these guidelines precisely to ensure consistency and maintainability of the code.
5+
6+
## Stack
7+
8+
- Language: Go (Go 1.22+)
9+
- Framework: Go standard library
10+
- Testing: Go's built-in testing package
11+
- Dependency Management: Go modules
12+
- Version Control: Git
13+
- Documentation: go doc
14+
- Code Review: Pull requests on GitHub
15+
- CI/CD: GitHub Actions
16+
- Logging: `slog` package from the standard library
17+
18+
## Project Structure
19+
20+
Since this is a library build in native go, the files are mostly organized following the standard Go project layout with some additional folders for specific functionalities.
21+
22+
- Library files are located in the root directory.
23+
- examples/ contains example code demonstrating how to use the library.
24+
- .github/ contains GitHub-specific files such as workflows for CI/CD.
25+
- .gitignore specifies files and directories to be ignored by Git.
26+
- .vscode/ contains Visual Studio Code configuration files.
27+
- LICENSE is the license file for the project.
28+
- README.md provides an overview of the project, installation instructions, usage examples, and other relevant information.
29+
- go.mod and go.sum manage the project's dependencies.
30+
- \*.go files contain the main source code of the library.
31+
- \*\_test.go files contain the test cases for the library.
32+
33+
## Code Style
34+
35+
- Follow Go's idiomatic style defined in
36+
- #fetch https://google.github.io/styleguide/go/guide
37+
- #fetch https://google.github.io/styleguide/go/decisions
38+
- #fetch https://google.github.io/styleguide/go/best-practices
39+
- #fetch https://golang.org/doc/effective_go.html
40+
- Use meaningful names for variables, functions, and packages.
41+
- Keep functions small and focused on a single task.
42+
- Use comments to explain complex logic or decisions.
43+
- Use dependency injection for services and repositories to facilitate testing and maintainability.
44+
- don't use `interface{}` instead use `any` for better readability.

.github/dependabot.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: "gomod" # See documentation for possible values
9+
directory: "/" # Location of package manifests
10+
schedule:
11+
interval: "weekly"

.github/release.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
# https://docs.github.com/es/repositories/releasing-projects-on-github/automatically-generated-release-notes
3+
changelog:
4+
categories:
5+
- title: Breaking Changes 🛠
6+
labels:
7+
- Semver-Major
8+
- breaking-change
9+
- title: New Features 🎉
10+
labels:
11+
- Semver-Minor
12+
- enhancement
13+
- title: Other Changes
14+
labels:
15+
- "*"

.github/workflows/codeql.yml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
#
12+
name: "CodeQL Advanced"
13+
14+
on:
15+
push:
16+
branches: ["main"]
17+
pull_request:
18+
branches: ["main"]
19+
schedule:
20+
- cron: "10 12 * * 3"
21+
22+
jobs:
23+
analyze:
24+
name: Analyze (${{ matrix.language }})
25+
# Runner size impacts CodeQL analysis time. To learn more, please see:
26+
# - https://gh.io/recommended-hardware-resources-for-running-codeql
27+
# - https://gh.io/supported-runners-and-hardware-resources
28+
# - https://gh.io/using-larger-runners (GitHub.com only)
29+
# Consider using larger runners or machines with greater resources for possible analysis time improvements.
30+
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
31+
permissions:
32+
# required for all workflows
33+
security-events: write
34+
35+
# required to fetch internal or private CodeQL packs
36+
packages: read
37+
38+
# only required for workflows in private repositories
39+
actions: read
40+
contents: read
41+
42+
strategy:
43+
fail-fast: false
44+
matrix:
45+
include:
46+
- language: actions
47+
build-mode: none
48+
- language: go
49+
build-mode: autobuild
50+
# CodeQL supports the following values keywords for 'language': 'actions', 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift'
51+
# Use `c-cpp` to analyze code written in C, C++ or both
52+
# Use 'java-kotlin' to analyze code written in Java, Kotlin or both
53+
# Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
54+
# To learn more about changing the languages that are analyzed or customizing the build mode for your analysis,
55+
# see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning.
56+
# If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
57+
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
58+
steps:
59+
- name: Checkout repository
60+
uses: actions/checkout@v6
61+
62+
# Add any setup steps before running the `github/codeql-action/init` action.
63+
# This includes steps like installing compilers or runtimes (`actions/setup-node`
64+
# or others). This is typically only required for manual builds.
65+
# - name: Setup runtime (example)
66+
# uses: actions/setup-example@v1
67+
68+
# Initializes the CodeQL tools for scanning.
69+
- name: Initialize CodeQL
70+
uses: github/codeql-action/init@v4
71+
with:
72+
languages: ${{ matrix.language }}
73+
build-mode: ${{ matrix.build-mode }}
74+
# If you wish to specify custom queries, you can do so here or in a config file.
75+
# By default, queries listed here will override any specified in a config file.
76+
# Prefix the list here with "+" to use these queries and those in the config file.
77+
78+
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
79+
# queries: security-extended,security-and-quality
80+
81+
# If the analyze step fails for one of the languages you are analyzing with
82+
# "We were unable to automatically build your code", modify the matrix above
83+
# to set the build mode to "manual" for that language. Then modify this step
84+
# to build your code.
85+
# ℹ️ Command-line programs to run using the OS shell.
86+
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
87+
- if: matrix.build-mode == 'manual'
88+
shell: bash
89+
run: |
90+
echo 'If you are using a "manual" build mode for one or more of the' \
91+
'languages you are analyzing, replace this with the commands to build' \
92+
'your code, for example:'
93+
echo ' make bootstrap'
94+
echo ' make release'
95+
exit 1
96+
97+
- name: Perform CodeQL Analysis
98+
uses: github/codeql-action/analyze@v4
99+
with:
100+
category: "/language:${{matrix.language}}"

.github/workflows/main.yml

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
name: Main
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v6
14+
15+
- name: Set up Go
16+
uses: actions/setup-go@v6
17+
with:
18+
go-version-file: ./go.mod
19+
20+
- name: Summary Information
21+
run: |
22+
echo "# Push Summary" > $GITHUB_STEP_SUMMARY
23+
echo "" >> $GITHUB_STEP_SUMMARY
24+
echo "**Repository:** ${{ github.repository }}" >> $GITHUB_STEP_SUMMARY
25+
echo "**Push:** ${{ github.event.head_commit.message }}" >> $GITHUB_STEP_SUMMARY
26+
echo "**Author:** ${{ github.event.head_commit.author.name }}" >> $GITHUB_STEP_SUMMARY
27+
echo "**Branch:** ${{ github.ref }}" >> $GITHUB_STEP_SUMMARY
28+
echo "" >> $GITHUB_STEP_SUMMARY
29+
30+
- name: Tools and versions
31+
run: |
32+
echo "## Tools and versions" >> $GITHUB_STEP_SUMMARY
33+
34+
ubuntu_version=$(lsb_release -a 2>&1 | grep "Description" | awk '{print $2, $3, $4}')
35+
echo "Ubuntu version: $ubuntu_version"
36+
echo "**Ubuntu Version:** $ubuntu_version" >> $GITHUB_STEP_SUMMARY
37+
38+
bash_version=$(bash --version | head -n 1 | awk '{print $4}')
39+
echo "Bash version: $bash_version"
40+
echo "**Bash Version:** $bash_version" >> $GITHUB_STEP_SUMMARY
41+
42+
git_version=$(git --version | awk '{print $3}')
43+
echo "Git version: $git_version"
44+
echo "**Git Version:** $git_version" >> $GITHUB_STEP_SUMMARY
45+
46+
go_version=$(go version | awk '{print $3}')
47+
echo "Go version: $go_version"
48+
echo "**Go Version:** $go_version" >> $GITHUB_STEP_SUMMARY
49+
echo "" >> $GITHUB_STEP_SUMMARY
50+
51+
- name: Lines of code
52+
env:
53+
GH_TOKEN: ${{ github.token }}
54+
run: |
55+
export TOOL_NAME="scc"
56+
export GIT_ORG="boyter"
57+
export GIT_REPO="scc"
58+
export OS=$(uname -s)
59+
export OS_ARCH=$(uname -m)
60+
# Normalize architecture names to match asset naming
61+
[[ "$OS_ARCH" == "aarch64" ]] && OS_ARCH="arm64"
62+
[[ "$OS_ARCH" == "x86_64" ]] && OS_ARCH="x86_64"
63+
export ASSETS_NAME=$(gh release view --repo ${GIT_ORG}/${GIT_REPO} --json assets -q "[.assets[] | select(.name | contains(\"${TOOL_NAME}\") and contains(\"${OS}\") and contains(\"${OS_ARCH}\"))] | sort_by(.createdAt) | last.name")
64+
65+
gh release download --repo $GIT_ORG/$GIT_REPO --pattern $ASSETS_NAME
66+
67+
# Extract based on file extension
68+
if [[ "$ASSETS_NAME" == *.tar.gz ]]; then
69+
tar -xzf $ASSETS_NAME
70+
elif [[ "$ASSETS_NAME" == *.zip ]]; then
71+
unzip $ASSETS_NAME
72+
fi
73+
74+
rm $ASSETS_NAME
75+
76+
mv $TOOL_NAME ~/go/bin/$TOOL_NAME
77+
~/go/bin/$TOOL_NAME --version
78+
79+
# go install github.com/boyter/scc/v3@latest
80+
81+
scc --format html-table . | tee -a $GITHUB_STEP_SUMMARY
82+
echo "" >> $GITHUB_STEP_SUMMARY
83+
84+
- name: Test
85+
run: |
86+
echo "### Test report" >> $GITHUB_STEP_SUMMARY
87+
88+
go test -race -coverprofile=coverage.txt -covermode=atomic -tags=unit ./... | tee -a $GITHUB_STEP_SUMMARY
89+
echo "" >> $GITHUB_STEP_SUMMARY
90+
91+
- name: Test coverage
92+
run: |
93+
echo "## Test Coverage" >> $GITHUB_STEP_SUMMARY
94+
95+
# Generate coverage report using standard library tools
96+
echo "" >> $GITHUB_STEP_SUMMARY
97+
echo "### Coverage report" >> $GITHUB_STEP_SUMMARY
98+
echo '```' >> $GITHUB_STEP_SUMMARY
99+
go tool cover -func=coverage.txt | tee -a $GITHUB_STEP_SUMMARY
100+
echo '```' >> $GITHUB_STEP_SUMMARY
101+
echo "" >> $GITHUB_STEP_SUMMARY
102+
103+
# Calculate total coverage percentage
104+
total_coverage=$(go tool cover -func=coverage.txt | grep total | awk '{print $3}')
105+
echo "**Total Coverage:** $total_coverage" >> $GITHUB_STEP_SUMMARY
106+
107+
- name: Build
108+
run: |
109+
echo "## Build" >> $GITHUB_STEP_SUMMARY
110+
111+
go build ./... | tee -a $GITHUB_STEP_SUMMARY
112+
echo "" >> $GITHUB_STEP_SUMMARY
113+
echo "Build completed successfully." >> $GITHUB_STEP_SUMMARY
114+
echo "" >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)