From 9efda70d16755b2c13ffd2d96dffe5e49d0f4a10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Correa=20G=C3=B3mez?= Date: Fri, 20 Jun 2025 20:18:18 +0200 Subject: [PATCH] build-jobs: use parallel:matrix instead of copy-pasting job definitions This has the additional benefit that the job is always defined, and then we can just add the placeholder as any other job Part-of: https://gitlab.postmarketos.org/postmarketOS/pmaports/-/merge_requests/6693 [ci:skip-build]: already built successfully in CI --- .ci/build-jobs.yaml.j2 | 85 ++++++++++------------------------ .ci/lib/generate_build_jobs.py | 39 +++++++++++++--- 2 files changed, 57 insertions(+), 67 deletions(-) diff --git a/.ci/build-jobs.yaml.j2 b/.ci/build-jobs.yaml.j2 index ce60e84cc..872596d6e 100644 --- a/.ci/build-jobs.yaml.j2 +++ b/.ci/build-jobs.yaml.j2 @@ -17,20 +17,9 @@ workflow: rules: - if: $CI_PIPELINE_SOURCE == "parent_pipeline" -{% if archs|length == 0 %} -# Needed because gitlab fails if no jobs are ran: -# - https://gitlab.com/gitlab-org/gitlab/-/issues/368248 -# This applies to `when: manual` is used on all jobs. -placeholder: - stage: build - script: - - 'true' -{% endif %} - .build: - # Create jobs, but don't run them unless this is + # Create jobs, but do not run them unless this is # overriden in jobs that extend it - when: manual stage: build interruptible: true before_script: @@ -51,57 +40,28 @@ placeholder: - keys/ timeout: 10 h -build-x86_64: -{% if ('x86_64' in archs) %} - when: always -{% endif %} +build: extends: .build - script: - - .ci/build-x86_64.sh - -build-x86: -{% if ('x86' in archs) %} - when: always + parallel: + matrix: +{% for arch in archs %} + - ARCH: {{ arch }} + TAG: {{ archtag[arch] }} +{% endfor %} +{% if archs|length == 0 %} + - ARCH: placeholder + TAG: shared {% endif %} - extends: .build + tags: + - $TAG script: - - .ci/build-x86.sh - -build-aarch64: -{% if ('aarch64' in archs) %} - when: always +# Needed because gitlab fails if no jobs are ran: +# - https://gitlab.com/gitlab-org/gitlab/-/issues/368248 +{% if archs|length == 0 %} + - 'true' +{% else %} + - .ci/build-$ARCH.sh {% endif %} - extends: .build - tags: [arm64] - script: - - .ci/build-aarch64.sh - -build-armv7: -{% if ('armv7' in archs) %} - when: always -{% endif %} - extends: .build - tags: [qemu] - script: - - .ci/build-armv7.sh - -build-armhf: -{% if ('armhf' in archs) %} - when: always -{% endif %} - extends: .build - tags: [qemu] - script: - - .ci/build-armhf.sh - -build-riscv64: -{% if ('riscv64' in archs) %} - when: always -{% endif %} - extends: .build - tags: [qemu] - script: - - .ci/build-riscv64.sh # Hardware testing @@ -139,7 +99,12 @@ prepare-{{ device.name }}: - {{ kernel }} {%- endfor %} {%- endif %} - needs: ["build-{{ device.arch }}"] + needs: + - job: "build" + parallel: + matrix: + - ARCH: "{{ device.arch }}" + TAG: "{{ archtag[device.arch] }}" variables: DEVICE_NAME: {{ device.name }} # NOTE: All the packages that may influence testing should have an diff --git a/.ci/lib/generate_build_jobs.py b/.ci/lib/generate_build_jobs.py index 6f32c0b9b..243496c7c 100755 --- a/.ci/lib/generate_build_jobs.py +++ b/.ci/lib/generate_build_jobs.py @@ -141,6 +141,23 @@ class Device: return supported_devices +class ArchTagSet(set): + supported_arches = [ + Arch.x86_64, + Arch.x86, + Arch.aarch64, + Arch.armv7, + Arch.armhf, + Arch.riscv64, + ] + + def update(self, iterable): + # This ignores things like !armv7, that could be a follow-up optimization + if 'noarch' in iterable or 'all' in iterable: + iterable = [arch for arch in self.supported_arches] + super().update([Arch(arch) for arch in iterable if Arch(arch) in self.supported_arches]) + + if __name__ == "__main__": # Needs input to output if we should create the jobs if len(sys.argv) != 3: @@ -163,7 +180,7 @@ if __name__ == "__main__": # Get the list of supported devices supported_devices = Device.supported_devices() - archs = set() + archs = ArchTagSet() devices_under_test = set() packages_modified = set() # Get and print modified packages @@ -189,19 +206,27 @@ if __name__ == "__main__": if apkbuild['pkgname'] in device.dependencies: devices_under_test.add(device) - # This ignores things like !armv7, that could be a follow-up optimization - if 'noarch' in archs or 'all' in archs: - archs = set([str(arch) for arch in Arch.supported()]) - if common.commit_message_has_string("[ci:skip-build]"): print("User requested skipping build, not creating child pipeline file") - archs = set() + archs = ArchTagSet() devices_under_test = set() print(f"Architectures to build: {archs}") print(f"Devices under test: {devices_under_test}") with open(template) as f: - rendered = Template(f.read()).render(archs=archs, devices_under_test=devices_under_test, packages_modified=packages_modified) + rendered = Template(f.read()).render( + archs=archs, + devices_under_test=devices_under_test, + packages_modified=packages_modified, + archtag={ + Arch.x86_64: "shared", + Arch.x86: "shared", + Arch.aarch64: "arm64", + Arch.armv7: "qemu", + Arch.armhf: "qemu", + Arch.riscv64: "qemu", + }, + ) with open(child_pipeline, "w") as fw: fw.write(rendered)