Skip to content

Commit

Permalink
Use cargo-careful for unit and E2E tests on CI
Browse files Browse the repository at this point in the history
  • Loading branch information
tyranron committed Oct 6, 2022
1 parent d8daaea commit 817aa11
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 21 deletions.
73 changes: 58 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ jobs:
- helm-lint
- rustdoc
- rustfmt
- test-e2e
- test-e2e-debug
- test-e2e-release
- test-unit
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -64,7 +65,7 @@ jobs:
- run: make cargo.lint

helm-lint:
name: Lint Helm chart
name: lint Helm chart
if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
strategy:
fail-fast: false
Expand Down Expand Up @@ -97,8 +98,35 @@ jobs:
# Testing #
###########

test-e2e:
name: E2E tests
test-e2e-debug: # as a separate CI job to omit waiting `docker` CI job
name: test E2E (debug)
if: ${{ !startsWith(github.ref, 'refs/tags/helm/') }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
components: rust-src
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ env.RUST_VER }}
override: true
- uses: Swatinem/rust-cache@v1
if: ${{ env.CACHE == 'true' }}

- run: cargo install cargo-careful

- run: make up background=yes dockerized=no
debug=yes careful=yes
- run: sleep 5

- run: make test.e2e start-app=no

test-e2e-release:
name: test E2E (release)
if: ${{ !startsWith(github.ref, 'refs/tags/helm/') }}
needs: ["docker"]
runs-on: ubuntu-latest
Expand All @@ -113,8 +141,8 @@ jobs:
if: ${{ env.CACHE == 'true' }}
- uses: satackey/action-docker-layer-caching@v0.0.11
with:
key: test-e2e-{hash}
restore-keys: test-e2e-
key: test-e2e-release-{hash}
restore-keys: test-e2e-release-
continue-on-error: true
timeout-minutes: 10
if: ${{ env.CACHE == 'true' }}
Expand All @@ -125,24 +153,38 @@ jobs:
path: .cache/docker/
- run: make docker.untar

- run: make test.e2e start-app=yes dockerized=yes
tag=build-${{ github.run_number }}
- run: make up background=yes dockerized=yes
tag=build-${{ github.run_number }}
- run: sleep 5

- run: make test.e2e start-app=no

test-unit:
name: Unit tests
name: test unit
if: ${{ !startsWith(github.ref, 'refs/tags/helm/') }}
strategy:
fail-fast: false
matrix:
toolchain: ["stable", "nightly"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ env.RUST_VER }}
toolchain: ${{ (matrix.toolchain == 'stable' && env.RUST_VER)
|| matrix.toolchain }}
components: rust-src
override: true
- uses: Swatinem/rust-cache@v1
if: ${{ env.CACHE == 'true' }}

- run: cargo install cargo-careful
if: ${{ matrix.toolchain == 'nightly' }}

- run: make test.unit
careful=${{ (matrix.toolchain == 'nightly' && 'yes')
|| 'no' }}



Expand Down Expand Up @@ -194,11 +236,11 @@ jobs:
#############

release-docker:
name: Release Docker image
name: release Docker image
if: ${{ github.event_name == 'push'
&& (github.ref == 'refs/heads/main'
|| startsWith(github.ref, 'refs/tags/v')) }}
needs: ["docker", "test-e2e"]
needs: ["docker", "test-e2e-release"]
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -306,14 +348,15 @@ jobs:
&& matrix.registry == 'quay.io' }}

release-github:
name: Release on GitHub
name: release on GitHub
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
needs:
- clippy
- release-docker
- rustdoc
- rustfmt
- test-e2e
- test-e2e-debug
- test-e2e-release
- test-unit
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -349,7 +392,7 @@ jobs:
prerelease: ${{ contains(steps.semver.outputs.group1, '-') }}

release-helm:
name: Release Helm chart
name: release Helm chart
if: ${{ startsWith(github.ref, 'refs/tags/helm/') }}
needs: ["helm-lint"]
strategy:
Expand Down
37 changes: 31 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ endif
# Usage:
# make up [background=(no|yes)]
# [debug=(yes|no)]
# [( [dockerized=no]
# [( [dockerized=no] [careful=(no|yes)]
# | dockerized=yes [tag=(dev|<docker-tag>)]
# [( [rebuild=no] | rebuild=yes [no-cache=(no|yes)] )] )]

Expand All @@ -91,7 +91,23 @@ endif
-v "$(PWD)/.cache/baza/":/.cache/baza/:z \
$(OWNER)/$(NAME):$(or $(tag),dev) -r .cache/baza
else
cargo run $(if $(call eq,$(debug),no),--release,) -- -r .cache/baza \
ifneq ($(debug),no)
ifeq ($(careful),yes)
ifeq ($(shell cargo install --list | grep cargo-careful),)
cargo install cargo-careful
endif
ifeq ($(shell rustup component list --toolchain=nightly \
| grep 'rust-src (installed)'),)
rustup component add --toolchain=nightly rust-src
endif
endif
endif
ifeq ($(background),yes)
cargo $(if $(call eq,$(careful),yes),+nightly careful,) run \
$(if $(call eq,$(debug),no),--release,) -- --help > /dev/null
endif
cargo $(if $(call eq,$(careful),yes),+nightly careful,) run \
$(if $(call eq,$(debug),no),--release,) -- -r .cache/baza \
$(if $(call eq,$(background),yes),&,)
endif

Expand Down Expand Up @@ -150,14 +166,14 @@ cargo.lint:
# make test.e2e [only=<regex>]
# [( [start-app=no]
# | start-app=yes [debug=(yes|no)]
# [( [dockerized=no]
# [( [dockerized=no] [careful=(no|yes)]
# | dockerized=yes [tag=(dev|<docker-tag>)]
# [( [rebuild=no] |
# rebuild=yes [no-cache=(no|yes)] )] )] )]

test.e2e:
ifeq ($(start-app),yes)
@make up background=yes debug=$(debug) \
@make up background=yes debug=$(debug) careful=$(careful) \
dockerized=$(dockerized) tag=$(tag) \
rebuild=$(rebuild) no-cache=$(no-cache)
sleep 5
Expand All @@ -172,10 +188,19 @@ endif
# Run project unit tests.
#
# Usage:
# make test.unit [crate=<crate-name>]
# make test.unit [crate=<crate-name>] [careful=(no|yes)]

test.unit:
cargo test \
ifeq ($(careful),yes)
ifeq ($(shell cargo install --list | grep cargo-careful),)
cargo install cargo-careful
endif
ifeq ($(shell rustup component list --toolchain=nightly \
| grep 'rust-src (installed)'),)
rustup component add --toolchain=nightly rust-src
endif
endif
cargo $(if $(call eq,$(careful),yes),+nightly careful,) test \
$(if $(call eq,$(crate),),--workspace --exclude baza-e2e,-p $(crate)) \
--all-features

Expand Down

0 comments on commit 817aa11

Please sign in to comment.