Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dci.yml: Maybe Schedule a DCI Job #119

Merged
merged 1 commit into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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