Skip to content

Commit

Permalink
fix DCI merge queue job
Browse files Browse the repository at this point in the history
  • Loading branch information
fredericlepied committed Jan 6, 2024
1 parent ceb04c6 commit 49c1fae
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 6 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/dci-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
jobs:

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

Expand All @@ -19,7 +19,9 @@ jobs:
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
echo "Starting DCI job"
export GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
./hack/dci-merge.sh ${{ github.event.merge_group.head_sha }}
else
echo "No code change"
fi
Expand Down
15 changes: 11 additions & 4 deletions hack/dci-merge.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
#
# Copyright (C) 2023 Red Hat, Inc.
# Copyright (C) 2023, 2024 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
Expand All @@ -16,6 +16,8 @@

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

HEAD_SHA="$1"
STATUSES_URL="https://api.github.com/repos/redhatci/ansible-collection-redhatci-ocp/statuses/$HEAD_SHA"
VIRT=
DCI_QUEUE=
SNO_DCI_QUEUE=
Expand All @@ -42,7 +44,7 @@ GH_HEADERS=(
COMMIT=HEAD
VIRT=
while true; do
PR=$(git log -1 "$COMMIT"|grep -oP 'Merge pull request #\K\d+')
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)

Expand Down Expand Up @@ -136,13 +138,18 @@ while true; do
COMMIT="${COMMIT}^"
done

# if nothing is specified
if [ -z "$VIRT" ]; then
VIRT=--virt
fi

CLCTDIR="$(cd .; pwd)"
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-queue schedule --block "$DCI_QUEUE" -- env GITHUB_TOKEN=$GITHUB_TOKEN STATUSES_URL=$STATUSES_URL DCI_SILENT=$DCI_SILENT UPGRADE_ARGS="$UPGRADE_ARGS" APP_NAME=$APP_NAME APP_ARGS="$APP_ARGS" $CLCTDIR/hack/test-runner-wrapper $VIRT $FORCE_CHECK $TAG $UPGRADE $NO_COMMENT $DIR -p @RESOURCE $OPTS

# dci-merge.sh ends here
43 changes: 43 additions & 0 deletions hack/test-runner-wrapper
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash
#
# Copyright (C) 2024 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.

GITHUB_JOBNAME="DCI / DCI Job"

# 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}"
)

send_status() {
curl -s "${GH_HEADERS[@]/#/-H}" -X POST -d "{\"state\":\"$1\",\"context\":\"$GITHUB_JOBNAME\"}" "$STATUSES_URL"
}

set -x

if /usr/share/dci-openshift-agent/test-runner "$@"; then
send_status success
exit 0
else
send_status failure
exit 1
fi

# test-runner-wrapper ends here

0 comments on commit 49c1fae

Please sign in to comment.