From dbf695667699d06eb7933de161c6d27e50ccdd0a Mon Sep 17 00:00:00 2001 From: "sagargurung1001@gmail.com" Date: Tue, 6 Sep 2022 15:37:04 +0545 Subject: [PATCH] Added coding-standard-php pipeline in drone --- .drone.star | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++++ Makefile | 6 ++++ 2 files changed, 107 insertions(+) diff --git a/.drone.star b/.drone.star index 2ad14a48fd..7024506864 100644 --- a/.drone.star +++ b/.drone.star @@ -148,6 +148,10 @@ config = { "architectures": ["arm", "arm64", "amd64"], }, "litmus": True, + "codestyle": True, + "branches": [ + "master", + ], } # volume for steps to cache Go dependencies between steps of a pipeline @@ -226,6 +230,7 @@ def main(ctx): cancelPreviousBuilds() + \ buildWebCache(ctx) + \ [buildOcisBinaryForTesting(ctx)] + \ + codestyle(ctx) + \ cacheCoreReposForTesting(ctx) + \ testOcisModules(ctx) + \ testPipelines(ctx) @@ -560,6 +565,102 @@ def uploadScanResults(ctx): }, } +def vendorbinCodestyle(phpVersion): + return [{ + "name": "vendorbin-codestyle", + "image": OC_CI_PHP % phpVersion, + "environment": { + "COMPOSER_HOME": "%s/.cache/composer" % dirs["base"], + }, + "commands": [ + "make vendor-bin-codestyle", + ], + }] + +def vendorbinCodesniffer(phpVersion): + return [{ + "name": "vendorbin-codesniffer", + "image": OC_CI_PHP % phpVersion, + "environment": { + "COMPOSER_HOME": "%s/.cache/composer" % dirs["base"], + }, + "commands": [ + "make vendor-bin-codesniffer", + ], + }] + +def codestyle(ctx): + pipelines = [] + + if "codestyle" not in config: + return pipelines + + default = { + "phpVersions": [DEFAULT_PHP_VERSION], + } + + if "defaults" in config: + if "codestyle" in config["defaults"]: + for item in config["defaults"]["codestyle"]: + default[item] = config["defaults"]["codestyle"][item] + + codestyleConfig = config["codestyle"] + + if type(codestyleConfig) == "bool": + if codestyleConfig: + # the config has 'codestyle' true, so specify an empty dict that will get the defaults + codestyleConfig = {} + else: + return pipelines + + if len(codestyleConfig) == 0: + # 'codestyle' is an empty dict, so specify a single section that will get the defaults + codestyleConfig = {"doDefault": {}} + + for category, matrix in codestyleConfig.items(): + params = {} + for item in default: + params[item] = matrix[item] if item in matrix else default[item] + + for phpVersion in params["phpVersions"]: + name = "coding-standard-php%s" % phpVersion + + result = { + "kind": "pipeline", + "type": "docker", + "name": name, + "workspace": { + "base": "/drone", + "path": "src", + }, + "steps": skipIfUnchanged(ctx, "acceptance-tests") + + vendorbinCodestyle(phpVersion) + + vendorbinCodesniffer(phpVersion) + + [ + { + "name": "php-style", + "image": OC_CI_PHP % phpVersion, + "commands": [ + "make test-php-style", + ], + }, + ], + "depends_on": [], + "trigger": { + "ref": [ + "refs/pull/**", + "refs/tags/**", + ], + }, + } + + for branch in config["branches"]: + result["trigger"]["ref"].append("refs/heads/%s" % branch) + + pipelines.append(result) + + return pipelines + def localApiTests(ctx, storage, suite, accounts_hash_difficulty = 4): early_fail = config["localApiTests"]["earlyFail"] if "earlyFail" in config["localApiTests"] else False diff --git a/Makefile b/Makefile index cf9b6526c4..d4e43e2555 100644 --- a/Makefile +++ b/Makefile @@ -283,6 +283,12 @@ test-php-style-fix: vendor-bin/owncloud-codestyle/vendor $(PHP_CS_FIXER) fix -v --diff --allow-risky yes $(PHP_CODEBEAUTIFIER) --cache --runtime-set ignore_warnings_on_exit --standard=phpcs.xml tests/acceptance +.PHONY: vendor-bin-codestyle +vendor-bin-codestyle: vendor-bin/owncloud-codestyle/vendor + +.PHONY: vendor-bin-codesniffer +vendor-bin-codesniffer: vendor-bin/php_codesniffer/vendor + vendor-bin/owncloud-codestyle/vendor: vendor/bamarni/composer-bin-plugin vendor-bin/owncloud-codestyle/composer.lock composer bin owncloud-codestyle install --no-progress