diff --git a/.github/workflows/dci-merge.yml b/.github/workflows/dci-merge.yml index 5605d82a6..3d3d0673f 100644 --- a/.github/workflows/dci-merge.yml +++ b/.github/workflows/dci-merge.yml @@ -6,12 +6,14 @@ on: jobs: dci-job: - name: "DCI" + name: "DCI Merge Job" runs-on: bos2 steps: - name: Checkout uses: actions/checkout@v4 + with: + fetch-depth: 0 # Fetch all history to be able to look at all the merge commits in dci-merge.sh - name: DCI Job run: | @@ -19,7 +21,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 diff --git a/hack/dci-merge.sh b/hack/dci-merge.sh index 4d4e48b72..9a868e66f 100755 --- a/hack/dci-merge.sh +++ b/hack/dci-merge.sh @@ -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 @@ -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= @@ -38,11 +40,13 @@ GH_HEADERS=( "Authorization: token ${GITHUB_TOKEN}" ) +set -x + # 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+') + 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) @@ -136,13 +140,21 @@ while true; do COMMIT="${COMMIT}^" done -DIR="$(cd ..; pwd)" -BASEDIR=/usr/share/dci-openshift-agent -export DCI_SILENT=1 +# if nothing is specified +if [ -z "$VIRT" ]; then + VIRT=--virt +fi + +# copy the change to another directory to let test-runner manage it +DIR=$HOME/github/ansible-collection-redhatci-ocp-mq-$HEAD_SHA +mkdir -p "$DIR" +cp -a "$PWD/" "$DIR/" +CLCTDIR=$DIR/ansible-collection-redhatci-ocp cd "$DIR" || exit 1 +export DCI_SILENT=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 "$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 diff --git a/hack/test-runner-wrapper b/hack/test-runner-wrapper new file mode 100755 index 000000000..7a25e862d --- /dev/null +++ b/hack/test-runner-wrapper @@ -0,0 +1,45 @@ +#!/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 + +send_status pending + +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