Skip to content

Commit

Permalink
Moved common DrevOps tests to GHA.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSkrypnyk committed Mar 1, 2024
1 parent 7bc404d commit e5808aa
Show file tree
Hide file tree
Showing 6 changed files with 206 additions and 131 deletions.
129 changes: 4 additions & 125 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -374,93 +374,17 @@ jobs:
- run: renovate
#;> RENOVATEBOT


#;============================================================================
#; DREVOPS development section. Removed during DrevOps installation/update.
#;============================================================================
#;
#; We are using CircleCI config file to both run the application tests (what
#; a consumer site would use) and DrevOps' own tests (to make sure that
#; this project is "buildable" at any time).
#;
#;< DREVOPS_DEV
#
#-----------------------------------------------------------------------------
# Test suite for DrevOps.
#-----------------------------------------------------------------------------
drevops-dev-test:
<<: *runner_config
parallelism: 1
steps:
- checkout
- *step_process_codebase_for_ci
- *step_setup_remote_docker
- *step_setup_docker_network
- run:
name: Lint DrevOps project
command: cd .drevops && ahoy lint
- run:
name: Run common tests
command: cd .drevops && DREVOPS_DEV_VOLUMES_MOUNTED=0 DREVOPS_DEV_TEST_COVERAGE_DIR=/tmp/artifacts/coverage ahoy test
no_output_timeout: 60m
- store_test_results:
path: *test_results
- store_artifacts:
path: *artifacts
- run:
name: Upload code coverage reports to Codecov
command: codecov -Z -s /tmp/artifacts/coverage

drevops-dev-test-workflow:
<<: *runner_config
parallelism: 3
resource_class: large
steps:
- checkout
- *step_process_codebase_for_ci
- *step_setup_remote_docker
- *step_setup_docker_network
- run:
name: Run workflow tests (long)
command: cd .drevops && DREVOPS_DEV_VOLUMES_MOUNTED=0 DREVOPS_DEV_TEST_COVERAGE_DIR=/tmp/artifacts/coverage ahoy test-workflow
no_output_timeout: 60m
- store_test_results:
path: *test_results
- store_artifacts:
path: *artifacts
- run:
name: Upload code coverage reports to Codecov
command: codecov -Z -s /tmp/artifacts/coverage

drevops-dev-test-deployment:
<<: *runner_config
parallelism: 2
steps:
- checkout
- *step_process_codebase_for_ci
- *step_setup_remote_docker
- *step_setup_docker_network
- add_ssh_keys:
fingerprints:
- *deploy_ssh_fingerprint
- attach_workspace:
at: /tmp/workspace
- run:
name: Run deployment tests (long)
command: cd .drevops && DREVOPS_DEV_VOLUMES_MOUNTED=0 DREVOPS_DEV_TEST_COVERAGE_DIR=/tmp/artifacts/coverage ahoy test-deployment
no_output_timeout: 60m
- store_test_results:
path: *test_results
- store_artifacts:
path: *artifacts
- run:
name: Upload code coverage reports to Codecov
command: codecov -Z -s /tmp/artifacts/coverage

# Run tests after 'build' job.
drevops-dev-test-postbuild:
# Run DrevOps tests after 'build' job to test CircleCI's configuration.
drevops-dev-test-ci-postbuild:
<<: *runner_config
parallelism: 1
steps:
- checkout
- *step_process_codebase_for_ci
Expand All @@ -477,13 +401,6 @@ jobs:
name: Upload code coverage reports to Codecov
command: codecov -Z -s /tmp/artifacts/coverage

# Deployment of feature branches and tags for DrevOps itself.
drevops-dev-deploy:
<<: *job_deploy

drevops-dev-deploy-tags:
<<: *job-deploy-tags

#-----------------------------------------------------------------------------
# Launching and testing databases stored within Docker data image.
#-----------------------------------------------------------------------------
Expand Down Expand Up @@ -625,54 +542,16 @@ workflows:
#;============================================================================
#;
#;< DREVOPS_DEV
# Run unit and functional tests for DrevOps.
# Run functional tests for DrevOps.
# Note that these jobs must run within the "commit" workflow, because they
# depend on the "build" job.
- drevops-dev-test:
filters:
tags:
only: /.*/
- drevops-dev-test-workflow:
filters:
tags:
only: /.*/
# Run deployment tests for DrevOps.
- drevops-dev-test-deployment:
filters:
tags:
only: /.*/
# Run tests after 'build' job.
- drevops-dev-test-postbuild:
- drevops-dev-test-ci-postbuild:
requires:
- build
filters:
tags:
only: /.*/
# Run actual deployment of DrevOps code to destination codebase (integration test).
# @see https://github.com/drevops/drevops-destination
- drevops-dev-deploy:
requires:
- build
- drevops-dev-test
- drevops-dev-test-workflow
filters:
branches:
# Allowed branches: 7.x, 8.x, 9.x, feature/7.x-description, feature/8.x-description, feature/9.x-description
only: /main|develop|7\.x|feature\/(?:7\.x)[a-zA-z0-9\-\.\,]+/
tags:
ignore: /.*/
# Run actual deployment of DrevOps code to destination codebase (integration test).
# @see https://github.com/drevops/drevops-destination
- drevops-dev-deploy-tags:
requires:
- build
- drevops-dev-test
- drevops-dev-test-workflow
filters:
branches:
ignore: /.*/
tags:
only: /^[0-9]+(\.[0-9]+)+(-rc[0-9]+)?$/

