Skip to content

Commit 5ba94b5

Browse files
authored
Merge pull request #10 from sqlitecloud/code-quality-tools-and-cicd-workflow
Code quality tools and CI/CD workflow
2 parents 21a8653 + fae10cd commit 5ba94b5

35 files changed

+345
-181
lines changed

.devcontainer/Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM mcr.microsoft.com/devcontainers/go:1-1-bullseye
2+
3+
# Python environment
4+
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
5+
&& apt-get -y install python3-pip git zlib1g-dev unzip
6+
7+
# Pre-Commit to run pre-commit tools
8+
RUN pip3 install pre-commit

.devcontainer/devcontainer.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,17 @@
33
{
44
"name": "Go",
55
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
6-
"image": "mcr.microsoft.com/devcontainers/go:1-1-bullseye"
6+
"build": {
7+
"dockerfile": "Dockerfile"
8+
},
9+
"customizations": {
10+
"vscode": {
11+
"extensions": [
12+
"eamodio.gitlens",
13+
"golang.go"
14+
]
15+
}
16+
}
717

818
// Features to add to the dev container. More info: https://containers.dev/features.
919
// "features": {},

.github/workflows/release.yaml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Create an incremental tag on Github using SemVer https://semver.org: x.y.z
2+
# A tag is a release version on pkg.go.dev, which is
3+
# notified with the publishing go command.
4+
5+
name: Release
6+
7+
on:
8+
workflow_dispatch:
9+
inputs:
10+
choice:
11+
type: choice
12+
description: "Release types (x.y.patch / x.minor.z / major.y.z)"
13+
options:
14+
- patch
15+
- minor
16+
- major
17+
18+
jobs:
19+
release:
20+
if: ${{ github.ref == 'refs/heads/main' }}
21+
runs-on: ubuntu-latest
22+
name: Tag for release
23+
steps:
24+
- name: Checkout code
25+
uses: actions/checkout@v2
26+
with:
27+
fetch-depth: 0
28+
- name: Last version
29+
id: last-version
30+
run: echo "::set-output name=tag::$(git describe --tags `git rev-list --tags --max-count=1`)"
31+
- name: Bump version
32+
id: bump-version
33+
uses: olegsu/semver-action@v1
34+
with:
35+
version: ${{ steps.last-version.outputs.tag }}
36+
bump: ${{ inputs.choice }}
37+
- name: Create tag as version for the package
38+
run: |
39+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
40+
git config --global user.name "GitHub Actions"
41+
git tag ${{ steps.bump-version.outputs.version }}
42+
git push origin ${{ steps.bump-version.outputs.version }}
43+
- name: Publish on pkg.go.dev
44+
run: GOPROXY=proxy.golang.org go list -m github.com/sqlitecloud/sqlitecloud-go@${{ steps.bump-version.outputs.version }}

.github/workflows/testing.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# This workflow will build a golang project
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
3+
4+
name: Test and QA
5+
6+
on:
7+
push:
8+
workflow_dispatch:
9+
10+
jobs:
11+
12+
tests:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
- name: Set up Go
17+
uses: actions/setup-go@v4
18+
with:
19+
go-version: '1.18'
20+
- name: Quality Assurance
21+
run: |
22+
go install golang.org/x/tools/cmd/goimports@latest
23+
gofmt -l ./*.go
24+
goimports -e -d ./*.go
25+
- name: golangci-lint
26+
uses: golangci/golangci-lint-action@v6
27+
with:
28+
version: latest
29+
- name: Tests
30+
env:
31+
SQLITE_CONNECTION_STRING: ${{ vars.SQLITE_CONNECTION_STRING }}
32+
SQLITE_USER: ${{ secrets.SQLITE_USER }}
33+
SQLITE_PASSWORD: ${{ secrets.SQLITE_PASSWORD }}
34+
SQLITE_API_KEY: ${{ secrets.SQLITE_API_KEY }}
35+
SQLITE_HOST: ${{ vars.SQLITE_HOST }}
36+
SQLITE_DB: ${{ vars.SQLITE_DB }}
37+
SQLITE_PORT: ${{ vars.SQLITE_PORT }}
38+
run: make test-codecov
39+
- name: Upload coverage reports to Codecov
40+
uses: codecov/[email protected]
41+
with:
42+
token: ${{ secrets.CODECOV_TOKEN }}

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ cli/.vscode
55
.vscode/launch.json
66
pkg/
77
bin
8-
.env
8+
.env

.pre-commit-config.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Pre-Commit
2+
# https://pre-commit.com
3+
# Run formatter and more before git commit.
4+
repos:
5+
- repo: https://github.com/pre-commit/pre-commit-hooks
6+
rev: v4.6.0
7+
hooks:
8+
- id: trailing-whitespace
9+
- id: end-of-file-fixer
10+
- id: detect-private-key
11+
- id: check-merge-conflict
12+
- repo: local
13+
hooks:
14+
- id: gofmt
15+
name: gofmt
16+
language: golang
17+
entry: fmt
18+
files: \.go$
19+
require_serial: true
20+
- repo: local
21+
hooks:
22+
- id: goimports
23+
name: goimports
24+
language: golang
25+
entry: goimports
26+
files: \.go$
27+
args:
28+
- -w
29+
require_serial: true
30+
- repo: https://github.com/golangci/golangci-lint
31+
rev: v1.59.1
32+
hooks:
33+
- id: golangci-lint
34+
exclude: ^pkg/

.vscode/settings.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{
22
"gopls": {
33
"ui.semanticTokens": true
4-
}
4+
},
5+
"go.lintTool": "golangci-lint",
6+
"go.lintFlags": [
7+
"--fast"
8+
]
59
}

ERRORs.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
12334
44
│││││
55
││││└─ Error Reason
6-
│││└── Data Type
6+
│││└── Data Type
77
││└─── Class
88
│└──── Module
99
```
@@ -37,4 +37,4 @@
3737
## Module
3838

3939
| Code | Alternative | Explanation |
40-
|------|-------------|-------------|
40+
|------|-------------|-------------|

MAKEFILE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SQLite Cloud go-sdk Makefile
1+
# SQLite Cloud sqlitecloud-go Makefile
22

33
### Run the test for the SDK
44
If you want to run the Test programs: `make test`
@@ -16,4 +16,4 @@ If you want to see the Documentation: `make doc` - Warning: A browser window wil
1616
- Check files with gosec: `make checksec`
1717
- Open the repo in github: `make github`.
1818
- See changes: `make diff`
19-
- Clean dependencies and precompiled code: `make clean`
19+
- Clean dependencies and precompiled code: `make clean`

Makefile

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
GOPATH = $(shell go env GOPATH)
22

3+
setup-ide:
4+
pre-commit install
5+
go install golang.org/x/tools/cmd/goimports@latest
6+
go mod tidy
7+
cd test; go mod tidy
8+
cd cli; go mod tidy
9+
310
# Test SDK
4-
test:
5-
cd test; go test -v
11+
test:
12+
cd test; go test -v .
13+
14+
test-codecov:
15+
cd test; go test -v -race -coverprofile=coverage.txt -covermode=atomic .
616

717
# GO SDK
818
sdk: *.go
@@ -11,15 +21,15 @@ sdk: *.go
1121
# CLI App
1222
$(GOPATH)/bin/sqlc: *.go cli/sqlc.go
1323
cd cli; go build -o $(GOPATH)/bin/sqlc
14-
24+
1525
cli: $(GOPATH)/bin/sqlc
1626

1727
github:
18-
open https://github.com/sqlitecloud/go-sdk
19-
28+
open https://github.com/sqlitecloud/sqlitecloud-go
29+
2030
diff:
2131
git difftool
22-
32+
2333

2434
# gosec
2535
gosec:
@@ -40,15 +50,15 @@ endif
4050

4151
doc: godoc
4252
ifeq ($(wildcard ./src),)
43-
ln -s . src
53+
ln -s . src
4454
endif
4555
@echo "Hit CRTL-C to stop the documentation server..."
46-
@( sleep 1 && open http://localhost:6060/pkg/github.com/sqlitecloud/go-sdk/ ) &
56+
@( sleep 1 && open http://localhost:6060/pkg/github.com/sqlitecloud/sqlitecloud-go/ ) &
4757
@$(GOPATH)/bin/godoc -http=:6060 -index -play
4858

4959
clean:
50-
rm -rf $(GOPATH)/bin/sqlc*
60+
rm -rf $(GOPATH)/bin/sqlc*
5161

5262
all: sdk cli test
5363

54-
.PHONY: test sdk
64+
.PHONY: test sdk

0 commit comments

Comments
 (0)