From ec5299ead82277bcd2085809f3bf5991e7766bd3 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 | 86 +++++++++++++++++++++++++++++++++++++++++++++ site.mk | 2 +- 3 files changed, 133 insertions(+), 1 deletion(-) create mode 100755 .ci/lint-targets.py create mode 100644 .gitlab-ci.yml 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 new file mode 100644 index 0000000..ab8caad --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,86 @@ +stages: + - lint + - build + - release + +variables: + GIT_CLEAN_FLAGS: "none" + GIT_STRATEGY: "fetch" + GIT_SUBMODULE_STRATEGY: "recursive" + GLUON_SITEDIR: "$CI_PROJECT_DIR" + GLUON_DIR: "$CI_PROJECT_DIR/gluon/" + +before_script: + - export GLUON_RELEASE="$(git describe --tags --abbrev=0 | sed 's/^v//g')-build${CI_PIPELINE_ID}" + + +'lint: TARGETS': + tags: + - gluon + stage: lint + script: + - ./.ci/lint-targets.py + +"build": + tags: + - gluon + stage: build + timeout: 4h 30m + 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" + parallel: + matrix: + - GLUON_TARGET: + - "ath79-generic" + - "ath79-nand" + - "ath79-mikrotik" + - "bcm27xx-bcm2708" + - "bcm27xx-bcm2709" + - "bcm27xx-bcm2710" # on BROKEN + - "ipq40xx-generic" + - "ipq40xx-mikrotik" + - "ipq806x-generic" + - "lantiq-xrx200" + - "lantiq-xway" + - "mediatek-mt7622" + - "mpc85xx-p1010" + - "mpc85xx-p1020" + - "mvebu-cortexa9" # on BROKEN + - "ramips-mt7620" + - "ramips-mt7621" + - "ramips-mt76x8" + - "rockchip-armv8" + - "sunxi-cortexa7" + - "x86-generic" + - "x86-geode" + - "x86-legacy" + - "x86-64" + +'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 4db5b4f..4bb4d11 100755 --- a/site.mk +++ b/site.mk @@ -28,7 +28,7 @@ GLUON_SITE_PACKAGES := \ gluon-scheduled-domain-switch # 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