Skip to content

Commit

Permalink
merge queue support
Browse files Browse the repository at this point in the history
  • Loading branch information
fredericlepied committed Jan 2, 2024
1 parent 55ec81b commit 016443f
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 7 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/dci-merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---

name: DCI Schedule
on:
merge_group:
jobs:

dci-job:
name: "Schedule a DCI job"
runs-on: bos2
steps:

- name: Checkout
uses: actions/checkout@v4

- name: Run a DCI Job
run: |
git fetch origin ${{ github.event.merge_group.base_sha }}
git fetch origin ${{ github.event.merge_group.head_sha }}
if git diff --name-only ${{ github.event.merge_group.base_sha }} ${{ github.event.merge_group.head_sha }} | grep -E 'roles/|plugins/'; then
./hack/dci-merge.sh
else
echo "No code change"
fi
...
14 changes: 9 additions & 5 deletions .github/workflows/dci.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
---

name: DCI Schedule
name: DCI
on:
pull_request:
types: [opened, synchronize, reopened]
paths:
- 'roles/**'
jobs:

dci-job:
name: "Schedule a DCI job"
name: "DCI Job"
runs-on: bos2
steps:

- name: Add a dci-check-change job to the queue
run: |
dci-check-change --silent ${{ github.event.pull_request.html_url }}
set -x
URL="${{ github.event.pull_request._links.self.href }}"
if curl -s -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ github.token }}" -H "X-GitHub-Api-Version: 2022-11-28" "${URL}/files"|jq -r .[].filename| grep -E 'roles/|plugins/'; then
dci-check-change --silent ${{ github.event.pull_request.html_url }}
else
echo "No code change"
fi
...
3 changes: 1 addition & 2 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Pull Request
on:
pull_request:
types: [opened, synchronize, reopened]
merge_group:
jobs:
ansible-lint:
name: Compute ansible-lint score
Expand Down Expand Up @@ -118,8 +119,6 @@ jobs:
name: "Check all dependencies are merged"
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Check all dependent Pull Requests are merged
uses: depends-on/depends-on-action@main
Expand Down
148 changes: 148 additions & 0 deletions hack/dci-merge.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
#!/usr/bin/env bash
#
# Copyright (C) 2023 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# 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.

# script called from a merge queue branch of the redhatci/ansible-collection-redhatci-ocp repo

VIRT=
DCI_QUEUE=
SNO_DCI_QUEUE=
SUPPORTED_HINTS=
NO_DCI_QUEUE=${NO_DCI_QUEUE:-}
NO_COMMENT=
UPGRADE=
UPGRADE_ARGS=
APP_NAME=
APP_ARGS=
FORCE_CHECK=

# shellcheck disable=SC1091
if [ -r /etc/dci-openshift-agent/config ]; then
. /etc/dci-openshift-agent/config
fi

GH_HEADERS=(
"Accept: application/vnd.github.v3+json"
"Authorization: token ${GITHUB_TOKEN}"
)

