Skip to content

Commit

Permalink
Merge pull request #224 from canonical/IAM-695-ci/endpoints-library-t…
Browse files Browse the repository at this point in the history
…ests

feat: add separate CI worflows to run library tests and linting
  • Loading branch information
BarcoMasile authored Mar 19, 2024
2 parents c23f947 + fb19d10 commit 7f53271
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
61 changes: 61 additions & 0 deletions .github/workflows/ci-rebac-admin-backend.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: ci-rebac-admin-backend
run-name: CI (rebac-admin) for ${{ github.sha }} on ${{ github.ref_name }}

on:
workflow_dispatch:
push:
branches:
- "feature-rebac-admin-ui-backend"
pull_request:
branches:
- "*"

permissions:
contents: read
pull-requests: read
checks: write

jobs:
lint:
name: Perform linting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
name: Checkout repo

- uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4
name: Setup Go version
with:
go-version-file: 'go.mod'

- uses: golangci/golangci-lint-action@v3
name: Perform linting and annotate code
with:
version: latest
working-directory: ./rebac-admin-backend
only-new-issues: true

unit-test:
name: Run unit tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4

- uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4
with:
go-version-file: 'go.mod'

- name: Build and test Go code
working-directory: ./rebac-admin-backend
run: make ARGS="-count=1" test-coverage


- uses: codecov/codecov-action@c4cf8a4f03f0ac8585acb7c1b7ce3460ec15782f # v4
with:
files: ./rebac-admin-backend/coverage.out

- name: Upload Go test results
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3
with:
name: Go-results
path: ./rebac-admin-backend/test.json
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ yarn-error.log*

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
test.json
test_source.json

# Dependency directories (remove the comment below to include it)
# vendor/
Expand Down
11 changes: 10 additions & 1 deletion rebac-admin-backend/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,16 @@ mocks:
go generate ./...
.PHONY: mocks

# Run tests with coverage
test-coverage: mocks
go test ./... -cover -coverprofile coverage_source.out $(ARGS)
# this will be cached, just needed to get the test.json
go test ./... -cover -coverprofile coverage_source.out $(ARGS) -json > test_source.json
cat coverage_source.out | grep -v "mock_*" | tee coverage.out
cat test_source.json | grep -v "mock_*" | tee test.json
.PHONY: test-coverage

# Run tests
test: mocks
go test ./...
go test ./... $(ARGS)
.PHONY: test

0 comments on commit 7f53271

Please sign in to comment.