# Test workflow to test DREVOPS_DB_DOCKER_IMAGE workflow for DB from file.
drevops-dev-didi-fi:
Expand Down
2 changes: 1 addition & 1 deletion .drevops/tests/bats/circleci.bats
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ load _helper.bash
load _helper.circleci.bash

@test "CircleCI artifacts are saved" {
if [ -z "${CI}" ]; then
if [ -z "${CIRCLECI}" ]; then
skip "This test is only run on CircleCI"
fi

Expand Down
2 changes: 1 addition & 1 deletion .drevops/tests/test.deployment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ TEST_DIR="${ROOT_DIR}/.drevops/tests"
# Create stub of local framework.
docker network create amazeeio-network 2>/dev/null || true

index="${CIRCLE_NODE_INDEX:-*}"
index="${TEST_NODE_INDEX:-*}"
echo "==> Run deployment functional tests (${index})."
[ ! -d "${TEST_DIR}/node_modules" ] && echo " > Install test Node dependencies." && npm --prefix="${TEST_DIR}" ci

Expand Down
6 changes: 4 additions & 2 deletions .drevops/tests/test.workflow.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ TEST_DIR="${ROOT_DIR}/.drevops/tests"
# Create stub of local framework.
docker network create amazeeio-network 2>/dev/null || true

index="${CIRCLE_NODE_INDEX:-*}"
index="${TEST_NODE_INDEX:-*}"
echo "==> Run workflow functional tests (${index})."
[ ! -d "${TEST_DIR}/node_modules" ] && echo " > Install test Node dependencies." && npm --prefix="${TEST_DIR}" ci

Expand Down Expand Up @@ -61,7 +61,9 @@ case ${index} in
bats "${TEST_DIR}"/bats/workflow.smoke.bats
bats "${TEST_DIR}"/bats/workflow.install.bats
bats "${TEST_DIR}"/bats/workflow.storage.image.bats
bats "${TEST_DIR}"/bats/workflow.storage.image_cached.bats
# Disabled due to intermittent failures.
# @see https://github.com/drevops/drevops/issues/893
# bats "${TEST_DIR}"/bats/workflow.storage.image_cached.bats
bats "${TEST_DIR}"/bats/workflow.storage.curl.bats
bats "${TEST_DIR}"/bats/workflow.utilities.bats
;;
Expand Down
192 changes: 192 additions & 0 deletions .github/workflows/drevops-test-common.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
# This action is used for DrevOps maintenance. It will not be used in the scaffolded project.
name: DrevOps - Test

on:
push:
branches:
- develop
pull_request:
branches:
- develop
- 'feature/**'

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
drevops-test-common:
runs-on: ubuntu-latest

container:
image: drevops/ci-runner:latest
env:
# Prevent GitHub overriding the Docker config.
DOCKER_CONFIG: /root/.docker
DREVOPS_DOCTOR_CHECK_MINIMAL: 1
TEST_GITHUB_TOKEN: ${{ secrets.TEST_GITHUB_TOKEN }}
TEST_DOCKER_USER: ${{ secrets.TEST_DOCKER_USER }}
TEST_DOCKER_PASS: ${{ secrets.TEST_DOCKER_PASS }}
DREVOPS_DEV_VOLUMES_MOUNTED: 0
DREVOPS_DEV_TEST_COVERAGE_DIR: /tmp/.drevops-coverage-html

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false

- name: Process codebase to run in CI
run: find . -name "docker-compose.yml" -print0 | xargs -0 -I {} sh -c "sed -i -e ''/###/d'' {} && sed -i -e ''s/##//'' {}"

- name: Adjust git config to allow running git-related tests
run: git config --global safe.directory '*'

- name: Generate test SSH key pair used for deployment tests
run: |
mkdir -p $HOME/.ssh
ssh-keygen -t rsa -b 4096 -m PEM -N '' -f $HOME/.ssh/id_rsa
chmod 600 $HOME/.ssh/id_rsa
echo "$(ssh-agent -a ${HOME}/ssh-agent.sock)" > ssh-agent-output
export SSH_AUTH_SOCK=$(grep SSH_AUTH_SOCK ssh-agent-output | cut -d';' -f1 | cut -d= -f2)
echo "SSH_AUTH_SOCK=${SSH_AUTH_SOCK}" >> $GITHUB_ENV
- name: Install dependencies
run: npm ci
working-directory: .drevops/tests

- name: Lint code
run: |
./tests/lint.scripts.sh
./tests/lint.dockerfiles.sh
./tests/lint.spelling.sh
working-directory: .drevops

- name: Run tests
run: ./tests/test.common.sh
working-directory: .drevops

- name: Upload coverage report as an artifact
uses: actions/upload-artifact@v4
with:
name: ${{github.job}}-code-coverage-report
path: /tmp/.drevops-coverage-html

- name: Upload coverage report to Codecov
uses: codecov/codecov-action@v4
with:
directory: /tmp/.drevops-coverage-html
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}

