From b891857572a2c03d45ead5e510c57fb3efd2fbfb Mon Sep 17 00:00:00 2001 From: Frederic Lepied Date: Fri, 5 Jan 2024 21:35:48 +0100 Subject: [PATCH] dci.yml: Maybe Schedule a DCI Job --- .github/workflows/dci.yml | 14 +++++------ hack/maybe-dci-check-change | 46 +++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 8 deletions(-) create mode 100755 hack/maybe-dci-check-change diff --git a/.github/workflows/dci.yml b/.github/workflows/dci.yml index 3fd09d6ce..64ea8e119 100644 --- a/.github/workflows/dci.yml +++ b/.github/workflows/dci.yml @@ -7,18 +7,16 @@ on: jobs: dci-job: - name: "DCI Job" + name: "Maybe Schedule a DCI Job" runs-on: bos2 steps: - - name: Add a dci-check-change job to the queue + - name: Checkout + uses: actions/checkout@v4 + + - name: Maybe call dci-check-change run: | 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 + ./hack/maybe-dci-check-change ${{ github.event.pull_request.html_url }} ... diff --git a/hack/maybe-dci-check-change b/hack/maybe-dci-check-change new file mode 100755 index 000000000..1c22f2bd3 --- /dev/null +++ b/hack/maybe-dci-check-change @@ -0,0 +1,46 @@ +#!/usr/bin/env 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. + +set -e + +BASEDIR=/usr/share/dci-pipeline +GITHUB_JOBNAME="DCI / DCI Job" + +. "$BASEDIR/common" + +URL="$1" + +GITHUB_REPO_TOKEN=$($BASEDIR/get-config-entry "https://github.com/$proj" github_token "$GITHUB_TOKEN") + +if [ -n "$GITHUB_REPO_TOKEN" ]; then + AUTH=(-H "Authorization: token $GITHUB_REPO_TOKEN") +else + AUTH=() +fi + +if curl -s -L -H "Accept: application/vnd.github+json" "${AUTH[@]}" "${URL}/files"|jq -r .[].filename|grep -v '\.md$'|grep -E 'roles/|plugins/'; then + dci-check-change --silent "$URL" +else + pr=$(sed -e 's@.*/pull/'@@ <<< $URL) + proj=$(sed -e 's@https://github.com/\(.*\)/pull/.*@\1@i' <<< $URL) + json=$(curl -s -H "Accept: application/vnd.github.v3+json" "${AUTH[@]}" https://api.github.com/repos/$proj/pulls/$pr) + STATUSES_URL=$(jq -r .statuses_url <<< $json) + curl -s -H "Accept: application/vnd.github+json" -H "Authorization: token $GITHUB_REPO_TOKEN" -X POST -d "{\"state\":\"success\",\"context\":\"$GITHUB_JOBNAME\",\"description\": \"non code files\"}" "$STATUSES_URL" +fi + +exit 0 + +# maybe-dci-check-change ends here