From 4f58866432a0af1067fc80a5142d4e6738d70c94 Mon Sep 17 00:00:00 2001 From: amrita Date: Tue, 30 Apr 2024 12:02:02 +0545 Subject: [PATCH 1/3] add starlark linter --- .drone.star | 114 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 71 insertions(+), 43 deletions(-) diff --git a/.drone.star b/.drone.star index df7c17df..9b8444c6 100644 --- a/.drone.star +++ b/.drone.star @@ -1,20 +1,18 @@ -OC_CI_PHP = "owncloudci/php:%s" -DEFAULT_PHP_VERSION = "8.1" -OC_UBUNTU = "owncloud/ubuntu:20.04" -PLUGINS_GITHUB_RELEASE = "plugins/github-release:1" -POSTGRESQL = "postgres:13" MOODLEHQ_APACHE = "moodlehq/moodle-php-apache:8.1" +OC_CI_BAZEL_BUILDIFIER = "owncloudci/bazel-buildifier:latest" OC_CI_GOLANG = "owncloudci/golang:1.22" OC_CI_NODEJS = "owncloudci/nodejs:18" +OC_CI_PHP = "owncloudci/php:%s" OC_CI_WAIT_FOR = "owncloudci/wait-for:latest" +OC_UBUNTU = "owncloud/ubuntu:20.04" +PLUGINS_GITHUB_RELEASE = "plugins/github-release:1" +POSTGRESQL = "postgres:13" SELENIUM = "selenium/standalone-chrome:94.0" +DEFAULT_PHP_VERSION = "8.1" + config = { - "branches": [ - "main", - ], - "codestyle": True, - "ocisBranches": ["master","stable"], + "ocisBranches": ["master", "stable"], } trigger = { @@ -63,40 +61,35 @@ MOODLE_ENV = { } def main(ctx): - testPipelines = tests( - ctx, - [ - ["codestyle", "make test-php-style"], - ], - ) - releasePipeline = release (ctx) - uiTestPipeLine = behattest() - dependsOn(testPipelines,uiTestPipeLine) - dependsOn(testPipelines + uiTestPipeLine , releasePipeline) - return testPipelines + uiTestPipeLine + releasePipeline + initialPipeline = checkStarlark() + beforePipeline = checkCodeStyle() + releasePipeline = release(ctx) + uiTestPipeLine = behatTest() + dependsOn(initialPipeline, beforePipeline) + dependsOn(beforePipeline, uiTestPipeLine) + dependsOn(beforePipeline + uiTestPipeLine, releasePipeline) + return initialPipeline + beforePipeline + uiTestPipeLine + releasePipeline -def tests(ctx, tests): - pipelines = [] - for test in tests: - if test[0] in config and config[test[0]]: - pipelines += [ +def checkCodeStyle(): + return [ + { + "kind": "pipeline", + "type": "docker", + "name": "coding-standard-php%s" % DEFAULT_PHP_VERSION, + "steps": [ { - "kind": "pipeline", - "name": test[0], - "steps": [ - { - "name": test[0], - "image": OC_CI_PHP % DEFAULT_PHP_VERSION, - "commands": [ - "composer install", - test[1], - ], - }, + "name": "check-php-style", + "image": OC_CI_PHP % DEFAULT_PHP_VERSION, + "commands": [ + "composer install", + "make test-php-style", ], - "trigger": trigger, }, - ] - return pipelines + ], + "trigger": trigger, + "depends_on": ["check-starlark"], + }, + ] def release(ctx): return [ @@ -118,7 +111,7 @@ def release(ctx): ], }, { - "name": "release to GitHub", + "name": "release-on-github", "image": PLUGINS_GITHUB_RELEASE, "settings": { "api_key": { @@ -134,7 +127,7 @@ def release(ctx): }, }, { - "name": "release to moodle", + "name": "release-on-moodle", "image": OC_UBUNTU, "environment": { "ZIPURL": "https://github.com/owncloud/moodle-repository_ocis/releases/download/%s/moodle-repository_ocis_%s.zip" % (ctx.build.ref.replace("refs/tags/", ""), ctx.build.ref.replace("refs/tags/v", "")), @@ -168,7 +161,7 @@ def release(ctx): } ] -def behattest(): +def behatTest(): pipelines = [] for branch in config["ocisBranches"]: pipelines += [{ @@ -426,3 +419,38 @@ def dependsOn(earlierStages, nextStages): for earlierStage in earlierStages: for nextStage in nextStages: nextStage["depends_on"].append(earlierStage["name"]) + +def checkStarlark(): + return [{ + "kind": "pipeline", + "type": "docker", + "name": "check-starlark", + "steps": [ + { + "name": "format-check-starlark", + "image": OC_CI_BAZEL_BUILDIFIER, + "commands": [ + "buildifier --mode=check .drone.star", + ], + }, + { + "name": "show-diff", + "image": OC_CI_BAZEL_BUILDIFIER, + "commands": [ + "buildifier --mode=fix .drone.star", + "git diff", + ], + "when": { + "status": [ + "failure", + ], + }, + }, + ], + "depends_on": [], + "trigger": { + "ref": [ + "refs/pull/**", + ], + }, + }] From 39d806136d6e99fb6c1fab297dc6f97ec48cbedc Mon Sep 17 00:00:00 2001 From: amrita Date: Tue, 30 Apr 2024 12:02:54 +0545 Subject: [PATCH 2/3] fix drone style --- .drone.star | 129 ++++++++++++++++++++++++++-------------------------- 1 file changed, 64 insertions(+), 65 deletions(-) diff --git a/.drone.star b/.drone.star index 9b8444c6..96454c0d 100644 --- a/.drone.star +++ b/.drone.star @@ -32,10 +32,10 @@ POSTGRESQL_ENV = { OCIS_ENV = { "OCIS_INSECURE": "true", "PROXY_ENABLE_BASIC_AUTH": "true", - "IDM_ADMIN_PASSWORD": 'admin', + "IDM_ADMIN_PASSWORD": "admin", "OCIS_URL": "https://ocis:9200", - "PROXY_TRANSPORT_TLS_KEY":"/usr/local/share/ca-certificates/ocis.pem", - "PROXY_TRANSPORT_TLS_CERT":"/usr/local/share/ca-certificates/ocis.crt", + "PROXY_TRANSPORT_TLS_KEY": "/usr/local/share/ca-certificates/ocis.pem", + "PROXY_TRANSPORT_TLS_CERT": "/usr/local/share/ca-certificates/ocis.crt", } MOODLE_ENV = { @@ -55,9 +55,9 @@ MOODLE_ENV = { "POSTGRES_USER": "moodle", "POSTGRES_PASSWORD": "moodle", "POSTGRES_DB": "moodle", - "OCIS_ADMIN_USERNAME":"admin", - "OCIS_ADMIN_PASSWORD":"admin", - "MOODLE_DOCKER_BEHAT_FAILDUMP":"/drone/src/tests" + "OCIS_ADMIN_USERNAME": "admin", + "OCIS_ADMIN_PASSWORD": "admin", + "MOODLE_DOCKER_BEHAT_FAILDUMP": "/drone/src/tests", } def main(ctx): @@ -157,8 +157,8 @@ def release(ctx): "ref": [ "refs/tags/v*", ], - } - } + }, + }, ] def behatTest(): @@ -169,17 +169,17 @@ def behatTest(): "type": "docker", "name": "behatUItest-%s" % branch, "depends_on": [], - "steps":generateSSLCert() + apacheService() + waitForService("apache",443) + runOcis(branch) + \ - waitForService("ocis",9200) + databaseService() + waitForService("postgresql",5432) + \ - seleniumService() + waitForService("selenium",4444) + setupMoodle() + runBehatTest(branch) , + "steps": generateSSLCert() + apacheService() + waitForService("apache", 443) + runOcis(branch) + + waitForService("ocis", 9200) + databaseService() + waitForService("postgresql", 5432) + + seleniumService() + waitForService("selenium", 4444) + setupMoodle() + runBehatTest(branch), "volumes": [ { - "name":"www-moodle", - "temp": {} + "name": "www-moodle", + "temp": {}, }, { - "name":"update-cert", - "temp":{} + "name": "update-cert", + "temp": {}, }, ], "trigger": { @@ -195,18 +195,18 @@ def databaseService(): { "name": "postgresql", "image": POSTGRESQL, - "detach":True, - "environment": POSTGRESQL_ENV + "detach": True, + "environment": POSTGRESQL_ENV, }, ] -def waitForService(name,port): +def waitForService(name, port): return [ { "name": "wait-for-%s" % name, "image": OC_CI_WAIT_FOR, - "commands": ["wait-for -it %s:%s -t 600" % (name,port)] - } + "commands": ["wait-for -it %s:%s -t 600" % (name, port)], + }, ] def getCommitId(branch): @@ -279,15 +279,15 @@ def runOcis(branch): "environment": OCIS_ENV, "volumes": [ { - "name":"www-moodle", - "path": "/var/www" + "name": "www-moodle", + "path": "/var/www", }, { - "name":"update-cert", - "path":"/usr/local/share/ca-certificates/" + "name": "update-cert", + "path": "/usr/local/share/ca-certificates/", }, ], - } + }, ] def generateSSLCert(): @@ -301,17 +301,17 @@ def generateSSLCert(): "openssl req -x509 -newkey rsa:2048 -keyout moodle.key -out moodle.crt -nodes -days 365 -subj '/CN=apache'", "chmod -R 755 /usr/local/share/ca-certificates/", ], - "volumes":[ + "volumes": [ { - "name":"www-moodle", - "path": "/var/www" + "name": "www-moodle", + "path": "/var/www", }, { - "name":"update-cert", - "path":"/usr/local/share/ca-certificates/" + "name": "update-cert", + "path": "/usr/local/share/ca-certificates/", }, ], - } + }, ] def apacheService(): @@ -319,9 +319,9 @@ def apacheService(): { "name": "apache", "image": MOODLEHQ_APACHE, - "detach":True, + "detach": True, "environment": MOODLE_ENV, - "commands":[ + "commands": [ "cd /usr/local/share/ca-certificates/", "update-ca-certificates", "cp moodle.crt /etc/ssl/certs/ssl-cert-snakeoil.pem", @@ -330,16 +330,16 @@ def apacheService(): "a2enmod ssl", "moodle-docker-php-entrypoint apache2-foreground", ], - "volumes":[ + "volumes": [ { - "name":"www-moodle", - "path": "/var/www" + "name": "www-moodle", + "path": "/var/www", }, { - "name":"update-cert", - "path":"/usr/local/share/ca-certificates" + "name": "update-cert", + "path": "/usr/local/share/ca-certificates", }, - ] + ], }, ] @@ -358,32 +358,32 @@ def setupMoodle(): "cp /drone/src/tests/drone/config.php ./", "php admin/tool/behat/cli/init.php", ], - "volumes":[ + "volumes": [ { - "name":"www-moodle", - "path": "/var/www" + "name": "www-moodle", + "path": "/var/www", }, { - "name":"update-cert", - "path":"/usr/local/share/ca-certificates" + "name": "update-cert", + "path": "/usr/local/share/ca-certificates", }, - ] + ], }, ] def seleniumService(): return [ { - "name":"selenium", - "image":SELENIUM, - "detach":True, - "volumes":[ + "name": "selenium", + "image": SELENIUM, + "detach": True, + "volumes": [ { - "name":"www-moodle", - "path": "/var/www" - } - ] - } + "name": "www-moodle", + "path": "/var/www", + }, + ], + }, ] def runBehatTest(branch): @@ -393,26 +393,25 @@ def runBehatTest(branch): tags = "@ocis &&~@skipOnStable" return [ { - "name":"behat-test", - "image":MOODLEHQ_APACHE, + "name": "behat-test", + "image": MOODLEHQ_APACHE, "environment": MOODLE_ENV, "commands": [ "update-ca-certificates", "cd /var/www/html/moodle", - 'vendor/bin/behat --config /var/www/behatdata/behatrun/behat/behat.yml --tags="%s"' %tags, + 'vendor/bin/behat --config /var/www/behatdata/behatrun/behat/behat.yml --tags="%s"' % tags, ], - "volumes":[ + "volumes": [ { - "name":"www-moodle", - "path": "/var/www" + "name": "www-moodle", + "path": "/var/www", }, { - "name":"update-cert", - "path":"/usr/local/share/ca-certificates" + "name": "update-cert", + "path": "/usr/local/share/ca-certificates", }, - ] - - } + ], + }, ] def dependsOn(earlierStages, nextStages): From 995a3eac1b23ad51350e52e317c12d2fbd51ec7d Mon Sep 17 00:00:00 2001 From: amrita Date: Tue, 30 Apr 2024 12:18:18 +0545 Subject: [PATCH 3/3] optimize drone step flow --- .drone.star | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/.drone.star b/.drone.star index 96454c0d..f73e7715 100644 --- a/.drone.star +++ b/.drone.star @@ -167,11 +167,11 @@ def behatTest(): pipelines += [{ "kind": "pipeline", "type": "docker", - "name": "behatUItest-%s" % branch, + "name": "behatUITest-on-ocis-%s" % branch, "depends_on": [], "steps": generateSSLCert() + apacheService() + waitForService("apache", 443) + runOcis(branch) + - waitForService("ocis", 9200) + databaseService() + waitForService("postgresql", 5432) + - seleniumService() + waitForService("selenium", 4444) + setupMoodle() + runBehatTest(branch), + waitForService("ocis", 9200) + waitForService("postgresql", 5432) + + waitForService("selenium", 4444) + setupMoodle() + runBehatUITest(branch), "volumes": [ { "name": "www-moodle", @@ -182,6 +182,7 @@ def behatTest(): "temp": {}, }, ], + "services": postgresService() + seleniumService(), "trigger": { "ref": [ "refs/pull/**", @@ -190,12 +191,11 @@ def behatTest(): }] return pipelines -def databaseService(): +def postgresService(): return [ { "name": "postgresql", "image": POSTGRESQL, - "detach": True, "environment": POSTGRESQL_ENV, }, ] @@ -239,14 +239,10 @@ def runOcis(branch): "name": "www-moodle", "path": "/var/www", }, - { - "name": "update-cert", - "path": "/usr/local/share/ca-certificates/", - }, ], }, { - "name": "generate-ocis-%s" % branch, + "name": "generate-ocis", "image": OC_CI_NODEJS, "commands": [ "cd /var/www/html/ocis/ocis", @@ -257,10 +253,6 @@ def runOcis(branch): "name": "www-moodle", "path": "/var/www", }, - { - "name": "update-cert", - "path": "/usr/local/share/ca-certificates/", - }, ], }, { @@ -386,14 +378,14 @@ def seleniumService(): }, ] -def runBehatTest(branch): +def runBehatUITest(branch): if branch == "master": tags = "@ocis" else: tags = "@ocis &&~@skipOnStable" return [ { - "name": "behat-test", + "name": "behat-UI-test", "image": MOODLEHQ_APACHE, "environment": MOODLE_ENV, "commands": [