drevops-test-workflow:
runs-on: ubuntu-latest

strategy:
matrix:
batch: [0, 1, 2]

container:
image: drevops/ci-runner:latest
env:
# Prevent GitHub overriding the Docker config.
DOCKER_CONFIG: /root/.docker
DREVOPS_DOCTOR_CHECK_MINIMAL: 1
TEST_GITHUB_TOKEN: ${{ secrets.TEST_GITHUB_TOKEN }}
TEST_DOCKER_USER: ${{ secrets.TEST_DOCKER_USER }}
TEST_DOCKER_PASS: ${{ secrets.TEST_DOCKER_PASS }}
DREVOPS_DEV_VOLUMES_MOUNTED: 0
DREVOPS_DEV_TEST_COVERAGE_DIR: /tmp/.drevops-coverage-html
TEST_NODE_INDEX: ${{ matrix.batch }}

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false

- name: Adjust git config to allow running git-related tests
run: git config --global safe.directory '*'

- name: Install dependencies
run: npm ci
working-directory: .drevops/tests

- name: Run tests
run: ./tests/test.workflow.sh
working-directory: .drevops

- name: Upload coverage report as an artifact
uses: actions/upload-artifact@v4
with:
name: ${{github.job}}-${{ matrix.batch }}-code-coverage-report
path: /tmp/.drevops-coverage-html

- name: Upload coverage report to Codecov
uses: codecov/codecov-action@v4
with:
directory: /tmp/.drevops-coverage-html
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}

drevops-test-deployment:
runs-on: ubuntu-latest

strategy:
matrix:
batch: [0, 1]

container:
image: drevops/ci-runner:latest
env:
# Prevent GitHub overriding the Docker config.
DOCKER_CONFIG: /root/.docker
DREVOPS_DOCTOR_CHECK_MINIMAL: 1
TEST_GITHUB_TOKEN: ${{ secrets.TEST_GITHUB_TOKEN }}
TEST_DOCKER_USER: ${{ secrets.TEST_DOCKER_USER }}
TEST_DOCKER_PASS: ${{ secrets.TEST_DOCKER_PASS }}
DREVOPS_DEV_VOLUMES_MOUNTED: 0
DREVOPS_DEV_TEST_COVERAGE_DIR: /tmp/.drevops-coverage-html
TEST_NODE_INDEX: ${{ matrix.batch }}

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false

- name: Adjust git config to allow running git-related tests
run: git config --global safe.directory '*'

- name: Generate test SSH key pair used for deployment tests
run: |
mkdir -p $HOME/.ssh
ssh-keygen -t rsa -b 4096 -m PEM -N '' -f $HOME/.ssh/id_rsa
chmod 600 $HOME/.ssh/id_rsa
echo "$(ssh-agent -a ${HOME}/ssh-agent.sock)" > ssh-agent-output
export SSH_AUTH_SOCK=$(grep SSH_AUTH_SOCK ssh-agent-output | cut -d';' -f1 | cut -d= -f2)
echo "SSH_AUTH_SOCK=${SSH_AUTH_SOCK}" >> $GITHUB_ENV
- name: Install dependencies
run: npm ci
working-directory: .drevops/tests

- name: Run tests
run: ./tests/test.deployment.sh
working-directory: .drevops

- name: Upload coverage report as an artifact
uses: actions/upload-artifact@v4
with:
name: ${{github.job}}-${{ matrix.batch }}-code-coverage-report
path: /tmp/.drevops-coverage-html

- name: Upload coverage report to Codecov
uses: codecov/codecov-action@v4
with:
directory: /tmp/.drevops-coverage-html
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
Loading

0 comments on commit e5808aa

Please sign in to comment.