Skip to content

Commit

Permalink
feat: refactor tests to not use gnomock (#36)
Browse files Browse the repository at this point in the history
* feat: refactor test to not use gnomock

* chore: set parallel to all tests

* chore: add mongo serice to tests
  • Loading branch information
danteay authored Dec 19, 2024
1 parent 405682a commit 065d92d
Show file tree
Hide file tree
Showing 46 changed files with 670 additions and 938 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ jobs:
test:
name: 👍 Test
runs-on: ubuntu-latest
services:
mongo_test:
image: mongo:latest
env:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: root
ports:
- "27017:27017"
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
67 changes: 17 additions & 50 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,62 +26,29 @@ jobs:
token: "${{ secrets.ACCESS_TOKEN }}"
ref: "main"

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Config Git User
run: |
git config --local user.email "$GIT_USER_EMAIL"
git config --local user.name "$GIT_USER_NAME"
git config --local pull.ff only
- id: cz
name: Create bump and changelog
run: |
python -m pip install -U commitizen
cz bump --changelog --yes
export REV=`cz version --project`
echo "version=$REV" >> $GITHUB_OUTPUT
- name: Push changes
uses: Woile/github-push-action@master
uses: commitizen-tools/[email protected]
with:
github_token: ${{ secrets.ACCESS_TOKEN }}
tags: "true"
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: "main"
git_name: ${{ secrets.GIT_NAME }}
git_email: ${{ secrets.GIT_EMAIL }}
changelog_increment_filename: body.md

- name: Print Version
run: echo "Bumped to version ${{ steps.cz.outputs.version }}"

release:
runs-on: ubuntu-latest
name: "Release service"
needs:
- bump_version
steps:
- name: Check out
uses: actions/checkout@v4
with:
fetch-depth: 0
token: "${{ secrets.ACCESS_TOKEN }}"
ref: "main"

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.21.x
run: echo "Bumped to version ${{ env.REVISION }}"

- name: Config private packages
run: git config --global url.https://${{ secrets.ACCESS_TOKEN }}@github.com/Drafteame.insteadOf https://github.com/Drafteame
- name: Trim body to 125000 characters
run: |
if [ $(wc -c < body.md) -gt 125000 ]; then
head -c 125000 body.md > body.md
fi
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
- name: Release
uses: softprops/action-gh-release@v2
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SLACK_WEBHOOK: ${{ secrets.SLACK_RELEASE_WEBHOOK }}
body_path: "body.md"
tag_name: ${{ env.REVISION }}
token: ${{ secrets.GITHUB_TOKEN }}
make_latest: "true"
47 changes: 0 additions & 47 deletions .goreleaser.yml

This file was deleted.

10 changes: 10 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env sh

. "$(dirname "$0")/_/husky.sh"

sh ./.husky/commit-msg-scripts/commitizen.sh

if [ $? -ne 0 ]; then
echo "[husky] commit validation error"
exit 1
fi
18 changes: 18 additions & 0 deletions .husky/commit-msg-scripts/commitizen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

if [ "$GIT_NV" = "1" ]; then
echo "[commitizen] skipping commit message check"
exit 0
fi

echo "[commitizen] checking commit message with commitizen"

cz check --commit-msg-file .git/COMMIT_EDITMSG

# shellcheck disable=SC2181
if [ $? -ne 0 ]; then
echo "[commitizen] found issues in commit message"
exit 1
fi

exit 0
16 changes: 16 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env sh

. "$(dirname "$0")/_/husky.sh"

MOD_VERSION="1.21"

sh ./.husky/pre-commit-scripts/go-mod-tidy.sh && \
sh ./.husky/pre-commit-scripts/force-mod-version.sh "$MOD_VERSION" && \
sh ./.husky/pre-commit-scripts/goimports-reviser.sh && \
sh ./.husky/pre-commit-scripts/go-vet.sh && \
sh ./.husky/pre-commit-scripts/revive.sh

if [ $? -ne 0 ]; then
echo "[husky] commit validation error"
exit 1
fi
55 changes: 55 additions & 0 deletions .husky/pre-commit-scripts/force-mod-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env bash

if [ "$GIT_NV" = "1" ]; then
echo "[force-mod-version] skipping go.mod version check"
exit 0
fi

echo "[force-mod-version] checking go.mod files"

set -e -o pipefail

version="1.21"
if [ $# -gt 0 ]; then
version="$1"
fi


function sed_replace() {
local os
os=$(uname)

if [ "$os" = "Darwin" ]; then
sed -i '' "$1" "$2"
else
sed -i "$1" "$2"
fi
}

function update_go_version() {
local file="$1"

if grep -q "^toolchain go" "$file"; then
echo "[force-mod-version] removing gotoolchain version from $file"
sed_replace '/^toolchain go/d' "$file"
fi

if current_version=$(grep "^go [0-9]" "$file" | awk '{print $2}'); then
if [ "$current_version" != "$version" ]; then
echo "[force-mod-version] updating go version from $current_version to $version in $file"
pattern="s|^go .*|go $version|g"
sed_replace "$pattern" "$file"
fi
fi
}

# Find and process go.mod files
go_mod_files=$(fd 'go.mod' --glob)
if [ -n "$go_mod_files" ]; then
for file in $go_mod_files; do
update_go_version "$file"
done
fi

git add --all
exit 0
38 changes: 38 additions & 0 deletions .husky/pre-commit-scripts/go-mod-tidy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash

if [ "$GIT_NV" = "1" ]; then
echo "[go-mod-tidy] skipping go.mod files check"
exit 0
fi

echo "[go-mod-tidy] checking go.mod files"

function get_base_dir() {
local dir

local file="$1"
dir=$(dirname "$file")

echo "$dir"
}

# Find and process go.mod files
go_mod_files=$(fd 'go.mod' --glob)
if [ -n "$go_mod_files" ]; then
for file in $go_mod_files; do
echo "[go-mod-tidy] tidying $file"

cd "$(get_base_dir "$file")" && go mod tidy -v

# shellcheck disable=SC2181
if [ $? -ne 0 ]; then
exit 2
fi

# shellcheck disable=SC2164
cd - > /dev/null
done
fi

git add --all
exit 0
18 changes: 18 additions & 0 deletions .husky/pre-commit-scripts/go-vet.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

if [ "$GIT_NV" = "1" ]; then
echo "[go-vet] skipping go files check"
exit 0
fi

echo "[go-vet] checking go files"

go vet ./...

# shellcheck disable=SC2181
if [ $? -ne 0 ]; then
echo "[go-vet] found issues in go files"
exit 1
fi

exit 0
19 changes: 19 additions & 0 deletions .husky/pre-commit-scripts/goimports-reviser.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

if [ "$GIT_NV" = "1" ]; then
echo "[goimports-reviser] skipping goimports formatting"
exit 0
fi

echo "[goimports-reviser] formatting code"

goimports-reviser -format ./...

# shellcheck disable=SC2181
if [ $? -ne 0 ]; then
echo "[goimports-reviser] found issues formatting go files"
exit 1
fi

git add --all
exit 0
18 changes: 18 additions & 0 deletions .husky/pre-commit-scripts/revive.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

if [ "$GIT_NV" = "1" ]; then
echo "[revive] skipping go files check"
exit 0
fi

echo "[revive] checking go files"

revive -config=revive.toml -formatter=friendly ./...

# shellcheck disable=SC2181
if [ $? -ne 0 ]; then
echo "[revive] found issues in go files"
exit 1
fi

exit 0
19 changes: 17 additions & 2 deletions .mockery.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
inpackage: False
dry-run: False
all: true
dir: '{{.InterfaceDir}}/mocks'
outpkg: mocks
recursive: false
with-expecter: true

exclude:
- node_modules
- vendor
- .git
- .husky
- .github
- .idea
- .vscode

packages:
github.com/Drafteame/mgorepo/logger: {}
30 changes: 0 additions & 30 deletions .pre-commit-config.yaml

This file was deleted.

Loading

0 comments on commit 065d92d

Please sign in to comment.