Skip to content

Commit

Permalink
add new test workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
dejanzele committed Jun 22, 2023
1 parent 476bc55 commit 23b7ed1
Show file tree
Hide file tree
Showing 5 changed files with 206 additions and 147 deletions.
73 changes: 0 additions & 73 deletions .github/workflows/go-integration.yml

This file was deleted.

66 changes: 0 additions & 66 deletions .github/workflows/go.yml

This file was deleted.

204 changes: 204 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
name: Code Build and Tests

on:
push:
branches: [master]
pull_request:
branches: [master]

permissions:
contents: read
checks: write

jobs:
unit-tests:
name: Unit Tests
runs-on: ubuntu-22.04

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Golang with Cache
uses: magnetikonline/action-golang-cache@v4
with:
go-version: "1.20"

- name: Setup dependencies
shell: bash
run: make download

- name: Unit Tests
id: unit_test
run: make tests

- name: Publish JUnit Report
uses: mikepenz/action-junit-report@v3
if: always()
with:
report_paths: test-reports/unit-tests.xml
fail_on_failure: true
require_tests: true
detailed_summary: true
token: ${{ secrets.GITHUB_TOKEN }}

- name: Upload Test Reports Artifacts
if: always()
uses: actions/upload-artifact@v3
with:
name: unit-test-reports
path: test-reports/
if-no-files-found: error

- name: Send Coverage Report to Codecov
if: always()
uses: codecov/codecov-action@v3
with:
file: ./test-reports/coverage.out
flags: unittests
name: codecov-armada-unit-tests
verbose: true

integration-tests:
name: Integration Tests
runs-on: ubuntu-22.04

env:
ARMADA_EXECUTOR_INGRESS_URL: "http://localhost"
ARMADA_EXECUTOR_INGRESS_PORT: 5001
# Cache Docker layers in the GitHub actions cache.
# These variables are picked up by the goreleaser config.
DOCKER_BUILDX_CACHE_FROM: "type=gha"
DOCKER_BUILDX_CACHE_TO: "type=gha,mode=max"
DOCKER_BUILDX_BUILDER: "builder"

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Create Docker Buildx Builder
run: docker buildx create --name ${DOCKER_BUILDX_BUILDER} --driver docker-container --use

- name: Install Docker Buildx
run: docker buildx install

- name: Setup Golang with Cache
uses: magnetikonline/action-golang-cache@v4
with:
go-version: "1.20"

- name: Setup dependencies
shell: bash
run: make download

- name: Setup and Run Integration Tests
run: |
# Manually create folders to ensure perms are correct.
mkdir -p .kube/internal
mkdir -p .kube/external
go run github.com/magefile/mage@v1.14.0 -v CiIntegrationTests
- name: Upload JUnit Report Artifact
uses: actions/upload-artifact@v3
with:
name: integration-rest-reports
path: junit.xml
if-no-files-found: error

- name: Publish JUnit Report
uses: mikepenz/action-junit-report@v3
if: always()
with:
report_paths: junit.xml
fail_on_failure: true
require_tests: true
detailed_summary: true
token: ${{ secrets.GITHUB_TOKEN }}

go-mod-up-to-date:
name: Go Mod Up To Date
runs-on: ubuntu-22.04

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup Golang with Cache
uses: magnetikonline/action-golang-cache@v4
with:
go-version: "1.20"

- name: Download all Go modules
run: go mod download

- name: Check for tidyness of go.mod and go.sum
run: |
go mod tidy
changed=$(git status -s -uno | wc -l)
echo -e "### Git status" >> $GITHUB_STEP_SUMMARY
if [[ "$changed" -gt 0 ]]; then
echo -e "Go modules are not synchronized. Please run 'go mod tidy' and commit the changes." >> $GITHUB_STEP_SUMMARY
git status -s -uno >> $GITHUB_STEP_SUMMARY
echo -e >> $GITHUB_STEP_SUMMARY
echo -e "### Git diff" >> $GITHUB_STEP_SUMMARY
git --no-pager diff >> $GITHUB_STEP_SUMMARY
else
echo -e "Go modules are synchronized." >> $GITHUB_STEP_SUMMARY
echo -e >> $GITHUB_STEP_SUMMARY
fi
exit $changed
proto-up-to-date:
name: Proto Up To Date
runs-on: ubuntu-22.04

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install Protoc
uses: arduino/setup-protoc@v1
with:
version: '3.17.3'
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}

- name: Setup dependencies
shell: bash
run: make download

# TODO(JayF): Consider moving this into its own job, that runs under a larger set of circumstances
# since it's possible for this to fail without any go changes being made.
- name: Validate no changes in generated proto files
run: |
make proto
make dotnet
changed=$(git status -s -uno | wc -l)
echo -e "### Git status" >> $GITHUB_STEP_SUMMARY
if [[ "$changed" -gt 0 ]]; then
echo -e "Generated proto files are out of date. Please run 'make proto' and commit the changes." >> $GITHUB_STEP_SUMMARY
git status -s -uno >> $GITHUB_STEP_SUMMARY
echo -e >> $GITHUB_STEP_SUMMARY
echo -e "### Git diff" >> $GITHUB_STEP_SUMMARY
git --no-pager diff >> $GITHUB_STEP_SUMMARY
else
echo -e "Generated proto files are up to date." >> $GITHUB_STEP_SUMMARY
echo -e >> $GITHUB_STEP_SUMMARY
fi
exit $changed
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ bin/
*.test

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

# Dependency directories (remove the comment below to include it)
Expand Down
9 changes: 1 addition & 8 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -402,14 +402,7 @@ tests: gotestsum
docker run -d --name=postgres $(DOCKER_NET) -p 5432:5432 -e POSTGRES_PASSWORD=psw postgres:14.2
sleep 3
function tearDown { docker rm -f redis postgres; }; trap tearDown EXIT
$(GOTESTSUM) -- $(shell go list ./internal/... | grep -v 'jobservice/repository') \
-coverprofile internal_coverage.xml -v 2>&1 | tee test_reports/internal.txt
env JSDBTYPE=sqlite $(GOTESTSUM) -- -v \
./internal/jobservice/repository/... 2>&1 | tee -a test_reports/internal.txt
env JSDBTYPE=postgres $(GOTESTSUM) -- -v \
./internal/jobservice/repository/... 2>&1 | tee -a test_reports/internal.txt
$(GOTESTSUM) -- -coverprofile pkg_coverage.xml -v ./pkg... 2>&1 | tee test_reports/pkg.txt
$(GOTESTSUM) -- -coverprofile cmd_coverage.xml -v ./cmd... 2>&1 | tee test_reports/cmd.txt
$(GOTESTSUM) --format short-verbose --junitfile test-reports/unit-tests.xml --jsonfile test-reports/unit-tests.json -- -coverprofile=test-reports/coverage.out -covermode=atomic ./...

.ONESHELL:
lint-fix:
Expand Down

0 comments on commit 23b7ed1

Please sign in to comment.