Skip to content

Commit

Permalink
Merge pull request #119 from redhatci/maybe
Browse files Browse the repository at this point in the history
dci.yml: Maybe Schedule a DCI Job
  • Loading branch information
fredericlepied authored Jan 5, 2024
2 parents 74bf6bb + b891857 commit 117a05e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 8 deletions.
14 changes: 6 additions & 8 deletions .github/workflows/dci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
...
46 changes: 46 additions & 0 deletions hack/maybe-dci-check-change
Original file line number Diff line number Diff line 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

0 comments on commit 117a05e

Please sign in to comment.