generated from DARMA-tasking/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
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
tlamonthezie
wants to merge
21
commits into
master
Choose a base branch
from
1-validate-required-workflows-usage-across-repositories
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+199
−1
Draft
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 49253d3
#1: update script to ckeck repositories have defined the required checks
tlamonthezie 994ea16
#1: introduce ci problem matcher for shell output
tlamonthezie f5569a8
#1: update ci script
tlamonthezie fc790b1
#1: implementing dynamic ci matrix strategy
tlamonthezie 13a8565
#1: resolve exclusion of some repositories from checks
tlamonthezie 64c76b3
#1: add comments in shell scripts
tlamonthezie db017eb
#1: disable fail-fast for the repositories matrix in ci
tlamonthezie 3e43c5f
#1: check contents of workflows and cancel existing jobs
cwschilly 8cb99f1
#1: fix grep syntax
cwschilly e85bf50
#1: add missing definition
cwschilly a55151e
#1: try different logic for finding workflows
cwschilly 9f7e788
#1: improve grep for workflows and only print relative path
cwschilly 9e93329
#1: clean up
cwschilly 07323a6
#1: ignore forked repos
cwschilly f4f8815
#1: ignore repos with no workflows
cwschilly 39dabba
#1: run repository workflow check on the first day of the month
cwschilly 6b589f1
#1: remove comment
cwschilly a71e1d2
#1: clarify cron comment
cwschilly fbecf8c
#1: create issue if repo is missing workflows
cwschilly 08e349e
#1: update name of github token
cwschilly File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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 }} |
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
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(.+)$" | ||
} | ||
] | ||
} | ||
] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
__pycache__ | ||
__pycache__ | ||
ci/repositories.json |
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
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 |
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
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", | ||
"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)' |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
, andfind-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.