Bump actions/setup-python from 4.6.1 to 5.0.0 #4
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Lint CODEOWNERS checks | |
env: | |
REPOSITY_NAME: github.com/koffloader-io/koffloader | |
# Any change in triggers needs to be reflected in the concurrency group. | |
on: | |
pull_request: | |
branches: | |
- main | |
permissions: read-all | |
jobs: | |
# find all changed files from PR | |
check_changes: | |
name: Deduce required tests from code changes | |
runs-on: ubuntu-latest | |
outputs: | |
added-files: ${{ steps.changes.outputs.added-files }} | |
deleted-files: ${{ steps.changes.outputs.deleted-files }} | |
codeowners-changed: ${{ steps.changes.outputs.codeowners-changed }} | |
steps: | |
- name: Check code changes | |
uses: dorny/paths-filter@v2.11.1 | |
id: changes | |
with: | |
filters: | | |
added-files: | |
- added: '**' | |
deleted-files: | |
- deleted: '**' | |
codeowners-changed: | |
- 'CODEOWNERS' | |
# check whether there is owner relationship entry on CODEOWNERS for the changed file | |
codeowners: | |
needs: check_changes | |
if: ${{ needs.check_changes.outputs.added-files == 'true' || needs.check_changes.outputs.deleted-files == 'true' }} | |
name: Check CODEOWNERS consistency | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
persist-credentials: false | |
# Hard-code the path instead of using ${{ github.repository }} | |
# to make sure it works for forked repo as well. | |
path: src/${{ env.REPOSITY_NAME }} | |
# for adding files on the PR , check whether there is relationship entry on the CODEOWNERS | |
- name: Check if all files have attributed code owners | |
if: ${{ needs.check_changes.outputs.added-files == 'true' }} | |
run: | | |
# CODEOWNERS patterns follows nearly the same syntax as a .gitignore. | |
# To check if all files are covered by patterns other than the | |
# catch-all '*', we turn the file into a .gitignore and list | |
# unmatched files. | |
cd src/${REPOSITY_NAME} | |
# Copy all patterns from CODEOWNERS, but skipping the comments | |
# ('^[^#]') and the catch-all '*' rule (the only one with a single | |
# character, we skip it with '^.[^ ]'). | |
awk '/^[^#][^ ]/ {print $1}' CODEOWNERS > .gitignore | |
# Reinitialize the repo and list all files NOT covered by .gitignore. | |
rm -rf .git | |
git init -q | |
if [[ -n "$(git ls-files --others -X .gitignore)" ]]; then | |
echo '::error title=missing_code_owners::Following files have no owners in CODEOWNERS:' | |
git ls-files --others -X .gitignore | |
exit 1 | |
fi | |
# when some file deleted in the PR , check whether some path recorded in the CODEOWNERS does not exist , | |
# if so, should update CODEOWNERS | |
- name: Check if CODEOWNERS has stale entries | |
if: ${{ needs.check_changes.outputs.deleted-files == 'true' }} | |
run: | | |
cd src/${REPOSITY_NAME} | |
EXIT_STATUS=0 | |
# We go through the patterns in CODEOWNERS, and for each of them we | |
# search for corresponding files in the repo. | |
# loop all path recorded in the CODEOWNER | |
while read l; do | |
case "${l}" in | |
/*) | |
# The pattern should match from the root of the repo, | |
# we'll use 'ls'. For now, just append pattern to $LIST. | |
LIST+=" ${l#/}" | |
;; | |
*) | |
# No leading slash: may not be at the root of the repo, | |
# search with 'find'. Print pattern if no file found. | |
if [[ -z $(find . -path "*${l}*" -print -quit) ]]; then | |
echo "${l}" | |
EXIT_STATUS=1 | |
fi | |
;; | |
esac | |
done <<< $(awk '/^[^#][^ ]/ {print $1}' CODEOWNERS) | |
# Just one final call to 'ls' with all /* patterns found. Catch | |
# patterns with no corresponding files/directories from stderr. | |
STALE_PATTERNS="$(ls -- ${LIST} 2>&1 >/dev/null | sed "s|.*'\(.*\)':.*|/\1|")" | |
if [[ -n "${STALE_PATTERNS}" ]]; then | |
echo "${STALE_PATTERNS}" | sed 's/ /\n/g' | |
EXIT_STATUS=1 | |
fi | |
if [[ ${EXIT_STATUS} -ne 0 ]]; then | |
echo '::error title=stale_patterns::The patterns above should be removed from CODEOWNERS.' | |
exit ${EXIT_STATUS} | |
fi |