From dfd2c4b43c5721752717fd097fd2375bd36a4b4e Mon Sep 17 00:00:00 2001 From: genofire Date: Wed, 20 Jul 2022 19:48:38 +0200 Subject: [PATCH] feat(ci): first version to run on gitlab --- .ci/lint-targets.py | 46 +++++++++++++++++++++++++++++++++++++ .gitlab-ci.yml | 56 +++++++++++++++++++++++++++++++++++---------- site.mk | 2 +- 3 files changed, 91 insertions(+), 13 deletions(-) create mode 100755 .ci/lint-targets.py diff --git a/.ci/lint-targets.py b/.ci/lint-targets.py new file mode 100755 index 0000000..6c86484 --- /dev/null +++ b/.ci/lint-targets.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python3 + +from yaml import safe_load as yaml_load +import subprocess +from os import environ, chdir + +targets_in_ci = [] +targets_in_make = [] + + +## +# Fetch data from .gitlab-ci.yml +## +with open('.gitlab-ci.yml', 'r') as file: + ci = yaml_load(file) + +if "build" in ci: + targets_in_ci = ci["build"]['parallel']["matrix"][0]['GLUON_TARGET'] + +## +# Fetch data from gluon make +## +d = dict(environ) +if "GLUON_SITEDIR" not in d: + d["GLUON_SITEDIR"] = "../" +if "GLUON_DIR" not in d: + d["GLUON_DIR"] = "./gluon/" +chdir(d["GLUON_DIR"]) +result = subprocess.run(['make', 'list-targets'], env=d, stdout=subprocess.PIPE, text=True) + +targets_in_make = result.stdout.splitlines() + +## +# Compare +## +only_in_ci = [ item for item in targets_in_ci if item not in targets_in_make] +only_in_make = [ item for item in targets_in_make if item not in targets_in_ci] + +if len(only_in_ci) > 0: + print(f"\U0001F525 CI-Pipeline contains not supported TARGETS: {only_in_ci}") + exit(1) + +if len(only_in_make) > 0: + print(f"\u26a0 CI-Pipeline does not contain all supported TARGETS: {only_in_make}") +else: + print("\u2705 works well - let's build for every TARGET a firmware") diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c9d2834..1819398 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,5 +1,7 @@ stages: + - lint - build + - release variables: GIT_CLEAN_FLAGS: "none" @@ -9,9 +11,17 @@ variables: GLUON_DIR: "$CI_PROJECT_DIR/gluon/" before_script: - - export GLUON_RELEASE="$(git describe --tags --abbrev=0)-build${CI_PIPELINE_ID}" + - export GLUON_RELEASE="$(git describe --tags --abbrev=0 | sed 's/^v//g')-build${CI_PIPELINE_ID}" -.job_build: + +'lint: TARGETS': + tags: + - gluon + stage: lint + script: + - ./.ci/lint-targets.py + +"build": tags: - gluon stage: build @@ -19,19 +29,41 @@ before_script: script: - cd "gluon" - env + # fetch newest gluon version if env is set + - "[ -z \"$FFHB_GLUON_PULL\" ] && git checkout origin/master && git pull --rebase" + # start build - make update V=s - make --jobs=$(grep -c '^processor' /proc/cpuinfo) --output-sync=recurse || make --jobs=1 --output-sync=recurse V=sc artifacts: paths: - "gluon/output/images/sysupgrade" - expire_in: 1 month + expire_in: "1 month" + cache: + # cache across all branches based on target + key: "$GLUON_TARGET" + paths: + - "gluon/openwrt" + parallel: + matrix: + - GLUON_TARGET: + - "ath79-generic" + - "ramips-mt7621" - -### -# Build per target -### - -'build: ath79-generic': - extends: .job_build - variables: - GLUON_TARGET: "ath79-generic" +'release: generate manifest': + tags: + - gluon + stage: release + script: + - cd "gluon" + - '[[ "$CI_BUILD_REF_NAME" != "master" ]] && export GLUON_AUTOUPDATER_BRANCH="nightly"' + - make update V=s + - ls output/images/sysupgrade + - make manifest + - ls output/images/sysupgrade + artifacts: + paths: + - "gluon/output/images/sysupgrade/*manifest" + expire_in: "1 month" + # not use dependencies will download from every job + # empty array not download artifacts + # dependencies: [] diff --git a/site.mk b/site.mk index 4f3dee7..7c7db33 100755 --- a/site.mk +++ b/site.mk @@ -31,7 +31,7 @@ GLUON_SITE_PACKAGES += \ # respondd-module-lldp \ # Allow overriding the these variables from the command line -GLUON_RELEASE ?= $(patsubst v%,%,$(shell git -C $(GLUON_SITEDIR) describe --tags --dirty=+)) +GLUON_RELEASE ?= $(patsubst v%,%,$(shell echo $(git -C $(GLUON_SITEDIR) describe --tags --abbrev=0))-build$(CI_PIPELINE_ID)))) GLUON_AUTOUPDATER_BRANCH ?= stable GLUON_AUTOUPDATER_ENABLED ?= 1 GLUON_PRIORITY ?= 0