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

ci: Add unit and functional tests using Dart beta #1786

Merged
merged 2 commits into from
Feb 7, 2024
Merged
Changes from 1 commit
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
190 changes: 190 additions & 0 deletions .github/workflows/at_server_dart_beta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
name: at_server_dart_beta
# Runs the workflow on the below events:
# On pull request raised to trunk branch.

on:
pull_request:
branches:
- trunk

env:
proot-working-directory: ./packages/at_persistence_root_server
root-working-directory: ./packages/at_root_server
psecondary-working-directory: ./packages/at_persistence_secondary_server
secondary-working-directory: ./packages/at_secondary_server
ftest-working-directory: ./tests/at_functional_test
e2etest-working-directory: ./tests/at_end2end_test
install-pkam-working-directory: ./tools/build_virtual_environment/install_PKAM_Keys

permissions: # added using https://github.com/step-security/secure-workflows
contents: read

jobs:
unit_tests_dart_beta:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 # v1.6.2
with:
sdk: beta
- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version: 'stable'
cache-dependency-path: tools/osv-scanner/go.sum

# Runs dart lint rules and unit tests on at_persistence_root_server
- name: Install dependencies in at_persistence_root_server
working-directory: ${{ env.proot-working-directory }}
run: dart pub get

- name: Run dart analyzer in at_persistence_root_server
working-directory: ${{ env.proot-working-directory }}
run: dart analyze

- name: Run tests in at_persistence_root_server
working-directory: ${{ env.proot-working-directory }}
run: dart test --concurrency=1

# Runs dart lint rules and unit tests on at_root_server
- name: Install dependencies in at_root_server
working-directory: ${{ env.root-working-directory }}
run: dart pub get

- name: Run dart analyzer in at_root_server
working-directory: ${{ env.root-working-directory }}
run: dart analyze

- name: Run tests in at_root_server
working-directory: ${{ env.root-working-directory }}
run: dart test --concurrency=1

- name: Install dependencies in at_persistence_secondary_server
working-directory: ${{ env.psecondary-working-directory }}
run: dart pub get

- name: Run dart analyzer in at_persistence_secondary_server
working-directory: ${{ env.psecondary-working-directory }}
run: dart analyze

- name: Run tests in at_persistence_secondary_server
working-directory: ${{ env.psecondary-working-directory }}
run: dart test --concurrency=1

# Runs dart lint rules and unit tests on at_secondary_server
- name: Install dependencies in at_secondary_server
working-directory: ${{ env.secondary-working-directory }}
run: dart pub get

- name: Run dart analyzer in at_secondary_server
working-directory: ${{ env.secondary-working-directory }}
run: dart analyze

- name: Run tests in at_secondary_server, with coverage
working-directory: ${{ env.secondary-working-directory }}
run: dart test --concurrency=1 --coverage="coverage"

# Runs osv-scanner to find any vulnerable Dart dependencies
# It needs to look at pubspec.lock files, which is why it's
# placed here, as the `dart pub get` above will create them
- name: Run osv-scanner
run: |
go install github.com/google/osv-scanner/cmd/osv-scanner@6316373e47d7e3e4b4fd3630c4bbc10987738de6 # v1.4.3
osv-scanner --lockfile=${{ env.proot-working-directory }}/pubspec.lock
osv-scanner --lockfile=${{ env.root-working-directory }}/pubspec.lock
osv-scanner --lockfile=${{ env.psecondary-working-directory }}/pubspec.lock
osv-scanner --lockfile=${{ env.secondary-working-directory }}/pubspec.lock

# Commenting out for now, need to investigate and fix but there are hotter fires burning right now
# - name: Convert coverage to LCOV format
# working-directory: ${{ env.secondary-working-directory }}
# run: dart pub run coverage:format_coverage --lcov --in=coverage --out=coverage.lcov --packages=.packages --report-on=lib
#
# - name: Upload coverage to Codecov
# uses: codecov/codecov-action@v3.1.0
# with:
# token: ${{secrets.CODECOV_TOKEN_AT_SERVER}}
# file: ${{ env.secondary-working-directory }}/coverage.lcov

# Runs functional tests on at_secondary.
# If tests are successful, uploads root server and secondary server binaries for subsequent jobs
functional_tests_dart_beta:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 # v1.6.2
with:
sdk: beta

- name: Install dependencies
working-directory: ${{ env.ftest-working-directory }}
run: dart pub get

- name: Run dart analyzer
working-directory: ${{ env.ftest-working-directory }}
run: dart analyze

- name: Add entry to hosts file
run: echo "127.0.0.1 vip.ve.atsign.zone" | sudo tee -a /etc/hosts

- name: Generate secondary server binary
working-directory: ${{ env.secondary-working-directory }}
run: dart pub get && dart compile exe bin/main.dart -o secondary

- name: copy secondary to tools/build_virtual_environment/ve
run: |
cp packages/at_secondary_server/secondary tools/build_virtual_environment/ve/contents/atsign/secondary/
cp packages/at_secondary_server/pubspec.yaml tools/build_virtual_environment/ve/contents/atsign/secondary/
chmod 755 tools/build_virtual_environment/ve/contents/atsign/secondary/secondary
ls -laR tools/build_virtual_environment/ve/*

- name: Build docker image
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 # v5.1.0
with:
file: tools/build_virtual_environment/ve/Dockerfile
context: tools/build_virtual_environment/ve
tags: at_virtual_env:trunk

- name: Run docker container
# -d: run container in detached mode. --rm: remove container on stop -p: bind ports to host
run: docker run -d --rm --name at_virtual_env_cont -e testingMode="true" -p 6379:6379 -p 25000-25019:25000-25019 -p 64:64 at_virtual_env:trunk

- name: Check docker readiness to load PKAM keys
working-directory: ${{ env.ftest-working-directory }}
run: dart run test/check_docker_readiness.dart

- name: Check root server readiness to load PKAM keys
working-directory: ${{ env.ftest-working-directory }}
run: dart run test/check_root_server_readiness.dart

# Set PKAM keys to the atsign's
- name: Load PKAM Keys
working-directory: ${{ env.install-pkam-working-directory }}
run: |
dart pub get
dart bin/install_PKAM_Keys.dart

# could save around 4s here using a compiled binary
- name: Check test environment readiness
working-directory: ${{ env.ftest-working-directory }}
run: dart run test/check_test_env.dart

- name: Run tests
working-directory: ${{ env.ftest-working-directory }}
run: dart run test --concurrency=1

# On push event, upload secondary server binary
- name: upload secondary server
if: ${{ github.event_name == 'push' }}
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
with:
name: secondary-server
path: packages/at_secondary_server/secondary

- name: Stop docker container
run: docker container stop at_virtual_env_cont

# Remove image created for at_virtual_env:trunk for running functional tests in pipeline.
- name: Remove docker image
run: docker rmi at_virtual_env:trunk