Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add tests #1

Merged
merged 5 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
test:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -16,25 +14,22 @@ jobs:
uses: actions/setup-go@v4
with:
go-version: "1.21"
cache: false

- name: Install Task
uses: arduino/setup-task@v1
run: |
curl -fsSL https://github.com/go-task/task/releases/download/v3.30.1/task_linux_amd64.tar.gz | \
sudo tar -xz -C /usr/local/bin task && \
sudo chmod +x /usr/local/bin/task

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
args: --config=.golangci.yml --out-format=colored-line-number
skip-cache: true
install-mode: binary

- name: Run tests
run: task test
args: --config=.golangci.yml

release:
needs: test
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs: lint
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -45,7 +40,12 @@ jobs:
uses: actions/setup-go@v4
with:
go-version: "1.21"
cache: false

- name: Install Task
run: |
curl -fsSL https://github.com/go-task/task/releases/download/v3.30.1/task_linux_amd64.tar.gz | \
sudo tar -xz -C /usr/local/bin task && \
sudo chmod +x /usr/local/bin/task

- name: Run semantic-release
env:
Expand All @@ -66,7 +66,12 @@ jobs:
uses: actions/setup-go@v4
with:
go-version: "1.21"
cache: false

- name: Install Task
run: |
curl -fsSL https://github.com/go-task/task/releases/download/v3.30.1/task_linux_amd64.tar.gz | \
sudo tar -xz -C /usr/local/bin task && \
sudo chmod +x /usr/local/bin/task

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
Expand Down
37 changes: 37 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Test

on:
pull_request:
branches: [main]

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]

steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.21"

- name: Install Task
run: |
curl -fsSL https://github.com/go-task/task/releases/download/v3.30.1/task_linux_amd64.tar.gz | \
sudo tar -xz -C /usr/local/bin task && \
sudo chmod +x /usr/local/bin/task
if: runner.os == 'Linux'

- name: Install Task
run: |
curl -fsSL https://github.com/go-task/task/releases/download/v3.30.1/task_darwin_amd64.tar.gz | \
sudo tar -xz -C /usr/local/bin task && \
sudo chmod +x /usr/local/bin/task
if: runner.os == 'macOS'

- name: Run tests
run: task test
25 changes: 7 additions & 18 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ version: "3"

vars:
GO_MODULE: github.com/rebelopsio/duet
BUILD_DIR: dist
COVERAGE_DIR: coverage
BUILD_DIR: "{{.ROOT_DIR}}/dist"
COVERAGE_DIR: "{{.ROOT_DIR}}/coverage"

tasks:
default:
Expand All @@ -19,7 +19,10 @@ tasks:
ensure-lint:
internal: true
cmds:
- which golangci-lint || go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
- |
if ! command -v golangci-lint &> /dev/null; then
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
fi

lint:
desc: Run golangci-lint
Expand All @@ -32,12 +35,11 @@ tasks:
cmds:
- mkdir -p {{.COVERAGE_DIR}}
- go test -race -coverprofile={{.COVERAGE_DIR}}/coverage.out -covermode=atomic ./...
- go tool cover -html={{.COVERAGE_DIR}}/coverage.out -o {{.COVERAGE_DIR}}/coverage.html

build:
desc: Build binary
deps: [clean]
cmds:
- task: clean
- mkdir -p {{.BUILD_DIR}}
- go build -o {{.BUILD_DIR}}/duet cmd/duet/main.go

Expand All @@ -58,16 +60,3 @@ tasks:
- task: generate
- task: lint
- task: test

check-license:
desc: Check license headers
cmds:
- |
find . -type f -name "*.go" -not -path "./vendor/*" -exec sh -c '
for file do
if ! grep -q "Copyright" "$file"; then
echo "Missing license header in $file"
exit 1
fi
done
' sh {} +
Loading
Loading