[RFC,v2,3/3] github: add a tool for restarting checks

Message ID 20231107203158.1261199-4-aconole@redhat.com (mailing list archive)
State New
Headers
Series Add a recheck framework to pw-ci |

Commit Message

Aaron Conole Nov. 7, 2023, 8:31 p.m. UTC
  The recheck framework can track specific recheck labels and track a
state for them.  Add a tool that will restart github workflow runs
and mark the git build table to check for a repoll.  This will allow
existing monitor tools to re-poll the workflow and report rerun
results.

Signed-off-by: Aaron Conole <aconole@redhat.com>
---
 github_restart   | 141 +++++++++++++++++++++++++++++++++++++++++++++++
 series_db_lib.sh |  16 ++++++
 2 files changed, 157 insertions(+)
 create mode 100755 github_restart
  

Comments

Michael Santana Nov. 17, 2023, 4:47 p.m. UTC | #1
On Tue, Nov 7, 2023 at 3:32 PM Aaron Conole <aconole@redhat.com> wrote:
>
> The recheck framework can track specific recheck labels and track a
> state for them.  Add a tool that will restart github workflow runs
> and mark the git build table to check for a repoll.  This will allow
> existing monitor tools to re-poll the workflow and report rerun
> results.
>
> Signed-off-by: Aaron Conole <aconole@redhat.com>
Acked-by: Michael Santana <msantana@redhat.com>
> ---
>  github_restart   | 141 +++++++++++++++++++++++++++++++++++++++++++++++
>  series_db_lib.sh |  16 ++++++
>  2 files changed, 157 insertions(+)
>  create mode 100755 github_restart
>
> diff --git a/github_restart b/github_restart
> new file mode 100755
> index 0000000..5ba9677
> --- /dev/null
> +++ b/github_restart
> @@ -0,0 +1,141 @@
> +#!/bin/bash
> +# SPDX-Identifier: gpl-2.0-or-later
> +# Copyright (C) 2023, Red Hat, Inc.
> +#
> +# Restarts a github job run.  This can be used in conjunction with
> +# the recheck requests to provide the ability for a user to restart
> +# a test - in case the workflow is suspected of having a spurious run.
> +#
> +# Licensed under the terms of the GNU General Public License as published
> +# by the Free Software Foundation; either version 2 of the License, or
> +# (at your option) any later version.  You may obtain a copy of the
> +# license at
> +#
> +#    https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
> +#
> +# Unless required by applicable law or agreed to in writing, software
> +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
> +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
> +# License for the specific language governing permissions and limitations
> +# under the License.
> +
> +wait_start="no"
> +
> +while [ "$1" != "" ]; do
> +    if echo "$1" | grep -q -s -E ^--pw-project= ; then
> +        pw_project=$(echo "$1" | sed s/^--pw-project=//)
> +        shift
> +    elif echo "$1" | grep -q -s -E ^--pw-instance= ; then
> +        pw_instance=$(echo "$1" | sed s/^--pw-instance=//)
> +        shift
> +    elif echo "$1" | grep -q -s -E ^--pw-credentials= ; then
> +        pw_credential=$(echo "$1" | sed s/^--pw-credentials=//)
> +        shift
> +    elif echo "$1" | grep -q -s -E ^--series-id= ; then
> +        series_id=$(echo "$1" | sed s/^--series-id=//)
> +        shift
> +    elif echo "$1" | grep -q -s -E ^--wait-start ; then
> +        wait_start="yes"
> +        if echo "$1" | grep -q -s -E ^--wait-start= ; then
> +            wait_start=$(echo "$1" | sed s/^--wait-start=//)
> +        fi
> +        shift
> +    elif echo "$1" | grep -q -s -E ^--github-token= ; then
> +        github_token=$(echo "$1" | sed s/^--github-token=//)
> +        shift
> +    elif echo "$1" | grep -q -s -E ^--repository= ; then
> +        reponame=$(echo "$1" | sed s/^--repository=//)
> +        shift
> +    elif echo "$1" | grep -q -s -E ^--run-id= ; then
> +        runid=$(echo "$1" | sed s/^--repository=//)
> +        shift
> +    elif echo "$1" | grep -q -s -E ^--sha= ; then
> +        sha=$(echo "$1" | sed s/^--sha=//)
> +        shift
> +    elif echo "$1" | grep -q -s -E ^--workflow= ; then
> +        workflow=$(echo "$1" | sed s/^--workflow=//)
> +        shift
> +    elif echo "$1" | grep -q -s -E ^--help ; then
> +        echo "github restarting script"
> +        echo "$0: args"
> +        echo "  --pw-project=<proj>            Project name"
> +        echo "  --pw-instance=<inst url>       URL for pw"
> +        echo "  --series-id=id         Series ID for reference"
> +        echo "  --github-token=token           Token for github"
> +        echo "  --wait-start[=yes|no]          Wait for the remote to start"
> +        echo "  --repository=repo              Repository name (ex foo/bar)"
> +        echo "  --run-id=id                    run ID"
> +        echo "  --workflow=workflow            Workflow name"
> +        echo "  --sha=commit                   Commit sha"
> +        echo ""
> +        exit 0
> +    else
> +        echo "Unknown option: '$1'" >&2
> +        echo "Rerun with --help for details" >&2
> +        exit 1
> +    fi
> +done
This entire block makes me feel like maybe we should switch to python :)
> +
> +source $(dirname $0)/series_db_lib.sh
> +
> +if [ "X$wait_start" != "Xno" -a "X$wait_start" != "Xyes" ]; then
> +    echo "Unrecognized '$wait_start' argument to --wait-start=" >&2
> +    echo "valid values are 'yes' or 'no'." >&2
> +    exit 1
> +fi
> +
> +if [ "X$github_token" == "X" ]; then
> +    echo "Please set a github API token." >&2
> +    echo "Use --help for more info." >&2
> +    exit 1
> +fi
> +
> +if [ "X$reponame" == "X" ]; then
> +    echo "Please set a repository (ie: '--repository=owner/repo')." >&2
> +    echo "Use --help for more info." >&2
> +    exit 1
> +fi
> +
> +AUTH="Authorization: token ${github_token}"
> +APP="Accept: application/vnd.github.v3+json"
> +
> +if [ "X$runid" == "X" ]; then
> +
> +    # lookup the runs based on the shasum
> +
> +    if [ "X$sha" == "X" ]; then
> +        echo "Need a runid or shasum to key off." >&2
> +        echo "See --help for more details." >&2
> +        exit 1
> +    fi
> +
> +    comma=""
> +    for job in $(curl -s -S -H "${AUTH}" -H "${APP}" \
> +                      "https://api.github.com/repos/${reponame}/actions/runs?head_sha=${sha}" | \
> +                     jq -rc '.workflow_runs[].id')
> +    do
> +        runid="${comma}${job}"
> +        comma=","
> +    done
> +fi
> +
> +echo -n "{\"results\":["
> +comma=""
> +for job in $(echo "$runid" | sed 's/,/ /'); do
> +    result=$(curl -s -X POST -L -S -H "${AUTH}" -H "${APP}" \
> +                  "https://api.github.com/repos/${reponame}/actions/runs/$job/rerun")
Okay!
> +    msg=$(echo "$result" | jq -rc '.message')
> +
> +    echo -n "$comma{\"run\":$job,\"result\":"
> +    if [ "X$msg" == "Xnull" ]; then
> +        echo -n "\"sent\""
> +        if [ "X$series_id" != "X" ]; then
> +            echo -n ",\"gap_sync\":\"reset\""
> +            set_unsynced_for_series "$series_id" "$pw_instance" "gap_sync"
> +        fi
> +    else
> +        echo -n "\"err\",\"error\":\"$msg\""
> +    fi
> +    echo -n "}"
> +done
> +echo "]}"
> diff --git a/series_db_lib.sh b/series_db_lib.sh
> index ca33c1f..3f052ad 100644
> --- a/series_db_lib.sh
> +++ b/series_db_lib.sh
> @@ -382,6 +382,14 @@ function set_synced_for_series() {
>      echo "update git_builds set gap_sync=1, obs_sync=1 where patchwork_instance=\"$instance\" and series_id=$series_id;" | series_db_execute
>  }
>
> +function set_unsynced_for_series() {
> +    local series_id="$1"
> +    local instance="$2"
> +    local ci_instance="$3"
> +
> +    echo "update git_builds set $ci_instance=0 where patchwork_instance=\"$instance\" and series_id=$series_id;" | series_db_execute
> +}
> +
>  function insert_commit() {
>      local series_id="$1"
>      local patch_id="$2"
> @@ -407,6 +415,14 @@ function get_patch_id_by_series_id_and_sha() {
>      echo "select patch_id from git_builds where patchwork_instance=\"$instance\" and series_id=$series_id and sha=\"$sha\";" | series_db_execute
>  }
>
> +function get_sha_for_series_id_and_patch() {
Is this function being used?
> +    local series_id="$1"
> +    local patch_id="$2"
> +    local instance="$3"
> +
> +    echo "select sha from git_builds where patchwork_instance=\"$instance\" and series_id=\"$series_id\" and patch_id=\"$patch_id\"" | series_db_execute
> +}
> +
>  function get_recheck_requests_by_project() {
>      local recheck_instance="$1"
>      local recheck_project="$2"
> --
> 2.41.0
>
  
Aaron Conole Nov. 17, 2023, 7:31 p.m. UTC | #2
Michael Santana <msantana@redhat.com> writes:

> On Tue, Nov 7, 2023 at 3:32 PM Aaron Conole <aconole@redhat.com> wrote:
>>
>> The recheck framework can track specific recheck labels and track a
>> state for them.  Add a tool that will restart github workflow runs
>> and mark the git build table to check for a repoll.  This will allow
>> existing monitor tools to re-poll the workflow and report rerun
>> results.
>>
>> Signed-off-by: Aaron Conole <aconole@redhat.com>
> Acked-by: Michael Santana <msantana@redhat.com>

Thanks.

>> ---
>>  github_restart   | 141 +++++++++++++++++++++++++++++++++++++++++++++++
>>  series_db_lib.sh |  16 ++++++
>>  2 files changed, 157 insertions(+)
>>  create mode 100755 github_restart
>>
>> diff --git a/github_restart b/github_restart
>> new file mode 100755
>> index 0000000..5ba9677
>> --- /dev/null
>> +++ b/github_restart
>> @@ -0,0 +1,141 @@
>> +#!/bin/bash
>> +# SPDX-Identifier: gpl-2.0-or-later
>> +# Copyright (C) 2023, Red Hat, Inc.
>> +#
>> +# Restarts a github job run.  This can be used in conjunction with
>> +# the recheck requests to provide the ability for a user to restart
>> +# a test - in case the workflow is suspected of having a spurious run.
>> +#
>> +# Licensed under the terms of the GNU General Public License as published
>> +# by the Free Software Foundation; either version 2 of the License, or
>> +# (at your option) any later version.  You may obtain a copy of the
>> +# license at
>> +#
>> +#    https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
>> +#
>> +# Unless required by applicable law or agreed to in writing, software
>> +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
>> +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
>> +# License for the specific language governing permissions and limitations
>> +# under the License.
>> +
>> +wait_start="no"
>> +
>> +while [ "$1" != "" ]; do
>> +    if echo "$1" | grep -q -s -E ^--pw-project= ; then
>> +        pw_project=$(echo "$1" | sed s/^--pw-project=//)
>> +        shift
>> +    elif echo "$1" | grep -q -s -E ^--pw-instance= ; then
>> +        pw_instance=$(echo "$1" | sed s/^--pw-instance=//)
>> +        shift
>> +    elif echo "$1" | grep -q -s -E ^--pw-credentials= ; then
>> +        pw_credential=$(echo "$1" | sed s/^--pw-credentials=//)
>> +        shift
>> +    elif echo "$1" | grep -q -s -E ^--series-id= ; then
>> +        series_id=$(echo "$1" | sed s/^--series-id=//)
>> +        shift
>> +    elif echo "$1" | grep -q -s -E ^--wait-start ; then
>> +        wait_start="yes"
>> +        if echo "$1" | grep -q -s -E ^--wait-start= ; then
>> +            wait_start=$(echo "$1" | sed s/^--wait-start=//)
>> +        fi
>> +        shift
>> +    elif echo "$1" | grep -q -s -E ^--github-token= ; then
>> +        github_token=$(echo "$1" | sed s/^--github-token=//)
>> +        shift
>> +    elif echo "$1" | grep -q -s -E ^--repository= ; then
>> +        reponame=$(echo "$1" | sed s/^--repository=//)
>> +        shift
>> +    elif echo "$1" | grep -q -s -E ^--run-id= ; then
>> +        runid=$(echo "$1" | sed s/^--repository=//)
>> +        shift
>> +    elif echo "$1" | grep -q -s -E ^--sha= ; then
>> +        sha=$(echo "$1" | sed s/^--sha=//)
>> +        shift
>> +    elif echo "$1" | grep -q -s -E ^--workflow= ; then
>> +        workflow=$(echo "$1" | sed s/^--workflow=//)
>> +        shift
>> +    elif echo "$1" | grep -q -s -E ^--help ; then
>> +        echo "github restarting script"
>> +        echo "$0: args"
>> +        echo "  --pw-project=<proj>            Project name"
>> +        echo "  --pw-instance=<inst url>       URL for pw"
>> +        echo "  --series-id=id         Series ID for reference"
>> +        echo "  --github-token=token           Token for github"
>> +        echo "  --wait-start[=yes|no]          Wait for the remote to start"
>> +        echo "  --repository=repo              Repository name (ex foo/bar)"
>> +        echo "  --run-id=id                    run ID"
>> +        echo "  --workflow=workflow            Workflow name"
>> +        echo "  --sha=commit                   Commit sha"
>> +        echo ""
>> +        exit 0
>> +    else
>> +        echo "Unknown option: '$1'" >&2
>> +        echo "Rerun with --help for details" >&2
>> +        exit 1
>> +    fi
>> +done
> This entire block makes me feel like maybe we should switch to python :)

Agreed.  We are on shell scripts for the time being, but a good effort
would be to re-do things in python and use better frameworks for
everything (for example, passing data between scripts with json rather
than the sqlite output strings directly).

>> +
>> +source $(dirname $0)/series_db_lib.sh
>> +
>> +if [ "X$wait_start" != "Xno" -a "X$wait_start" != "Xyes" ]; then
>> +    echo "Unrecognized '$wait_start' argument to --wait-start=" >&2
>> +    echo "valid values are 'yes' or 'no'." >&2
>> +    exit 1
>> +fi
>> +
>> +if [ "X$github_token" == "X" ]; then
>> +    echo "Please set a github API token." >&2
>> +    echo "Use --help for more info." >&2
>> +    exit 1
>> +fi
>> +
>> +if [ "X$reponame" == "X" ]; then
>> +    echo "Please set a repository (ie: '--repository=owner/repo')." >&2
>> +    echo "Use --help for more info." >&2
>> +    exit 1
>> +fi
>> +
>> +AUTH="Authorization: token ${github_token}"
>> +APP="Accept: application/vnd.github.v3+json"
>> +
>> +if [ "X$runid" == "X" ]; then
>> +
>> +    # lookup the runs based on the shasum
>> +
>> +    if [ "X$sha" == "X" ]; then
>> +        echo "Need a runid or shasum to key off." >&2
>> +        echo "See --help for more details." >&2
>> +        exit 1
>> +    fi
>> +
>> +    comma=""
>> +    for job in $(curl -s -S -H "${AUTH}" -H "${APP}" \
>> +
>> "https://api.github.com/repos/${reponame}/actions/runs?head_sha=${sha}"
>> | \
>> +                     jq -rc '.workflow_runs[].id')
>> +    do
>> +        runid="${comma}${job}"
>> +        comma=","
>> +    done
>> +fi
>> +
>> +echo -n "{\"results\":["
>> +comma=""
>> +for job in $(echo "$runid" | sed 's/,/ /'); do
>> +    result=$(curl -s -X POST -L -S -H "${AUTH}" -H "${APP}" \
>> +                  "https://api.github.com/repos/${reponame}/actions/runs/$job/rerun")
> Okay!
>> +    msg=$(echo "$result" | jq -rc '.message')
>> +
>> +    echo -n "$comma{\"run\":$job,\"result\":"
>> +    if [ "X$msg" == "Xnull" ]; then
>> +        echo -n "\"sent\""
>> +        if [ "X$series_id" != "X" ]; then
>> +            echo -n ",\"gap_sync\":\"reset\""
>> +            set_unsynced_for_series "$series_id" "$pw_instance" "gap_sync"
>> +        fi
>> +    else
>> +        echo -n "\"err\",\"error\":\"$msg\""
>> +    fi
>> +    echo -n "}"
>> +done
>> +echo "]}"
>> diff --git a/series_db_lib.sh b/series_db_lib.sh
>> index ca33c1f..3f052ad 100644
>> --- a/series_db_lib.sh
>> +++ b/series_db_lib.sh
>> @@ -382,6 +382,14 @@ function set_synced_for_series() {
>>      echo "update git_builds set gap_sync=1, obs_sync=1 where patchwork_instance=\"$instance\" and series_id=$series_id;" | series_db_execute
>>  }
>>
>> +function set_unsynced_for_series() {
>> +    local series_id="$1"
>> +    local instance="$2"
>> +    local ci_instance="$3"
>> +
>> +    echo "update git_builds set $ci_instance=0 where patchwork_instance=\"$instance\" and series_id=$series_id;" | series_db_execute
>> +}
>> +
>>  function insert_commit() {
>>      local series_id="$1"
>>      local patch_id="$2"
>> @@ -407,6 +415,14 @@ function get_patch_id_by_series_id_and_sha() {
>>      echo "select patch_id from git_builds where patchwork_instance=\"$instance\" and series_id=$series_id and sha=\"$sha\";" | series_db_execute
>>  }
>>
>> +function get_sha_for_series_id_and_patch() {
> Is this function being used?

Yes - but it should have appeared in 2/3 rather than here in 3/3.  I'll
fix it before applying things and I plan to send a PATCH series out with
those changes as well.

>> +    local series_id="$1"
>> +    local patch_id="$2"
>> +    local instance="$3"
>> +
>> +    echo "select sha from git_builds where patchwork_instance=\"$instance\" and series_id=\"$series_id\" and patch_id=\"$patch_id\"" | series_db_execute
>> +}
>> +
>>  function get_recheck_requests_by_project() {
>>      local recheck_instance="$1"
>>      local recheck_project="$2"
>> --
>> 2.41.0
>>
  
Michael Santana Nov. 17, 2023, 10:20 p.m. UTC | #3
On Fri, Nov 17, 2023 at 2:31 PM Aaron Conole <aconole@redhat.com> wrote:
>
> Michael Santana <msantana@redhat.com> writes:
>
> > On Tue, Nov 7, 2023 at 3:32 PM Aaron Conole <aconole@redhat.com> wrote:
> >>
> >> The recheck framework can track specific recheck labels and track a
> >> state for them.  Add a tool that will restart github workflow runs
> >> and mark the git build table to check for a repoll.  This will allow
> >> existing monitor tools to re-poll the workflow and report rerun
> >> results.
> >>
> >> Signed-off-by: Aaron Conole <aconole@redhat.com>
> > Acked-by: Michael Santana <msantana@redhat.com>
>
> Thanks.
>
> >> ---
> >>  github_restart   | 141 +++++++++++++++++++++++++++++++++++++++++++++++
> >>  series_db_lib.sh |  16 ++++++
> >>  2 files changed, 157 insertions(+)
> >>  create mode 100755 github_restart
> >>
> >> diff --git a/github_restart b/github_restart
> >> new file mode 100755
> >> index 0000000..5ba9677
> >> --- /dev/null
> >> +++ b/github_restart
> >> @@ -0,0 +1,141 @@
> >> +#!/bin/bash
> >> +# SPDX-Identifier: gpl-2.0-or-later
> >> +# Copyright (C) 2023, Red Hat, Inc.
> >> +#
> >> +# Restarts a github job run.  This can be used in conjunction with
> >> +# the recheck requests to provide the ability for a user to restart
> >> +# a test - in case the workflow is suspected of having a spurious run.
> >> +#
> >> +# Licensed under the terms of the GNU General Public License as published
> >> +# by the Free Software Foundation; either version 2 of the License, or
> >> +# (at your option) any later version.  You may obtain a copy of the
> >> +# license at
> >> +#
> >> +#    https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
> >> +#
> >> +# Unless required by applicable law or agreed to in writing, software
> >> +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
> >> +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
> >> +# License for the specific language governing permissions and limitations
> >> +# under the License.
> >> +
> >> +wait_start="no"
> >> +
> >> +while [ "$1" != "" ]; do
> >> +    if echo "$1" | grep -q -s -E ^--pw-project= ; then
> >> +        pw_project=$(echo "$1" | sed s/^--pw-project=//)
> >> +        shift
> >> +    elif echo "$1" | grep -q -s -E ^--pw-instance= ; then
> >> +        pw_instance=$(echo "$1" | sed s/^--pw-instance=//)
> >> +        shift
> >> +    elif echo "$1" | grep -q -s -E ^--pw-credentials= ; then
> >> +        pw_credential=$(echo "$1" | sed s/^--pw-credentials=//)
> >> +        shift
> >> +    elif echo "$1" | grep -q -s -E ^--series-id= ; then
> >> +        series_id=$(echo "$1" | sed s/^--series-id=//)
> >> +        shift
> >> +    elif echo "$1" | grep -q -s -E ^--wait-start ; then
> >> +        wait_start="yes"
> >> +        if echo "$1" | grep -q -s -E ^--wait-start= ; then
> >> +            wait_start=$(echo "$1" | sed s/^--wait-start=//)
> >> +        fi
> >> +        shift
> >> +    elif echo "$1" | grep -q -s -E ^--github-token= ; then
> >> +        github_token=$(echo "$1" | sed s/^--github-token=//)
> >> +        shift
> >> +    elif echo "$1" | grep -q -s -E ^--repository= ; then
> >> +        reponame=$(echo "$1" | sed s/^--repository=//)
> >> +        shift
> >> +    elif echo "$1" | grep -q -s -E ^--run-id= ; then
> >> +        runid=$(echo "$1" | sed s/^--repository=//)
> >> +        shift
> >> +    elif echo "$1" | grep -q -s -E ^--sha= ; then
> >> +        sha=$(echo "$1" | sed s/^--sha=//)
> >> +        shift
> >> +    elif echo "$1" | grep -q -s -E ^--workflow= ; then
> >> +        workflow=$(echo "$1" | sed s/^--workflow=//)
> >> +        shift
> >> +    elif echo "$1" | grep -q -s -E ^--help ; then
> >> +        echo "github restarting script"
> >> +        echo "$0: args"
> >> +        echo "  --pw-project=<proj>            Project name"
> >> +        echo "  --pw-instance=<inst url>       URL for pw"
> >> +        echo "  --series-id=id         Series ID for reference"
> >> +        echo "  --github-token=token           Token for github"
> >> +        echo "  --wait-start[=yes|no]          Wait for the remote to start"
> >> +        echo "  --repository=repo              Repository name (ex foo/bar)"
> >> +        echo "  --run-id=id                    run ID"
> >> +        echo "  --workflow=workflow            Workflow name"
> >> +        echo "  --sha=commit                   Commit sha"
> >> +        echo ""
> >> +        exit 0
> >> +    else
> >> +        echo "Unknown option: '$1'" >&2
> >> +        echo "Rerun with --help for details" >&2
> >> +        exit 1
> >> +    fi
> >> +done
> > This entire block makes me feel like maybe we should switch to python :)
>
> Agreed.  We are on shell scripts for the time being, but a good effort
> would be to re-do things in python and use better frameworks for
> everything (for example, passing data between scripts with json rather
> than the sqlite output strings directly).
I wonder how useful ChatGPT and its siblings would be at converting
all of our shell scripts into python :P
>
> >> +
> >> +source $(dirname $0)/series_db_lib.sh
> >> +
> >> +if [ "X$wait_start" != "Xno" -a "X$wait_start" != "Xyes" ]; then
> >> +    echo "Unrecognized '$wait_start' argument to --wait-start=" >&2
> >> +    echo "valid values are 'yes' or 'no'." >&2
> >> +    exit 1
> >> +fi
> >> +
> >> +if [ "X$github_token" == "X" ]; then
> >> +    echo "Please set a github API token." >&2
> >> +    echo "Use --help for more info." >&2
> >> +    exit 1
> >> +fi
> >> +
> >> +if [ "X$reponame" == "X" ]; then
> >> +    echo "Please set a repository (ie: '--repository=owner/repo')." >&2
> >> +    echo "Use --help for more info." >&2
> >> +    exit 1
> >> +fi
> >> +
> >> +AUTH="Authorization: token ${github_token}"
> >> +APP="Accept: application/vnd.github.v3+json"
> >> +
> >> +if [ "X$runid" == "X" ]; then
> >> +
> >> +    # lookup the runs based on the shasum
> >> +
> >> +    if [ "X$sha" == "X" ]; then
> >> +        echo "Need a runid or shasum to key off." >&2
> >> +        echo "See --help for more details." >&2
> >> +        exit 1
> >> +    fi
> >> +
> >> +    comma=""
> >> +    for job in $(curl -s -S -H "${AUTH}" -H "${APP}" \
> >> +
> >> "https://api.github.com/repos/${reponame}/actions/runs?head_sha=${sha}"
> >> | \
> >> +                     jq -rc '.workflow_runs[].id')
> >> +    do
> >> +        runid="${comma}${job}"
> >> +        comma=","
> >> +    done
> >> +fi
> >> +
> >> +echo -n "{\"results\":["
> >> +comma=""
> >> +for job in $(echo "$runid" | sed 's/,/ /'); do
> >> +    result=$(curl -s -X POST -L -S -H "${AUTH}" -H "${APP}" \
> >> +                  "https://api.github.com/repos/${reponame}/actions/runs/$job/rerun")
> > Okay!
> >> +    msg=$(echo "$result" | jq -rc '.message')
> >> +
> >> +    echo -n "$comma{\"run\":$job,\"result\":"
> >> +    if [ "X$msg" == "Xnull" ]; then
> >> +        echo -n "\"sent\""
> >> +        if [ "X$series_id" != "X" ]; then
> >> +            echo -n ",\"gap_sync\":\"reset\""
> >> +            set_unsynced_for_series "$series_id" "$pw_instance" "gap_sync"
> >> +        fi
> >> +    else
> >> +        echo -n "\"err\",\"error\":\"$msg\""
> >> +    fi
> >> +    echo -n "}"
> >> +done
> >> +echo "]}"
> >> diff --git a/series_db_lib.sh b/series_db_lib.sh
> >> index ca33c1f..3f052ad 100644
> >> --- a/series_db_lib.sh
> >> +++ b/series_db_lib.sh
> >> @@ -382,6 +382,14 @@ function set_synced_for_series() {
> >>      echo "update git_builds set gap_sync=1, obs_sync=1 where patchwork_instance=\"$instance\" and series_id=$series_id;" | series_db_execute
> >>  }
> >>
> >> +function set_unsynced_for_series() {
> >> +    local series_id="$1"
> >> +    local instance="$2"
> >> +    local ci_instance="$3"
> >> +
> >> +    echo "update git_builds set $ci_instance=0 where patchwork_instance=\"$instance\" and series_id=$series_id;" | series_db_execute
> >> +}
> >> +
> >>  function insert_commit() {
> >>      local series_id="$1"
> >>      local patch_id="$2"
> >> @@ -407,6 +415,14 @@ function get_patch_id_by_series_id_and_sha() {
> >>      echo "select patch_id from git_builds where patchwork_instance=\"$instance\" and series_id=$series_id and sha=\"$sha\";" | series_db_execute
> >>  }
> >>
> >> +function get_sha_for_series_id_and_patch() {
> > Is this function being used?
>
> Yes - but it should have appeared in 2/3 rather than here in 3/3.  I'll
> fix it before applying things and I plan to send a PATCH series out with
> those changes as well.
>
> >> +    local series_id="$1"
> >> +    local patch_id="$2"
> >> +    local instance="$3"
> >> +
> >> +    echo "select sha from git_builds where patchwork_instance=\"$instance\" and series_id=\"$series_id\" and patch_id=\"$patch_id\"" | series_db_execute
> >> +}
> >> +
> >>  function get_recheck_requests_by_project() {
> >>      local recheck_instance="$1"
> >>      local recheck_project="$2"
> >> --
> >> 2.41.0
> >>
>
  

Patch

diff --git a/github_restart b/github_restart
new file mode 100755
index 0000000..5ba9677
--- /dev/null
+++ b/github_restart
@@ -0,0 +1,141 @@ 
+#!/bin/bash
+# SPDX-Identifier: gpl-2.0-or-later
+# Copyright (C) 2023, Red Hat, Inc.
+#
+# Restarts a github job run.  This can be used in conjunction with
+# the recheck requests to provide the ability for a user to restart
+# a test - in case the workflow is suspected of having a spurious run.
+#
+# Licensed under the terms of the GNU General Public License as published
+# by the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.  You may obtain a copy of the
+# license at
+#
+#    https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+wait_start="no"
+
+while [ "$1" != "" ]; do
+    if echo "$1" | grep -q -s -E ^--pw-project= ; then
+        pw_project=$(echo "$1" | sed s/^--pw-project=//)
+        shift
+    elif echo "$1" | grep -q -s -E ^--pw-instance= ; then
+        pw_instance=$(echo "$1" | sed s/^--pw-instance=//)
+        shift
+    elif echo "$1" | grep -q -s -E ^--pw-credentials= ; then
+        pw_credential=$(echo "$1" | sed s/^--pw-credentials=//)
+        shift
+    elif echo "$1" | grep -q -s -E ^--series-id= ; then
+        series_id=$(echo "$1" | sed s/^--series-id=//)
+        shift
+    elif echo "$1" | grep -q -s -E ^--wait-start ; then
+        wait_start="yes"
+        if echo "$1" | grep -q -s -E ^--wait-start= ; then
+            wait_start=$(echo "$1" | sed s/^--wait-start=//)
+        fi
+        shift
+    elif echo "$1" | grep -q -s -E ^--github-token= ; then
+        github_token=$(echo "$1" | sed s/^--github-token=//)
+        shift
+    elif echo "$1" | grep -q -s -E ^--repository= ; then
+        reponame=$(echo "$1" | sed s/^--repository=//)
+        shift
+    elif echo "$1" | grep -q -s -E ^--run-id= ; then
+        runid=$(echo "$1" | sed s/^--repository=//)
+        shift
+    elif echo "$1" | grep -q -s -E ^--sha= ; then
+        sha=$(echo "$1" | sed s/^--sha=//)
+        shift
+    elif echo "$1" | grep -q -s -E ^--workflow= ; then
+        workflow=$(echo "$1" | sed s/^--workflow=//)
+        shift
+    elif echo "$1" | grep -q -s -E ^--help ; then
+        echo "github restarting script"
+        echo "$0: args"
+        echo "  --pw-project=<proj>		Project name"
+        echo "  --pw-instance=<inst url>	URL for pw"
+        echo "  --series-id=id		Series ID for reference"
+        echo "  --github-token=token		Token for github"
+        echo "  --wait-start[=yes|no]		Wait for the remote to start"
+        echo "  --repository=repo		Repository name (ex foo/bar)"
+        echo "  --run-id=id			run ID"
+        echo "  --workflow=workflow		Workflow name"
+        echo "  --sha=commit			Commit sha"
+        echo ""
+        exit 0
+    else
+        echo "Unknown option: '$1'" >&2
+        echo "Rerun with --help for details" >&2
+        exit 1
+    fi
+done
+
+source $(dirname $0)/series_db_lib.sh
+
+if [ "X$wait_start" != "Xno" -a "X$wait_start" != "Xyes" ]; then
+    echo "Unrecognized '$wait_start' argument to --wait-start=" >&2
+    echo "valid values are 'yes' or 'no'." >&2
+    exit 1
+fi
+
+if [ "X$github_token" == "X" ]; then
+    echo "Please set a github API token." >&2
+    echo "Use --help for more info." >&2
+    exit 1
+fi
+
+if [ "X$reponame" == "X" ]; then
+    echo "Please set a repository (ie: '--repository=owner/repo')." >&2
+    echo "Use --help for more info." >&2
+    exit 1
+fi
+
+AUTH="Authorization: token ${github_token}"
+APP="Accept: application/vnd.github.v3+json"
+
+if [ "X$runid" == "X" ]; then
+
+    # lookup the runs based on the shasum
+
+    if [ "X$sha" == "X" ]; then
+        echo "Need a runid or shasum to key off." >&2
+        echo "See --help for more details." >&2
+        exit 1
+    fi
+
+    comma=""
+    for job in $(curl -s -S -H "${AUTH}" -H "${APP}" \
+                      "https://api.github.com/repos/${reponame}/actions/runs?head_sha=${sha}" | \
+                     jq -rc '.workflow_runs[].id')
+    do
+        runid="${comma}${job}"
+        comma=","
+    done
+fi
+
+echo -n "{\"results\":["
+comma=""
+for job in $(echo "$runid" | sed 's/,/ /'); do
+    result=$(curl -s -X POST -L -S -H "${AUTH}" -H "${APP}" \
+                  "https://api.github.com/repos/${reponame}/actions/runs/$job/rerun")
+    msg=$(echo "$result" | jq -rc '.message')
+
+    echo -n "$comma{\"run\":$job,\"result\":"
+    if [ "X$msg" == "Xnull" ]; then
+        echo -n "\"sent\""
+        if [ "X$series_id" != "X" ]; then
+            echo -n ",\"gap_sync\":\"reset\""
+            set_unsynced_for_series "$series_id" "$pw_instance" "gap_sync"
+        fi
+    else
+        echo -n "\"err\",\"error\":\"$msg\""
+    fi
+    echo -n "}"
+done
+echo "]}"
diff --git a/series_db_lib.sh b/series_db_lib.sh
index ca33c1f..3f052ad 100644
--- a/series_db_lib.sh
+++ b/series_db_lib.sh
@@ -382,6 +382,14 @@  function set_synced_for_series() {
     echo "update git_builds set gap_sync=1, obs_sync=1 where patchwork_instance=\"$instance\" and series_id=$series_id;" | series_db_execute
 }
 
+function set_unsynced_for_series() {
+    local series_id="$1"
+    local instance="$2"
+    local ci_instance="$3"
+
+    echo "update git_builds set $ci_instance=0 where patchwork_instance=\"$instance\" and series_id=$series_id;" | series_db_execute
+}
+
 function insert_commit() {
     local series_id="$1"
     local patch_id="$2"
@@ -407,6 +415,14 @@  function get_patch_id_by_series_id_and_sha() {
     echo "select patch_id from git_builds where patchwork_instance=\"$instance\" and series_id=$series_id and sha=\"$sha\";" | series_db_execute
 }
 
+function get_sha_for_series_id_and_patch() {
+    local series_id="$1"
+    local patch_id="$2"
+    local instance="$3"
+
+    echo "select sha from git_builds where patchwork_instance=\"$instance\" and series_id=\"$series_id\" and patch_id=\"$patch_id\"" | series_db_execute
+}
+
 function get_recheck_requests_by_project() {
     local recheck_instance="$1"
     local recheck_project="$2"