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

#1: validate required workflows usage across repositories #6

Draft
wants to merge 21 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
41e2354
#1: add script to list repositories and initial workflow for reposito…
tlamonthezie Sep 17, 2024
49253d3
#1: update script to ckeck repositories have defined the required checks
tlamonthezie Sep 18, 2024
994ea16
#1: introduce ci problem matcher for shell output
tlamonthezie Sep 18, 2024
f5569a8
#1: update ci script
tlamonthezie Sep 18, 2024
fc790b1
#1: implementing dynamic ci matrix strategy
tlamonthezie Sep 18, 2024
13a8565
#1: resolve exclusion of some repositories from checks
tlamonthezie Sep 18, 2024
64c76b3
#1: add comments in shell scripts
tlamonthezie Sep 18, 2024
db017eb
#1: disable fail-fast for the repositories matrix in ci
tlamonthezie Sep 18, 2024
3e43c5f
#1: check contents of workflows and cancel existing jobs
cwschilly Jan 6, 2025
8cb99f1
#1: fix grep syntax
cwschilly Jan 6, 2025
e85bf50
#1: add missing definition
cwschilly Jan 6, 2025
a55151e
#1: try different logic for finding workflows
cwschilly Jan 6, 2025
9f7e788
#1: improve grep for workflows and only print relative path
cwschilly Jan 6, 2025
9e93329
#1: clean up
cwschilly Jan 6, 2025
07323a6
#1: ignore forked repos
cwschilly Jan 6, 2025
f4f8815
#1: ignore repos with no workflows
cwschilly Jan 6, 2025
39dabba
#1: run repository workflow check on the first day of the month
cwschilly Jan 6, 2025
6b589f1
#1: remove comment
cwschilly Jan 6, 2025
a71e1d2
#1: clarify cron comment
cwschilly Jan 7, 2025
fbecf8c
#1: create issue if repo is missing workflows
cwschilly Jan 7, 2025
08e349e
#1: update name of github token
cwschilly Jan 10, 2025
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
46 changes: 46 additions & 0 deletions .github/workflows/check-repositories.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: DARMA repositories check

# Runs at 00:00 UTC on day 1 of every month
on:
# schedule:
# - cron: '0 0 1 * *'
push:
branches:
- 1-validate-required-workflows-usage-across-repositories

concurrency:
group: ${{ github.event.repository.name }}-${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: True

jobs:
list_repositories:
name: List repositories
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4

- name: List repositories
id: list-repositories
run: |
REPOSITORIES=$(bash ci/list_repositories.sh)
echo "repositories=$(echo $REPOSITORIES)" >> $GITHUB_OUTPUT
outputs:
repositories: ${{ steps.list-repositories.outputs.repositories }}

check_repository:
name: Check repository (${{ matrix.repository.name }})
runs-on: ubuntu-latest
needs: list_repositories
env:
GH_TOKEN: ${{ secrets.ISSUE_CREATION_1}}
strategy:
fail-fast: false
matrix:
repository: ${{ fromJson(needs.list_repositories.outputs.repositories ) }}
steps:
- uses: actions/checkout@v4
- name: Check repositories
run: |
bash ./ci/check_repository.sh ${{ matrix.repository.name }}
31 changes: 31 additions & 0 deletions .github/workflows/matchers/shell.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"problemMatcher": [
{
"owner": "shell-error",
"severity": "error",
"pattern": [
{
"regexp": "^[error]:\\s(.+)$"
}
]
},
{
"owner": "shell-warning",
"severity": "warning",
"pattern": [
{
"regexp": "^[warning]:\\s(.+)$"
}
]
},
{
"owner": "shell-notice",
"severity": "notice",
"pattern": [
{
"regexp": "^[notice]:\\s(.+)$"
}
]
}
]
}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
__pycache__
__pycache__
ci/repositories.json
101 changes: 101 additions & 0 deletions ci/check_repository.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/bin/bash

# Check that a repository is compliant:
# - all expected workflows are present

CURRENT_DIR="$(dirname -- "$(realpath -- "$0")")" # Current directory
PARENT_DIR="$(dirname "$CURRENT_DIR")"
WORKING_DIR="$PARENT_DIR/output"
ORG=DARMA-tasking
REPOSITORY=$1
EXPECTED_WORKFLOWS=( \
find-unsigned-commits \
check-commit-format \
find-trailing-whitespace \
check-pr-fixes-issue \
action-git-diff-check \
)

