Support for Patchwork CI
cover Support for Patchwork CI
Add support for patch-series validation in the patchwork ML. We use Github to schedule a trigger every 30 minutes, checking for new patche-series in parchwork which has not been tested yet.
The way we decide if a patch-series has been tested in patchwork, is by looking at its status (in particular, if it's "Needs Review / ACK"), as well as checking if test report has been uploaded to any of the series patches.
All communication to Patchwrok is done via REST API, using curl and js tools.
First, we create a script called patchwork-ci.sh that provides all the commands to read new untested patch-series, set their status and testing report. Then, we create a scheduled workflow in Gitlab, checking every 30 minutes if there are new untested patch-series. At the end, we trigger the main build workflow, used to validate LTP commits in our Github mainline. All the times we trigger the build workflow, we also provide the patch-series ID, that will be fetched and applied on the current branch before running the tests.
---
Andrea Cervesato (4):
ci: install dependences for patchwork-ci script
ci: add patchwork-ci script
ci: add ci-patchwork-trigger workflow
ci: apply patchwork series in ci-docker-build workflow
.github/workflows/ci-docker-build.yml | 29 ++++- .github/workflows/ci-patchwork-trigger.yml | 53 ++++++++++ ci/alpine-runtime.sh | 2 + ci/alpine.sh | 2 + ci/debian.i386.sh | 2 + ci/debian.sh | 28 ++--- ci/fedora.sh | 2 + ci/patchwork-ci.sh | 164 +++++++++++++++++++++++++++++ ci/tumbleweed.sh | 2 + 9 files changed, 270 insertions(+), 14 deletions(-)
---
base-commit: 8000c950d6ba61a541a9278cdda6d68141c2fc0d
change-id: 20250410-patchwork_ci-7dc4ae02c40d
Best regards,
Signature · 5 lines
Andrea Cervesato <[email protected]> -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 1/4 ci: install dependences for patchwork-ci script
From: Andrea Cervesato <[email protected]>
--- ci/alpine-runtime.sh | 2 ++ ci/alpine.sh | 2 ++ ci/debian.i386.sh | 2 ++ ci/debian.sh | 28 +++++++++++++++------------- ci/fedora.sh | 2 ++ ci/tumbleweed.sh | 2 ++ 6 files changed, 25 insertions(+), 13 deletions(-)
ci/alpine-runtime.sh +2 -0
@@ -4,6 +4,8 @@ apk add \ acl \ + curl \ + jq \ keyutils \ libaio \ libacl \
ci/alpine.sh +2 -0
@@ -9,6 +9,8 @@ apk add \ autoconf \ automake \ clang \ + curl \ + jq \ gcc \ git \ acl-dev \
ci/debian.i386.sh +2 -0
@@ -6,6 +6,8 @@ dpkg --add-architecture i386 apt update apt install -y --no-install-recommends \ + curl \ + jq \ linux-libc-dev:i386 \ gcc-multilib \ libacl1-dev:i386 \
ci/debian.sh +15 -13
@@ -4,7 +4,7 @@ # workaround for missing oldstable-updates repository # W: Failed to fetch http://deb.debian.org/debian/dists/oldstable-updates/main/binary-amd64/Packages -grep -v oldstable-updates /etc/apt/sources.list > /tmp/sources.list && mv /tmp/sources.list /etc/apt/sources.list +grep -v oldstable-updates /etc/apt/sources.list >/tmp/sources.list && mv /tmp/sources.list /etc/apt/sources.list apt update
@@ -23,6 +23,8 @@ pkg_minimal=" debhelper devscripts clang + curl + jq gcc git iproute2
@@ -47,18 +49,18 @@ pkg_nonessential=" " case "$ACTION" in - minimal) - echo "=== Installing only minimal dependencies ===" - $install $pkg_minimal - ;; - remove-nonessential) - echo "=== Make sure devel libraries are removed ===" - $remove $pkg_nonessential - ;; - *) - echo "=== Installing dependencies ===" - $install $pkg_minimal $pkg_nonessential - ;; +minimal) + echo "=== Installing only minimal dependencies ===" + $install $pkg_minimal + ;; +remove-nonessential) + echo "=== Make sure devel libraries are removed ===" + $remove $pkg_nonessential + ;; +*) + echo "=== Installing dependencies ===" + $install $pkg_minimal $pkg_nonessential + ;; esac df -hT
ci/fedora.sh +2 -0
@@ -9,6 +9,8 @@ $yum \ automake \ make \ clang \ + curl \ + jq \ gcc \ git \ findutils \
ci/tumbleweed.sh +2 -0
@@ -8,6 +8,8 @@ $zyp \ autoconf \ automake \ clang \ + curl \ + jq \ findutils \ gcc \ git \
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 2/4 ci: add patchwork-ci script
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
Add a script to communicate with patchwork. Available commands are:
- verify: will print a list of new patch-series which has not been tested in the past hour (by default)
- apply: apply a patch-series to the current git branch using git-am
- check: send a tests report to patchwork
The script can be configured defining:
- PATCHWORK_URL: patchwork url to communicate with
- PATCHWORK_SINCE: timespan in seconds where we want to fetch patch-series
--- ci/patchwork-ci.sh | 164 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 164 insertions(+)
ci/patchwork-ci.sh new file +164 -0
@@ -0,0 +1,164 @@ +#!/bin/sh -ex +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2025 Andrea Cervesato <[email protected]> + +if [ -z "$PATCHWORK_URL" ]; then + PATCHWORK_URL="https://patchwork.ozlabs.org" +fi + +if [ -z "$PATCHWORK_SINCE" ]; then + PATCHWORK_SINCE=3600 +fi + +fetch_series() { + local current_time=$(date +%s) + local since_time=$(expr $current_time - $PATCHWORK_SINCE) + local date=$(date -u -d @$since_time +"%Y-%m-%dT%H:%M:%SZ") + + curl -k -G "$PATCHWORK_URL/api/events/" \ + --data "category=series-completed" \ + --data "project=ltp" \ + --data "state=new" \ + --data "since=$date" \ + --data "archive=no" | + jq -r '.[] | "\(.payload.series.id):\(.payload.series.mbox)"' +} + +get_patches() { + local series_id="$1" + + curl -k -G "$PATCHWORK_URL/api/patches/" \ + --data "project=ltp" \ + --data "series=$series_id" | + jq -r '.[] | "\(.id)"' +} + +set_patch_state() { + local patch_id="$1" + local state="$2" + + curl -k -X PATCH \ + -H "Authorization: Token $PATCHWORK_TOKEN" \ + -F "state=$state" \ + "$PATCHWORK_URL/api/patches/$patch_id/" +} + +set_series_state() { + local series_id="$1" + local state="$2" + + get_patches "$series_id" | while IFS= read -r patch_id; do + if [ -n "$patch_id" ]; then + set_patch_state "$patch_id" "$state" + fi + done +} + +get_checks() { + local patch_id="$1" + + curl -k -G "$PATCHWORK_URL/api/patches/$patch_id/checks/" | + jq -r '.[] | "\(.id)"' +} + +already_tested() { + local series_id="$1" + + get_patches "$series_id" | while IFS= read -r patch_id; do + if [ ! -n "$patch_id" ]; then + continue + fi + + get_checks "$patch_id" | while IFS= read -r check_id; do + if [ -n "$check_id" ]; then + echo "$check_id" + return + fi + done + done +} + +verify_new_patches() { + local output="output.txt" + + fetch_series | while IFS=: read -r series_id series_mbox; do + if [ ! -n "$series_id" ]; then + continue + fi + + tested=$(already_tested "$series_id") + if [ -n "$tested" ]; then + continue + fi + + echo -n "$series_id:$series_mbox;" >>"$output" + done + + if [ -e "$output" ]; then + cat "$output" + fi +} + +apply_series() { + local series_id="$1" + local series_mbox="$2" + + git config --global user.name 'GitHub CI' + git config --global user.email '[email protected]' + git config --global --add safe.directory $GITHUB_WORKSPACE + + curl -k "$series_mbox" | git am + + # we set patch state after applying it, so + # the next triggering won't take patch into account + set_series_state "$series_id" "needs-review-ack" +} + +send_results() { + local series_id="$1" + local target_url="$2" + + local context=$(echo "$3" | sed 's/:/_/g; s/\//_/g') + if [ -n "$CC" ]; then + context="${context}_${CC}" + fi + + if [ -n "$ARCH" ]; then + context="${context}_${ARCH}" + fi + + local result="$4" + if [ "$result" = "cancelled" ]; then + return + fi + + local state="fail" + if [ "$result" = "success" ]; then + state="success" + fi + + get_patches "$series_id" | while IFS= read -r patch_id; do + if [ -n "$patch_id" ]; then + curl -k -X POST \ + -H "Authorization: Token $PATCHWORK_TOKEN" \ + -F "state=$state" \ + -F "context=$context" \ + -F "target_url=$target_url" \ + -F "description=$result" \ + "$PATCHWORK_URL/api/patches/$patch_id/checks/" + fi + done +} + +run="$1" + +if [ -z "$run" -o "$run" = "verify" ]; then + verify_new_patches +elif [ -z "$run" -o "$run" = "apply" ]; then + apply_series "$2" "$3" +elif [ -z "$run" -o "$run" = "check" ]; then + send_results "$2" "$3" "$4" "$5" +else + echo "Available commands: apply, check, verify" + exit 1 +fi
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 4/4 ci: apply patchwork series in ci-docker-build workflow
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
Modify ci-docker-build workflow in order to apply untested new patchwork patch-series inside the current branch and to send back results in the patchwork instance.
--- .github/workflows/ci-docker-build.yml | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-)
.github/workflows/ci-docker-build.yml +28 -1
@@ -1,7 +1,19 @@ # Copyright (c) 2021-2024 Petr Vorel <[email protected]> name: "Test building in various distros in Docker" -on: [push, pull_request] +on: + push: + pull_request: + workflow_dispatch: + inputs: + SERIES_ID: + description: LTP patch series ID + required: false + default: '' + SERIES_MBOX: + description: LTP patch series URL + required: false + default: '' permissions: contents: read # to fetch code (actions/checkout)
@@ -125,6 +137,10 @@ jobs: - name: Compiler version run: $CC --version + - name: Apply Patchwork series + if: inputs.SERIES_ID != '' && inputs.SERIES_MBOX != '' + run: ./ci/patchwork-ci.sh apply ${{ inputs.SERIES_ID }} ${{ inputs.SERIES_MBOX }} + - name: ver_linux run: ./ver_linux
@@ -158,3 +174,14 @@ jobs: run: | if [ "$MAKE_INSTALL" = 1 ]; then INSTALL_OPT="-i"; fi ./build.sh -r install -o ${TREE:-in} $INSTALL_OPT + + - name: Send results to Patchwork + if: always() && inputs.SERIES_ID != '' && inputs.SERIES_MBOX != '' + env: + PATCHWORK_TOKEN: ${{ secrets.PATCHWORK_TOKEN }} + run: | + ./ci/patchwork-ci.sh check \ + "${{ inputs.SERIES_ID }}" \ + "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" \ + "${{ matrix.container }}" \ + "${{ job.status }}"
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 4/4] ci: apply patchwork series in ci-docker-build workflow
Hi Andrea!
Quoted 37 lines · Andrea Cervesato
From: Andrea Cervesato <[email protected]>
Modify ci-docker-build workflow in order to apply untested new patchwork patch-series inside the current branch and to send back results in the patchwork instance.
Signed-off-by Andrea Cervesato <[email protected]>--- .github/workflows/ci-docker-build.yml | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-).github/workflows/ci-docker-build.yml +13
-1@@ -1,7 +1,19 @@ # Copyright (c) 2021-2024 Petr Vorel <[email protected]> name: "Test building in various distros in Docker" -on: [push, pull_request] +on: + push: + pull_request: + workflow_dispatch: + inputs: + SERIES_ID: + description: LTP patch series ID + required: false + default: '' + SERIES_MBOX: + description: LTP patch series URL + required: false + default: '' permissions: contents: read # to fetch code (actions/checkout)
.github/workflows/ci-docker-build.yml jobs: · line 143
Quoted 7 lines
.github/workflows/ci-docker-build.yml +4
-0@@ -125,6 +137,10 @@ jobs: - name: Compiler version run: $CC --version + - name: Apply Patchwork series + if: inputs.SERIES_ID != '' && inputs.SERIES_MBOX != '' + run: ./ci/patchwork-ci.sh apply ${{ inputs.SERIES_ID }} ${{ inputs.SERIES_MBOX }} +
That if: condition will disable this job to be run when we push to a fork, right?
.github/workflows/ci-docker-build.yml jobs: · line 181
Quoted 12 lines
.github/workflows/ci-docker-build.yml +5
-0- name: ver_linux run: ./ver_linux@@ -158,3 +174,14 @@ jobs: run: | if [ "$MAKE_INSTALL" = 1 ]; then INSTALL_OPT="-i"; fi ./build.sh -r install -o ${TREE:-in} $INSTALL_OPT + + - name: Send results to Patchwork + if: always() && inputs.SERIES_ID != '' && inputs.SERIES_MBOX != '' + env: + PATCHWORK_TOKEN: ${{ secrets.PATCHWORK_TOKEN }}
Even with the if:, I think it would be better to check if $PATCHWORK_TOKEN is null in patchwork-ci.sh
.github/workflows/ci-docker-build.yml jobs: · line 187
Quoted 6 lines
.github/workflows/ci-docker-build.yml +6
-0+ run: | + ./ci/patchwork-ci.sh check \ + "${{ inputs.SERIES_ID }}" \ + "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" \ + "${{ matrix.container }}" \ + "${{ job.status }}"
Nice work!
Thank you,
- rbm
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 4/4] ci: apply patchwork series in ci-docker-build workflow
Hi Ricardo,
Quoted 3 lines · Ricardo B. Marlière
Quoted 1 line
+
PATCHWORK_TOKEN: ${{ secrets.PATCHWORK_TOKEN }}Even with the
if:, I think it would be better to check if $PATCHWORK_TOKEN is null inpatchwork-ci.sh
Good idea.
- Andrea
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 4/4] ci: apply patchwork series in ci-docker-build workflow
Quoted 10 lines · Andrea Cervesato
Hi Ricardo,
Quoted 3 lines · Ricardo B. Marlière
Quoted 1 line
+
PATCHWORK_TOKEN: ${{ secrets.PATCHWORK_TOKEN }}Even with the
if:, I think it would be better to check if $PATCHWORK_TOKEN is null inpatchwork-ci.shGood idea.
- Andrea
Unfortunately this can't be done: secrets are not supported in if: statement. I guess we will obtain authorization error, which is good anyway.. I managed to run the pipeline first, but eventually I missed the modification. Revert to v1, now it's working again.
- Andrea
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [LTP] [PATCH 3/4] ci: add ci-patchwork-trigger workflow
Apparently this patch is totally missing from patchwork [1]. It's clearly a bug of the platform and it might affect our automate testing, since the "series-completed" event is triggered only when all the patch-series are received and it's the one checked by our scripts. I'm scared we will need to test each single patch via "b4 shazam" checking "patch-completed"
Also b4 complains:
Grabbing thread from lore.kernel.org/all/[email protected]/t.mbox.gz Breaking thread to remove parents of [email protected] Checking for newer revisions
Grabbing search results from lore.kernel.org
Analyzing 4 messages in the thread
Looking for additional code-review trailers on lore.kernel.org
Analyzing 0 code-review messages
Checking attestation on all messages, may take a moment...
---
✗ [PATCH 1/4] ci: install dependences for patchwork-ci script
✗ No key: ed25519/[email protected]
✗ BADSIG: DKIM/suse.de
✗ BADSIG: DKIM/suse.de
✗ BADSIG: DKIM/suse.de
✗ BADSIG: DKIM/suse.de
✗ [PATCH 2/4] ci: add patchwork-ci script
✗ No key: ed25519/[email protected]
✗ BADSIG: DKIM/suse.de
✗ BADSIG: DKIM/suse.de
✗ BADSIG: DKIM/suse.de
✗ BADSIG: DKIM/suse.de
------------------> ERROR: missing [3/4]! <--------------
✗ [PATCH 4/4] ci: apply patchwork series in ci-docker-build workflow ✗ No key: ed25519/[email protected]
✗ BADSIG: DKIM/suse.de
✗ BADSIG: DKIM/suse.de
✗ BADSIG: DKIM/suse.de
✗ BADSIG: DKIM/suse.de
This is so frustrating after days of work :-)
[1] https://patchwork.ozlabs.org/project/ltp/patch/[email protected]/
- Andrea
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp