From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 6A2C0A0C43 for ; Mon, 18 Oct 2021 09:46:32 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 64A41410EF; Mon, 18 Oct 2021 09:46:32 +0200 (CEST) Received: from AZHDRRW-EX01.nvidia.com (azhdrrw-ex01.nvidia.com [20.51.104.162]) by mails.dpdk.org (Postfix) with ESMTP id B603240683 for ; Mon, 18 Oct 2021 09:46:30 +0200 (CEST) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (104.47.55.102) by mxs.oss.nvidia.com (10.13.234.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.858.15; Mon, 18 Oct 2021 00:46:29 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YOYOSwqX6m1t4RzR/4lTvJD0Wxz5TKoyeStNCpkOfTJFe1P6+U44Q17SMW6YB+CEzgWTSQ9lo6jiVmIBKsW/x3ZM5IinJbl1Dq54aubl8Fpvr3/jTeSw4xS9O/6BXSrakWqsW3ijBvA7CmRJHDcYz6Yoq7x/boTsNheQuDxq0FGnfes/dKfqd+QWpM3SFfJdNMZFR7DzQtvxJVoI2hZZV0Pz70+nRWNMRh78Z/Kig/RAx4VaRzCRqlUQHj1w5y+L+MqvkIm/mb0uOrTuZc3m7u33dO+7LDntlkY+LVgeXweEDfqRHfDh4ctuwP9wUbTgitM/hKpbuAFwV75wJQfwGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=1miHLtPzMJJ7UHP6sheMA+TKzvmWfOKAvHugusKTwbw=; b=EhFGl7Yblvv2JPJbaHs6j4p9cxjMMy1z5FbjUQslts1gwGW+h7Rb5u55Dx0ccwBowSuvxmWUM3/e55RziT0M/BilB8MM7xMnoE61bQBW7D1w//6fZGab+89WHh++lzSjSQubFv1HLsBBuudvVioP+Ges6GHCLbWjJuOKqRtkh3iu8RWAZhnhOyVl5oA682Jf2YapHFCJhB2V+rSGOjhmMwSDEm9CB7b283uIJhM99JFxc0ngbCUhsn8MgXu2M3d04dQfXvt6MV6rUl6p8gcYnjdSNJ9jNavY0sWalZvwUslXu2+Jz/5XP0UCgxO8EiTdnj6zoTkUezUdKpkV26YqKA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=intel.com smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1miHLtPzMJJ7UHP6sheMA+TKzvmWfOKAvHugusKTwbw=; b=nHMvqpfbjyU8y6e4HOc17wgcrNl23LPGZkojqLe3M3gWbU4UwbacwkZ9FFJAw/4ndiEzc1lmZ2wRaMY9LQ1AKuwx8K8hp08T7nHwqhc0LK8RtfbaAZO0HGBvW1kqr1d7fO0Eg/UL4qNM7gdZt2gUyWp/tlFKWsXMrya0ieVWYoSYRy6lwLHtK2M7zd1YYfv1qW3Elc303rzqXBCxEDKmpnVjbLOpJW8c8CTLLKjm+jrf/l7brI3/DFXitg36Y7JgZrWZUbZvMcg6S1y3XC9LZURNDT+YvUOXRIYRR/njT5I7XdKLdDhHv7NLCdF+YK4uZJXP9oVfGb3FBBzQuiIiZA== Received: from MW3PR05CA0027.namprd05.prod.outlook.com (2603:10b6:303:2b::32) by BL0PR12MB2577.namprd12.prod.outlook.com (2603:10b6:207:42::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.18; Mon, 18 Oct 2021 07:46:26 +0000 Received: from CO1NAM11FT050.eop-nam11.prod.protection.outlook.com (2603:10b6:303:2b:cafe::77) by MW3PR05CA0027.outlook.office365.com (2603:10b6:303:2b::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.13 via Frontend Transport; Mon, 18 Oct 2021 07:46:25 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; intel.com; dkim=none (message not signed) header.d=none;intel.com; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by CO1NAM11FT050.mail.protection.outlook.com (10.13.174.79) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4608.15 via Frontend Transport; Mon, 18 Oct 2021 07:46:25 +0000 Received: from nvidia.com (172.20.187.5) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Mon, 18 Oct 2021 07:46:21 +0000 From: Ali Alnubani To: CC: , , , , Date: Mon, 18 Oct 2021 10:44:57 +0300 Message-ID: <20211018074500.16199-8-alialnu@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211018074500.16199-1-alialnu@nvidia.com> References: <20211018074500.16199-1-alialnu@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [172.20.187.5] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 96e84b31-7fb7-4323-8bbb-08d9920b632e X-MS-TrafficTypeDiagnostic: BL0PR12MB2577: X-LD-Processed: 43083d15-7273-40c1-b7db-39efd9ccc17a,ExtAddr X-Microsoft-Antispam-PRVS: X-MS-Exchange-Transport-Forked: True X-MS-Oob-TLC-OOBClassifiers: OLM:2512; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: o+VMq+FuzVOe9VhI6gj7j5VPbJGmNAYSl1czl0EezHyaBcjDyMeu4rUpQE8UvxNzw0LaWdXK1+/o4ymq6eWZvD5qhj8Jah/COkybkfMkBYhya4jBjRIrFcQMFs37k4z/n7gW6xel0jdrjdmW6KCJ26jH9JRq3w851c2Z0X/ty2n2300WosJ4j7k1NkBNqlhC6HwAiJOdEaE2DvOHB+Ng4fUlKVpWtKTubfOQWi6N/O6L9/m+PtTTBCdvukmYZJAKYUkY8+kCBad521p2lHMIEc0KqQO7FqywGuyXxsB3KeF9cAMDQ7BVG1QTCFYMsGqx7zZy1KitG70CQyUekAvXW/iB/xxe4YD6v+Hqkw6AcQIWMBXBhjnafwy+gjMBQBzqbHf1XDEPsg7RFSMSsfsN8lb2y1DkdgkIqWoAn3xTQXgeWzogtUxS9IPoYL8Seiucs/bf4r7b6B/xiFQ8nHEjzhLbQ1cQBw3OUq70UCV+zHZFcpEYjanRoyFTvyCelpQaH1Dn7jbc7v4QWx/LIEkcGwBLMMcf+NSDYo7Wgl5n8B5gacveGyUhAJ8EVEkzFdTXJsJM3V+AhX75v64PacLU5/V0Lu5HEikK70EqszEInwQtyxyMhKkU3m2MiBpkVL18ftnzdfgEYOJ2QgtVR8ZuIeANeYKXouV2ow2kAOxf3YL2Ugn7Fhv7k1NcqqoM5DuZrujFXujqxZCIWTCCU2TxmMhuY2dTskXuG5x1QOyB5qIvOAWAPD6npCBsbMYk6vvRorpU6RE1L2w2WTfVii5nKGhvBgM/vWQ4bTqJS5VcQOe2+5ayzIi4TgVm60naYpTi X-Forefront-Antispam-Report: CIP:216.228.112.34; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid03.nvidia.com; CAT:NONE; SFS:(4636009)(36840700001)(46966006)(336012)(107886003)(2616005)(356005)(426003)(83380400001)(1076003)(70206006)(36860700001)(70586007)(55016002)(4326008)(316002)(2906002)(966005)(8936002)(6286002)(54906003)(26005)(508600001)(7696005)(36756003)(6916009)(6666004)(8676002)(5660300002)(86362001)(47076005)(16526019)(7636003)(82310400003)(186003); DIR:OUT; SFP:1101; X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Oct 2021 07:46:25.3287 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 96e84b31-7fb7-4323-8bbb-08d9920b632e X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.34]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT050.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB2577 Subject: [dpdk-ci] [PATCH v3 07/10] tools: filter new Patchwork IDs by date X-BeenThere: ci@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK CI discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ci-bounces@dpdk.org Sender: "ci" API resource IDs are guaranteed to be unique, but they aren't guaranteed to have no gaps, for example, the following series IDs are nonexistent: 16157, 17181, 18235. Filtering by the date since the last check is necessary to later add support for fetching new series IDs in addition to patch IDs. The script now periodically fetches Patchwork's events API filtering by the 'patch-completed' category (see [1]). It parses the responses using jq and passes the IDs to 'callcmd'. Instead of requiring a file that contains the next patch ID, a file containing the timestamp of the last time the API was fetched is now used. Each time the API is fetched for new patches, the timestamp in the file gets updated, and the script sleeps an amount of time specified by PAUSE_SECONDS before attempting to fetch new resources again. There are 2 variables, 'date_now', which is recorded right before fetching from the API, and then gets written to the file, and 'since', which is the last date that was written to the file. Since API responses can be in multiple pages, the script will keep attempting to fetch the next page until jq encounters an error while parsing a non list response with no 'payload' key. The pause amount between each poll attempt is still 100 seconds. The script writes the date in Universal Time (UTC) format and expects to read the same format from the file as Patchwork stores event objects with a naive datetime object that is not aware of the server's timezone (see [2] and [3]). The package jq (Command-line JSON processor) is now required by the script. Example usage: $ export MAINTAINERS_FILE_PATH=/path/to/dpdk/MAINTAINERS $ ./tools/poll-pw /path/to/last.txt \ '/path/to/pw_maintainers_cli.py --type patch set_pw_delegate $1' [1] https://patchwork.readthedocs.io/en/latest/usage/overview/#patch-completed [2] https://github.com/getpatchwork/patchwork/blob/580cc8570a05c1/patchwork/models.py#L1058 [3] https://docs.python.org/3/library/datetime.html#datetime.datetime.utcnow Signed-off-by: Ali Alnubani --- Changes in v2: - Removed an unnecessary 'break' statement in the for loop. Changes in v3: - Fetch the events API endpoint for new patches as the date field in the /patches and /series endpoints is the mbox creation date, not the date they were created in Patchwork. - Use UTC date format. - Redirect error messages to stderr. - Fixed typo in usage (specifed -> specified). tools/poll-pw | 63 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 21 deletions(-) diff --git a/tools/poll-pw b/tools/poll-pw index bdf860a..ccc58f0 100755 --- a/tools/poll-pw +++ b/tools/poll-pw @@ -1,58 +1,79 @@ -#! /bin/sh -e +#! /bin/sh # SPDX-License-Identifier: BSD-3-Clause # Copyright 2017 6WIND S.A. # Copyright 2018 Mellanox Technologies, Ltd URL=http://patches.dpdk.org/api +PAUSE_SECONDS=100 print_usage () { cat <<- END_OF_HELP - usage: $(basename $0) + usage: $(basename $0) [OPTIONS] Poll patchwork and call command for each patch. - The first patchwork id to be checked is read from the counter file. - The command should use '$1' to be evaluated as patchwork id. - When a patch is found and the command is successful, - then the counter is incremented. + The first date to filter with is read from the specified file. + The command should use '$1' to be evaluated as the patch id. + The date in the specified file is updated after each pull. END_OF_HELP } +which jq >/dev/null 2>&1 +if [ ! $? -eq 0 ] ; then + printf "The command 'jq' doesn't exist, please install it.\n\n" >&2 + exit 1 +fi + while getopts h arg ; do case $arg in h ) print_usage ; exit 0 ;; ? ) print_usage >&2 ; exit 1 ;; esac done + if [ $# -lt 2 ] ; then - printf 'missing argument\n\n' >&2 + printf 'missing argument(s)\n\n' >&2 print_usage >&2 exit 1 fi shift $(($OPTIND - 1)) -counter=$1 +since_file=$1 shift cmd=$* +if [ ! -f "$since_file" ] ; then + printf "The file '$since_file' doesn't exist.\n\n" >&2 + exit 1 +fi + +date -d "$(cat $since_file | tr '\n' ' ')" >/dev/null 2>&1 +if [ ! $? -eq 0 ] ; then + printf "The file '$since_file' doesn't contain a valid date format.\n\n" >&2 + exit 1 +fi + +URL="${URL}/events/?category=patch-completed" + callcmd () # { eval $cmd } -checkid () # -{ - curl -sfIo /dev/null $URL/patches/$1/ || - curl -sfIo /dev/null $URL/covers/$1/ -} - -pwid=$(cat $counter) +set -e while true ; do - # process all recent patches - while checkid $pwid ; do - callcmd $pwid || break - pwid=$(($pwid + 1)) - echo $pwid >$counter + date_now=$(date --utc '+%FT%T') + since=$(date -d $(cat $since_file | tr '\n' ' ') '+%FT%T') + page=1 + while true ; do + ids=$(curl -s "${URL}&page=${page}&since=${since}" \ + | jq 'try ( .[].payload.patch.id )') + [ -z "$(echo $ids | tr -d '\n')" ] && break + for id in $ids ; do + callcmd $id + done + page=$((page+1)) done + echo -n $date_now >$since_file # pause before next check - sleep 100 + sleep $PAUSE_SECONDS done -- 2.25.1