# Clean
rm -rf $WORKING_DIR
mkdir -p $WORKING_DIR

# Initialize
N_ERRORS=0
TSSTART=$(date +%s)
echo "$ORG/$REPOSITORY > Cloning repository...";
git clone https://github.com/$ORG/$REPOSITORY $WORKING_DIR/$REPOSITORY >/dev/null 2>&1

# Directory containing workflow files
WORKFLOWS_DIR="$WORKING_DIR/$REPOSITORY/.github/workflows"
FOUND_WORKFLOWS=()

# Check workflows
if [ ! -d "$WORKFLOWS_DIR" ]; then
echo "[error] Workflow directory '$WORKFLOWS_DIR' does not exist."
exit 1
fi

for file in "$WORKFLOWS_DIR"/*.yml; do
if [ ! -f "$file" ]; then
continue
fi

# Check each file for the current workflow
for w in "${EXPECTED_WORKFLOWS[@]}"; do
if grep -qE "uses: .*/$w" "$file"; then
if [[ ! " ${FOUND_WORKFLOWS[@]} " =~ " $w " ]]; then
FOUND_WORKFLOWS+=("$w")
echo "[ok] Found workflow '$w' in file '${file#$WORKING_DIR/}'"
fi
fi
done

# Exit if all workflows are found
if [ ${#FOUND_WORKFLOWS[@]} -eq ${#EXPECTED_WORKFLOWS[@]} ]; then
break
fi
done

# Find any missing workflows
MISSING_WORKFLOWS=()
if [ ${#FOUND_WORKFLOWS[@]} -ne ${#EXPECTED_WORKFLOWS[@]} ]; then
echo "[error] Missing workflows:"
for w in "${EXPECTED_WORKFLOWS[@]}"; do
if [[ ! " ${FOUND_WORKFLOWS[@]} " =~ " $w " ]]; then
echo " - $w"
MISSING_WORKFLOWS+=("$w")
((N_ERRORS++))
fi
done
else
echo "[ok] All expected workflows are present."
fi

# Finalize
TSEND=$(date +%s)
TSDURATION=$(( $TSEND - $TSSTART ))
if [[ $N_ERRORS -gt 0 ]]; then
echo "Creating an issue in $REPOSITORY to add missing workflows..."

if [ ${#MISSING_WORKFLOWS[@]} -gt 0 ]; then
ISSUE_TITLE="[workflows] Missing Actions"
ISSUE_BODY="The following actions are missing from the repository:"
for w in "${MISSING_WORKFLOWS[@]}"; do
ISSUE_BODY+=$'\n- '"$w"
done

gh issue create \
--repo "$ORG/$REPOSITORY" \
--title "$ISSUE_TITLE" \
--body "$ISSUE_BODY"
fi
else
echo "[success] repository checks OK."
fi
echo "$WORKING_DIR/$REPOSITORY has been processed in $TSDURATION seconds."
echo "--------------------------------------------------";

if [[ $N_ERRORS -gt 0 ]]; then
exit 1
fi
19 changes: 19 additions & 0 deletions ci/list_repositories.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

# List the repositories in the DARMA-tasking organization - in JSON format -
# that need to be checked

ORG=DARMA-tasking
EXCLUDE='[
"DARMA-tasking.github.io",
"find-unsigned-commits",
"check-commit-format",
"find-trailing-whitespace",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is trailing WS finder excluded?

Copy link
Contributor

@cwschilly cwschilly Jan 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

find-unsigned-commits, check-commit-format, check-pr-fixes-issue, and find-trailing-whitespace are the actions that we're looking for in other DARMA-tasking repos. Since they don't run themselves (or any of the other actions), we can exclude them all from the check.

"check-pr-fixes-issue",
"vt-sample-project",
"parallel-for-transformer",
"detector",
"workflows"
]'
JQ="$EXCLUDE as \$blacklist | .[] | select(.isFork | not) | select(.name as \$in | \$blacklist | index(\$in) | not)"
gh repo list $ORG --json name,defaultBranchRef,isFork --jq "$JQ" | jq -s 'sort_by(.name)'
Loading