Refactor functions and wrapup

Signed-off-by: Kiran Parajuli <kiranparajuli589@gmail.com>
This commit is contained in:
Kiran Parajuli
2022-08-03 17:58:30 +05:45
parent fa32f76f5d
commit f3e47ea5da
6 changed files with 178 additions and 195 deletions

View File

@@ -41,9 +41,11 @@ DEFAULT_PHP_VERSION = "7.4"
DEFAULT_NODEJS_VERSION = "14"
dirs = {
"core": "/drone/src/oc10/testrunner",
"testing_app": "/drone/src/oc10/testing",
"base": "/drone/src",
"web": "/drone/src/webTestRunner",
# relative paths from /drone/src
"core": "oc10/testrunner",
"testing_app": "oc10/testing",
}
# configuration
@@ -160,6 +162,9 @@ pipelineVolumeGo = \
# minio mc environment variables
MINIO_MC_ENV = {
"CACHE_BUCKET": {
"from_secret": "cache_public_s3_bucket",
},
"MC_HOST": {
"from_secret": "cache_s3_endpoint",
},
@@ -213,8 +218,7 @@ def main(ctx):
test_pipelines = \
cancelPreviousBuilds() + \
buildCacheWeb() + \
yarnCache(ctx) + \
buildCacheWeb(ctx) + \
[buildOcisBinaryForTesting(ctx)] + \
cacheCoreReposForTesting(ctx) + \
testOcisModules(ctx) + \
@@ -233,13 +237,19 @@ def main(ctx):
test_pipelines.append(
pipelineDependsOn(
purgeBuildArtifactCache(ctx, "tests-yarn"),
purgeBuildArtifactCache(ctx, "ocis-binary-amd64"),
testPipelines(ctx),
),
)
test_pipelines.append(
pipelineDependsOn(
purgeBuildArtifactCache(ctx, "ocis-binary-amd64"),
purgeBuildArtifactCache(ctx, "testrunner"),
testPipelines(ctx),
),
)
test_pipelines.append(
pipelineDependsOn(
purgeBuildArtifactCache(ctx, "testing_app"),
testPipelines(ctx),
),
)
@@ -270,12 +280,15 @@ def main(ctx):
pipelineSanityChecks(ctx, pipelines)
return pipelines
def buildCacheWeb():
def buildCacheWeb(ctx):
return [{
"kind": "pipeline",
"type": "docker",
"name": "cache-web",
"steps": performWebCache(),
"clone": {
"disable": True,
},
"steps": performWebCache(ctx),
"trigger": {
"ref": [
"refs/heads/master",
@@ -285,49 +298,6 @@ def buildCacheWeb():
},
}]
def yarnCache(ctx):
return [{
"kind": "pipeline",
"type": "docker",
"name": "cache-yarn",
"steps": skipIfUnchanged(ctx, "cache") +
restoreWebCache() +
yarnInstallUITests() +
rebuildBuildArtifactCache(ctx, "tests-yarn", "%s/tests/acceptance/.yarn" % dirs["web"]),
"depends_on": getPipelineNames(buildCacheWeb()),
"trigger": {
"ref": [
"refs/heads/master",
"refs/pull/**",
],
},
}]
def yarnInstallUITests():
return [{
"name": "yarn-install",
"image": OC_CI_NODEJS % DEFAULT_NODEJS_VERSION,
"commands": [
". /drone/src/.drone.env",
"cd %s" % dirs["web"],
"git checkout $WEB_COMMITID",
"cd tests/acceptance/",
"retry -t 3 'yarn install --immutable'",
],
}]
def yarnInstallE2eTests():
return [{
"name": "yarn-install-e2e",
"image": OC_CI_NODEJS % DEFAULT_NODEJS_VERSION,
"commands": [
". /drone/src/.drone.env",
"cd webTestRunner",
"git checkout $WEB_COMMITID",
"retry -t 3 'yarn install --immutable'",
],
}]
def testOcisModules(ctx):
pipelines = []
for module in config["modules"]:
@@ -488,7 +458,10 @@ def cacheCoreReposForTesting(ctx):
"os": "linux",
"arch": "amd64",
},
"steps": performCoreReposCache(),
"steps": skipIfUnchanged(ctx, "acceptance-tests") + # skip for those pipelines where core repos are not needed
cloneCoreRepos() +
rebuildBuildArtifactCache(ctx, "testrunner", dirs["core"]) +
rebuildBuildArtifactCache(ctx, "testing_app", dirs["testing_app"]),
"trigger": {
"ref": [
"refs/heads/master",
@@ -604,8 +577,8 @@ def localApiTests(ctx, storage, suite, accounts_hash_difficulty = 4):
"steps": skipIfUnchanged(ctx, "acceptance-tests") +
restoreBuildArtifactCache(ctx, "ocis-binary-amd64", "ocis/bin") +
ocisServer(storage, accounts_hash_difficulty) +
restoreCoreCache() +
restoreTestingAppCache() +
restoreBuildArtifactCache(ctx, "testrunner", dirs["core"]) +
restoreBuildArtifactCache(ctx, "testing_app", dirs["testing_app"]) +
[
{
"name": "localApiTests-%s-%s" % (suite, storage),
@@ -613,10 +586,10 @@ def localApiTests(ctx, storage, suite, accounts_hash_difficulty = 4):
"environment": {
"TEST_WITH_GRAPH_API": "true",
"PATH_TO_OCIS": "/drone/src",
"PATH_TO_CORE": dirs["core"],
"PATH_TO_CORE": "/drone/src/%s" % dirs["core"],
"TEST_SERVER_URL": "https://ocis-server:9200",
"OCIS_REVA_DATA_ROOT": "%s" % ("/srv/app/tmp/ocis/owncloud/data/" if storage == "owncloud" else ""),
"SKELETON_DIR": dirs["testing_app"],
"SKELETON_DIR": "/drone/src/%s/data/apiSkeleton" % dirs["testing_app"],
"OCIS_SKELETON_STRATEGY": "%s" % ("copy" if storage == "owncloud" else "upload"),
"TEST_OCIS": "true",
"SEND_SCENARIO_LINE_REFERENCES": "true",
@@ -694,8 +667,8 @@ def coreApiTests(ctx, part_number = 1, number_of_parts = 1, storage = "ocis", ac
"steps": skipIfUnchanged(ctx, "acceptance-tests") +
restoreBuildArtifactCache(ctx, "ocis-binary-amd64", "ocis/bin") +
ocisServer(storage, accounts_hash_difficulty) +
restoreCoreCache() +
restoreTestingAppCache() +
restoreBuildArtifactCache(ctx, "testrunner", dirs["core"]) +
restoreBuildArtifactCache(ctx, "testing_app", dirs["testing_app"]) +
[
{
"name": "oC10ApiTests-%s-storage-%s" % (storage, part_number),
@@ -703,10 +676,10 @@ def coreApiTests(ctx, part_number = 1, number_of_parts = 1, storage = "ocis", ac
"environment": {
"TEST_WITH_GRAPH_API": "true",
"PATH_TO_OCIS": "/drone/src",
"PATH_TO_CORE": dirs["core"],
"PATH_TO_CORE": "/drone/src/%s" % dirs["core"],
"TEST_SERVER_URL": "https://ocis-server:9200",
"OCIS_REVA_DATA_ROOT": "%s" % ("/srv/app/tmp/ocis/owncloud/data/" if storage == "owncloud" else ""),
"SKELETON_DIR": "%s/data/apiSkeleton" % dirs["testing_app"],
"SKELETON_DIR": "/drone/src/%s/data/apiSkeleton" % dirs["testing_app"],
"OCIS_SKELETON_STRATEGY": "%s" % ("copy" if storage == "owncloud" else "upload"),
"TEST_OCIS": "true",
"SEND_SCENARIO_LINE_REFERENCES": "true",
@@ -718,7 +691,7 @@ def coreApiTests(ctx, part_number = 1, number_of_parts = 1, storage = "ocis", ac
"UPLOAD_DELETE_WAIT_TIME": "1" if storage == "owncloud" else 0,
},
"commands": [
"make -C %s test-acceptance-api" % dirs["core"],
"make -C /drone/src/%s test-acceptance-api" % dirs["core"],
],
},
] + failEarly(ctx, early_fail),
@@ -809,11 +782,10 @@ def uiTestPipeline(ctx, filterTags, early_fail, runPart = 1, numberOfParts = 1,
"steps": skipIfUnchanged(ctx, "acceptance-tests") +
restoreBuildArtifactCache(ctx, "ocis-binary-amd64", "ocis/bin") +
restoreWebCache() +
restoreBuildArtifactCache(ctx, "tests-yarn", "%s/tests/acceptance/.yarn" % dirs["web"]) +
yarnInstallUITests() +
restoreWebAcceptanceYarnCache() +
ocisServer(storage, accounts_hash_difficulty) +
waitForSeleniumService() + waitForMiddlewareService() +
restoreTestingAppCache() +
restoreBuildArtifactCache(ctx, "testing_app", dirs["testing_app"]) +
[
{
"name": "webUITests",
@@ -823,7 +795,7 @@ def uiTestPipeline(ctx, filterTags, early_fail, runPart = 1, numberOfParts = 1,
"BACKEND_HOST": "https://ocis-server:9200",
"RUN_ON_OCIS": "true",
"OCIS_REVA_DATA_ROOT": "/srv/app/tmp/ocis/owncloud/data",
"TESTING_DATA_DIR": dirs["testing_app"],
"TESTING_DATA_DIR": "/drone/src/%s" % dirs["testing_app"],
"WEB_UI_CONFIG": "/drone/src/tests/config/drone/ocis-config.json",
"TEST_TAGS": finalFilterTags,
"LOCAL_UPLOAD_DIR": "/uploads",
@@ -893,8 +865,8 @@ def e2eTests(ctx):
e2eTestsSteps = \
skipIfUnchanged(ctx, "e2e-tests") + \
restoreBuildArtifactCache(ctx, "ocis-binary-amd64", "ocis/bin/ocis") + \
restoreBuildArtifactCache(ctx, "web-dist", "webTestRunner") + \
yarnInstallE2eTests() + \
restoreWebCache() + \
restoreWebE2EYarnCache() + \
ocisServer("ocis", 4, []) + \
e2e_test_ocis + \
uploadTracingResult(ctx) + \
@@ -997,6 +969,8 @@ def settingsUITests(ctx, storage = "ocis", accounts_hash_difficulty = 4):
ocisServer(storage, accounts_hash_difficulty) +
waitForSeleniumService() +
waitForMiddlewareService() +
restoreWebCache() +
restoreWebAcceptanceYarnCache() +
[
{
"name": "WebUIAcceptanceTests",
@@ -1010,16 +984,11 @@ def settingsUITests(ctx, storage = "ocis", accounts_hash_difficulty = 4):
"TEST_TAGS": "not @skipOnOCIS and not @skip",
"LOCAL_UPLOAD_DIR": "/uploads",
"NODE_TLS_REJECT_UNAUTHORIZED": 0,
"WEB_PATH": "/srv/app/web",
"WEB_PATH": dirs["web"],
"FEATURE_PATH": "/drone/src/services/settings/ui/tests/acceptance/features",
"MIDDLEWARE_HOST": "http://middleware:3000",
},
"commands": [
". /drone/src/.drone.env",
# we need to have Web around for some general step definitions (eg. how to log in)
"git clone -b $WEB_BRANCH --single-branch --no-tags https://github.com/owncloud/web.git /srv/app/web",
"cd /srv/app/web",
"git checkout $WEB_COMMITID",
# TODO: settings/package.json has all the acceptance test dependencies
# they shouldn't be needed since we could also use them from web:/tests/acceptance/package.json
"cd /drone/src/services/settings",
@@ -1952,6 +1921,23 @@ def waitForMiddlewareService():
],
}]
def cloneCoreRepos():
return [
{
"name": "clone-core-repos",
"image": OC_CI_ALPINE,
"commands": [
"source .drone.env",
"git clone -b master --depth=1 https://github.com/owncloud/testing.git %s" % dirs["testing_app"],
"ls -la %s" % dirs["testing_app"],
"git clone -b $CORE_BRANCH --single-branch --no-tags https://github.com/owncloud/core.git %s" % dirs["core"],
"ls -la %s" % dirs["core"],
"cd %s" % dirs["core"],
"git checkout $CORE_COMMITID",
],
},
]
def redis():
return [
{
@@ -2429,8 +2415,8 @@ def parallelDeployAcceptancePipeline(ctx):
},
"steps": skipIfUnchanged(ctx, "acceptance-tests") +
restoreBuildArtifactCache(ctx, "ocis-binary-amd64", "ocis/bin") +
restoreCoreCache() +
restoreTestingAppCache() +
restoreBuildArtifactCache(ctx, "testrunner", dirs["core"]) +
restoreBuildArtifactCache(ctx, "testing_app", dirs["testing_app"]) +
copyConfigs() +
parallelDeploymentOC10Server() +
owncloudLog() +
@@ -2482,8 +2468,8 @@ def parallelAcceptance(env):
"REVA_LDAP_BASE_DN": "dc=owncloud,dc=com",
"REVA_LDAP_HOSTNAME": "openldap",
"REVA_LDAP_BIND_DN": "cn=admin,dc=owncloud,dc=com",
"SKELETON_DIR": "%s/data/apiSkeleton" % dirs["testing_app"],
"PATH_TO_CORE": dirs["core"],
"SKELETON_DIR": "/drone/src/%s/data/apiSkeleton" % dirs["testing_app"],
"PATH_TO_CORE": "/drone/src/%s" % dirs["core"],
"OCIS_REVA_DATA_ROOT": "/mnt/data/",
"EXPECTED_FAILURES_FILE": "/drone/src/tests/parallelDeployAcceptance/expected-failures-API.md",
"OCIS_SKELETON_STRATEGY": "copy",
@@ -2786,13 +2772,47 @@ def setupForLitmus():
],
}]
def performWebCache():
def performWebCache(ctx):
ocis_git_base_url = "https://raw.githubusercontent.com/owncloud/ocis"
path_to_drone_env = "%s/%s/.drone.env" % (ocis_git_base_url, ctx.build.commit)
path_to_check_script = "%s/%s/tests/config/drone/check_web_cache.sh" % (ocis_git_base_url, ctx.build.commit)
return [
{
"name": "clone-web",
"name": "get-drone-env-and-check-script",
"image": OC_UBUNTU,
"commands": [
"bash -x ./tests/config/drone/clone_web.sh",
"curl -s -o .drone.env %s" % path_to_drone_env,
"cat .drone.env",
"curl -s -o check_web_cache.sh %s" % path_to_check_script,
"chmod +x check_web_cache.sh",
"cat check_web_cache.sh",
],
},
{
"name": "check-for-web-cache",
"image": OC_UBUNTU,
"environment": {
"CACHE_ENDPOINT": {
"from_secret": "cache_public_s3_server",
},
"CACHE_BUCKET": {
"from_secret": "cache_public_s3_bucket",
},
},
"commands": [
"bash check_web_cache.sh",
],
},
{
"name": "clone-web",
"image": OC_CI_NODEJS % DEFAULT_NODEJS_VERSION,
"commands": [
". ./.drone.env",
"rm -rf /drone/src/webTestRunner",
"git clone -b $WEB_BRANCH --single-branch --no-tags https://github.com/owncloud/web.git webTestRunner",
"cd webTestRunner && git checkout $WEB_COMMITID",
"ls -la",
],
},
{
@@ -2800,60 +2820,36 @@ def performWebCache():
"image": MINIO_MC,
"environment": MINIO_MC_ENV,
"commands": [
"bash -x ./tests/config/drone/cache_web.sh",
"source ./.drone.env",
# cache using the minio/mc client to the 'owncloud' bucket (long term bucket)
"mc alias set s3 $MC_HOST $AWS_ACCESS_KEY_ID $AWS_SECRET_ACCESS_KEY",
"mc mirror --overwrite --remove webTestRunner s3/$CACHE_BUCKET/ocis/web-test-runner/$WEB_COMMITID",
],
"depends_on": ["clone-web"],
},
]
def performCoreReposCache():
return [
{
"name": "clone-core-repos",
"image": OC_UBUNTU,
"name": "install-yarn",
"image": OC_CI_NODEJS % DEFAULT_NODEJS_VERSION,
"commands": [
"bash -x ./tests/config/drone/clone_core_repos.sh",
"cd %s/webTestRunner" % dirs["base"],
"retry -t 3 'yarn install --immutable --frozen-lockfile'",
"cd %s/webTestRunner/tests/acceptance" % dirs["base"],
"retry -t 3 'yarn install --immutable --frozen-lockfile'",
],
},
{
"name": "cache-core-repos",
"name": "cache-yarn",
"image": MINIO_MC,
"environment": MINIO_MC_ENV,
"commands": [
"bash -x ./tests/config/drone/cache_core_repos.sh",
],
"depends_on": [
"clone-core-repos",
"source ./.drone.env",
# cache using the minio/mc client to the 'owncloud' bucket (long term bucket)
"mc alias set s3 $MC_HOST $AWS_ACCESS_KEY_ID $AWS_SECRET_ACCESS_KEY",
"mc mirror --overwrite --remove webTestRunner/.yarn s3/$CACHE_BUCKET/ocis/web-test-runner/yarn-e2e-$WEB_COMMITID",
"mc mirror --overwrite --remove webTestRunner/tests/acceptance/.yarn s3/$CACHE_BUCKET/ocis/web-test-runner/yarn-acceptance-$WEB_COMMITID",
],
},
]
def restoreCoreCache():
return [{
"name": "retore-oc10-test-runner-cache",
"image": MINIO_MC,
"environment": MINIO_MC_ENV,
"commands": [
"source ./.drone.env",
"mc alias set s3 $MC_HOST $AWS_ACCESS_KEY_ID $AWS_SECRET_ACCESS_KEY",
"mc mirror s3/owncloud/ocis/oc10-test-runner/$CORE_COMMITID %s" % dirs["core"],
"ls -la %s" % dirs["core"],
],
}]
def restoreTestingAppCache():
return [{
"name": "retore-oc10-testing-app-cache",
"image": MINIO_MC,
"environment": MINIO_MC_ENV,
"commands": [
"source ./.drone.env",
"mc alias set s3 $MC_HOST $AWS_ACCESS_KEY_ID $AWS_SECRET_ACCESS_KEY",
"mc mirror s3/owncloud/ocis/oc10-test-runner/testingApp %s" % dirs["testing_app"],
"ls -la %s" % dirs["testing_app"],
],
}]
def restoreWebCache():
return [{
"name": "retore-web-cache",
@@ -2862,7 +2858,50 @@ def restoreWebCache():
"commands": [
"source ./.drone.env",
"mc alias set s3 $MC_HOST $AWS_ACCESS_KEY_ID $AWS_SECRET_ACCESS_KEY",
"mc mirror s3/owncloud/ocis/web-test-runner/$WEB_COMMITID %s" % dirs["web"],
"mc mirror s3/$CACHE_BUCKET/ocis/web-test-runner/$WEB_COMMITID %s" % dirs["web"],
"ls -la %s" % dirs["web"],
"chmod +x %s/tests/acceptance/*.sh" % dirs["web"],
],
}]
def restoreWebE2EYarnCache():
return [{
"name": "retore-web-e2e-yarn-cache",
"image": MINIO_MC,
"environment": MINIO_MC_ENV,
"commands": [
"source ./.drone.env",
"mc alias set s3 $MC_HOST $AWS_ACCESS_KEY_ID $AWS_SECRET_ACCESS_KEY",
"mc mirror s3/$CACHE_BUCKET/ocis/web-test-runner/yarn-e2e-$WEB_COMMITID %s/.yarn" % dirs["web"],
"ls -la %s/.yarn" % dirs["web"],
],
}, {
# we need to install again becase the node_modules are not cached
"name": "install-yarn-e2e",
"image": OC_CI_NODEJS % DEFAULT_NODEJS_VERSION,
"commands": [
"cd %s" % dirs["web"],
"retry -t 3 'yarn install --immutable'",
],
}]
def restoreWebAcceptanceYarnCache():
return [{
"name": "retore-web-acceptance-yarn-cache",
"image": MINIO_MC,
"environment": MINIO_MC_ENV,
"commands": [
"source ./.drone.env",
"mc alias set s3 $MC_HOST $AWS_ACCESS_KEY_ID $AWS_SECRET_ACCESS_KEY",
"mc mirror s3/$CACHE_BUCKET/ocis/web-test-runner/yarn-acceptance-$WEB_COMMITID %s/tests/acceptance/.yarn" % dirs["web"],
"ls -la %s/tests/acceptance/.yarn" % dirs["web"],
],
}, {
# we need to install again becase the node_modules are not cached
"name": "install-yarn-acceptance",
"image": OC_CI_NODEJS % DEFAULT_NODEJS_VERSION,
"commands": [
"cd %s/tests/acceptance" % dirs["web"],
"retry -t 3 'yarn install --immutable'",
],
}]

View File

@@ -1,16 +0,0 @@
#!/bin/bash
source .drone.env
echo "Checking core version - $CORE_COMMITID in cache"
URL="https://cache.owncloud.com/owncloud/ocis/oc10-test-runner/$CORE_COMMITID"
if curl --output /dev/null --silent --head --fail "$URL"; then
echo "Web cache for ${CORE_COMMITID} already available in cache"
exit 0
else
# cache using the minio/mc client to the 'owncloud' bucket (long term bucket)
mc alias set s3 "${MC_HOST}" "${AWS_ACCESS_KEY_ID}" "${AWS_SECRET_ACCESS_KEY}"
mc mirror --overwrite --remove --debug oc10TestRunner "s3/owncloud/ocis/oc10-test-runner/""${CORE_COMMITID}"
mc mirror --overwrite --remove --debug testingApp s3/owncloud/ocis/oc10-testing-app
fi

View File

@@ -1,15 +0,0 @@
#!/bin/bash
source .drone.env
echo "Checking web version - $WEB_COMMITID in cache"
URL="https://cache.owncloud.com/owncloud/ocis/web-test-runner/$WEB_COMMITID"
if curl --output /dev/null --silent --head --fail "$URL"; then
echo "web cache for $WEB_COMMITID already available in cache"
exit 0
else
# cache using the minio/mc client to the 'owncloud' bucket (long term bucket)
mc alias set s3 "${MC_HOST}" "${AWS_ACCESS_KEY_ID}" "${AWS_SECRET_ACCESS_KEY}"
mc mirror --overwrite --remove --debug webTestRunner "s3/owncloud/ocis/web-test-runner/""${WEB_COMMITID}"
fi

View File

@@ -0,0 +1,18 @@
#!/bin/bash
source .drone.env
echo "Checking web version - $WEB_COMMITID in cache"
URL="$CACHE_ENDPOINT/$CACHE_BUCKET/ocis/web-test-runner/$WEB_COMMITID/README.md"
echo "Checking for the web cache at '$URL'."
if curl --output /dev/null --silent --head --fail "$URL"
then
echo "Web with commit id $WEB_COMMITID already available in cache"
# https://discourse.drone.io/t/how-to-exit-a-pipeline-early-without-failing/3951
# exit a Pipeline early without failing
exit 78
else
echo "Web with $WEB_COMMITID not available in cache"
fi

View File

@@ -1,25 +0,0 @@
#!/bin/bash
source .drone.env
echo "Checking core version - $CORE_COMMITID in cache"
URL="https://cache.owncloud.com/owncloud/ocis/oc10-test-runner/$CORE_COMMITID"
if curl --output /dev/null --silent --head --fail "$URL"; then
echo "Core cache for $CORE_COMMITID already available in cache"
exit 0
else
echo "Cache for $CORE_COMMITID not available in cache, cloning..."
# clone the core repository
git clone -b "${CORE_BRANCH}" --single-branch --no-tags https://github.com/owncloud/core.git oc10TestRunner
cd oc10TestRunner && git checkout "${CORE_COMMITID}"
ls -la .
cd ..
# clone the testing app repository
git clone -b master --single-branch --no-tags https://github.com/owncloud/testing.git testingApp
ls -la testingApp
fi

View File

@@ -1,18 +0,0 @@
#!/bin/bash
source .drone.env
echo "Checking web version - $WEB_COMMITID in cache"
URL="https://cache.owncloud.com/owncloud/ocis/web-test-runner/$WEB_COMMITID"
if curl --output /dev/null --silent --head --fail "$URL"; then
echo "web cache for $WEB_COMMITID already available in cache"
exit 0
else
echo "Cache for $WEB_COMMITID not available in cache, cloning..."
# clone the "owncloud/web" repository
git clone -b "${WEB_BRANCH}" --single-branch --no-tags https://github.com/owncloud/web.git webTestRunner
cd webTestRunner && git checkout "${WEB_COMMITID}"
ls -la .
fi