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

Implement Local Hub integration tests as separate job #683

Merged
merged 11 commits into from
Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
20 changes: 19 additions & 1 deletion .github/workflows/branch-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,24 @@ jobs:
run: |
make release-latest-binaries

local-hub-tests:
name: Local Hub integration tests
runs-on: ubuntu-latest
needs: [ entry-tests, build-app, build-tests ]
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup environment
run: |
. ./hack/ci/setup-env.sh
- name: Run local Hub integration tests
env:
BUILD_IMAGES: "false"
run: |
make test-local-hub

integration-tests:
name: Integration tests
runs-on: ubuntu-latest
Expand Down Expand Up @@ -299,7 +317,7 @@ jobs:
slackNotification:
name: Slack Notification
runs-on: ubuntu-latest
needs: [ update-cluster, integration-tests ]
needs: [ update-cluster, local-hub-tests, integration-tests ]
if: failure()
steps:
- name: Slack Notification
Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/pr-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,30 @@ jobs:
path: ${{ github.workspace }}/bin/capact_linux_amd64/capact
retention-days: 1 # Default 90 days

local-hub-tests:
name: Local Hub integration tests
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
needs: [ push-apps, push-tests, build-cli ]
permissions:
contents: read

steps:
- name: Checkout code
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Setup environment
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
. ./hack/ci/setup-env.sh
- name: Run local Hub integration tests
env:
BUILD_IMAGES: "false"
run: |
make test-local-hub

integration-tests:
name: Integration tests
runs-on: ubuntu-latest
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ all: generate build-all-images test-unit test-lint ## Default: generate all, bui
############

APPS = gateway k8s-engine hub-js argo-runner helm-runner cloudsql-runner populator terraform-runner argo-actions gitlab-api-runner secret-storage-backend helm-storage-backend
TESTS = e2e
TESTS = e2e local-hub
INFRA = json-go-gen graphql-schema-linter jinja2 merger

build-all-tools: ## Builds the standalone binaries for all tools
Expand Down Expand Up @@ -124,6 +124,10 @@ test-lint: ## Run linters on the codebase
./hack/lint.sh
.PHONY: test-lint

test-local-hub:
pkosiec marked this conversation as resolved.
Show resolved Hide resolved
./hack/test-local-hub.sh
.PHONY: test-local-hub

test-integration:
./hack/test-integration.sh
.PHONY: test-integration
Expand Down
3 changes: 1 addition & 2 deletions hack/ci/setup-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ CERT_NUMBER_TO_BACKUP=1
CERT_SERVICE_NAMESPACE=capact-system
EOT


if [ "${GITHUB_EVENT_NAME}" = "pull_request_target" ]
then
echo "DOCKER_TAG=PR-${PR_NUMBER}" >> "$GITHUB_ENV"
Expand All @@ -37,6 +36,6 @@ fi
# TODO: Read components to build in automated way, e.g. from directory structure
cat <<EOT >>"$GITHUB_ENV"
APPS=name=matrix::{"include":[{"APP":"gateway"},{"APP":"k8s-engine"},{"APP":"hub-js"},{"APP":"argo-runner"},{"APP":"helm-runner"},{"APP":"populator"},{"APP":"terraform-runner"},{"APP":"argo-actions"},{"APP":"gitlab-api-runner"},{"APP":"secret-storage-backend"},{"APP":"helm-storage-backend"}]}
TESTS=name=matrix::{"include":[{"TEST":"e2e"}]}
TESTS=name=matrix::{"include":[{"TEST":"e2e"}, {"TEST":"local-hub"}]}
INFRAS=name=matrix::{"include":[{"INFRA":"json-go-gen"},{"INFRA":"graphql-schema-linter"},{"INFRA":"jinja2"},{"INFRA":"merger"}]}
EOT
45 changes: 45 additions & 0 deletions hack/test-local-hub.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env bash
#
# This script provisions testing environment for local Hub using docker-compose
# and execute tests.
#
# It requires Docker to be installed.

# standard bash error handling
set -o nounset # treat unset variables as an error and exit immediately.
set -o errexit # exit immediately when a command fails.

CURRENT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
REPO_ROOT_DIR=$(cd "${CURRENT_DIR}/.." && pwd)

# shellcheck source=./hack/lib/utilities.sh
source "${CURRENT_DIR}/lib/utilities.sh" || { echo 'Cannot load CI utilities.'; exit 1; }
# shellcheck source=./hack/lib/const.sh
source "${CURRENT_DIR}/lib/const.sh" || { echo 'Cannot load constant values.'; exit 1; }

build_images() {
export DOCKER_TAG=$RANDOM
export DOCKER_REPOSITORY="local"

local make_targets=("build-test-image-local-hub" "build-app-image-hub-js" "build-app-image-secret-storage-backend")
for make_target in "${make_targets[@]}"
do
cd "${REPO_ROOT_DIR}" && make "${make_target}"
done
}

main() {
if [[ "${BUILD_IMAGES:-"true"}" == "true" ]]; then
build_images
fi

docker-compose -f "${REPO_ROOT_DIR}/test/local-hub/docker-compose.yml" up --exit-code-from tests --force-recreate
}

cleanup() {
docker-compose -f "${REPO_ROOT_DIR}/test/local-hub/docker-compose.yml" down
}

trap cleanup EXIT

main
Loading