# Lookup the merge commits and get their PR descriptions to detect Test-Hints: strings
COMMIT=HEAD
VIRT=
while true; do
PR=$(git log -1 "$COMMIT"|grep -oP 'Merge pull request #\K\d+')
if [ -n "$PR" ]; then
DESC=$(curl -s "${GH_HEADERS[@]/#/-H}" https://api.github.com/repos/redhatci/ansible-collection-redhatci-ocp/pulls/"$PR"|jq -r .body)

if [[ sno =~ $SUPPORTED_HINTS ]] && grep -qi "^\s*Test-Hints:\s*sno\s*" <<< "$DESC"; then
VIRT=--sno
if [ -n "$SNO_DCI_QUEUE" ]; then
DCI_QUEUE="$SNO_DCI_QUEUE"
fi
fi

if [[ sno-ai =~ $SUPPORTED_HINTS ]] && grep -qi "^\s*Test-Hints:\s*sno-ai\s*" <<< "$DESC"; then
VIRT=--sno-ai
if [ -n "$SNO_AI_DCI_QUEUE" ]; then
DCI_QUEUE="$SNO_AI_DCI_QUEUE"
fi
fi

if [[ assisted =~ $SUPPORTED_HINTS ]] && grep -qi "^\s*Test-Hints:\s*assisted\s*" <<< "$DESC"; then
VIRT=--assisted
if [ -n "$ASSISTED_DCI_QUEUE" ]; then
DCI_QUEUE="$ASSISTED_DCI_QUEUE"
fi
fi

if [[ assisted-abi =~ $SUPPORTED_HINTS ]] && grep -qi "^\s*Test-Hints:\s*assisted-abi\s*" <<< "$DESC"; then
VIRT=--assisted-abi
if [ -n "$ASSISTED_DCI_QUEUE" ]; then
DCI_QUEUE="$ASSISTED_DCI_QUEUE"
fi
fi

if [[ libvirt =~ $SUPPORTED_HINTS ]] && grep -qi "^\s*Test-Hints:\s*libvirt\s*" <<< "$DESC"; then
VIRT=--virt
fi

if [[ no-check =~ $SUPPORTED_HINTS ]] && grep -qi "^\s*Test-Hints:\s*no-check\s*" <<< "$DESC"; then
continue
fi

if [[ force-check =~ $SUPPORTED_HINTS ]] && grep -qi "^\s*Test-Hints:\s*force-check\s*" <<< "$DESC"; then
FORCE_CHECK=--force-check
fi

if [[ upgrade =~ $SUPPORTED_HINTS ]] && grep -qi "^\s*Test-Upgrade-Hints:\s*yes\s*" <<< "$DESC"; then
UPGRADE=--upgrade

if [ -z "$VIRT" ]; then
VIRT=--virt
fi

# process Test-Upgrade-Args-Hints
if [[ upgrade-args =~ $SUPPORTED_HINTS ]] && grep -qi "^\s*Test-Upgrade-Args-Hints:" <<< "$DESC"; then
UPGRADE_ARGS="$(sed -n -e 's/^\s*Test-Upgrade-Args-Hints:\s*//pi' <<< "$DESC")"
fi

# process Test-Upgrade-From-Topic-Hints
if [[ upgrade-from-topic =~ $SUPPORTED_HINTS ]] && grep -qi "^\s*Test-Upgrade-From-Topic-Hints:" <<< "$DESC"; then
UPGRADE="$UPGRADE --from-topic $(sed -n -e 's/^\s*Test-Upgrade-From-Topic-Hints:\s*//pi' <<< "$DESC")"
fi

# process Test-Upgrade-To-Topic-Hints
if [[ upgrade-to-topic =~ $SUPPORTED_HINTS ]] && grep -qi "^\s*Test-Upgrade-To-Topic-Hints:" <<< "$DESC"; then
UPGRADE="$UPGRADE --to-topic $(sed -n -e 's/^\s*Test-Upgrade-To-Topic-Hints:\s*//pi' <<< "$DESC")"
fi
fi

if [ -n "$VIRT" ]; then
# process Test-Args-Hints
if [[ args =~ $SUPPORTED_HINTS ]]; then
OPTS=$(sed -n -e "s/^\s*Test-Args-Hints:\s*//pi" <<< "$DESC")
else
OPTS=
fi

# process Test-App-Hints
if [[ app =~ $SUPPORTED_HINTS ]]; then
APP_NAME=$(sed -n -e "s/^\s*Test-App-Hints:\s*//pi" <<< "$DESC")
fi

# process Test-App-Args-Hints
if [[ app-args =~ $SUPPORTED_HINTS ]]; then
APP_ARGS=$(sed -n -e "s/^\s*Test-App-Args-Hints:\s*//pi" <<< "$DESC")
fi

# stop at the first valid Test-Hints: string
break
fi
else
break
fi
COMMIT="${COMMIT}^"
done

DIR="$(cd ..; pwd)"
BASEDIR=/usr/share/dci-openshift-agent
export DCI_SILENT=1

cd "$DIR" || exit 1

# shellcheck disable=SC2086
dci-queue schedule --block -C "$DCI_QUEUE" -- env DCI_SILENT=$DCI_SILENT UPGRADE_ARGS="$UPGRADE_ARGS" RES=@RESOURCE APP_NAME=$APP_NAME APP_ARGS="$APP_ARGS" $BASEDIR/test-runner $VIRT $FORCE_CHECK $TAG $UPGRADE $NO_COMMENT $DIR "$@" $OPTS

# dci-merge.sh ends here

0 comments on commit 016443f

Please sign in to comment.