Skip to content

Commit

Permalink
#1: create issue if repo is missing workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
cwschilly committed Jan 9, 2025
1 parent a71e1d2 commit fbecf8c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build-docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
push:
branches:
- master
pull_request:
branches: "*"

jobs:
get-matrix:
Expand Down
9 changes: 6 additions & 3 deletions .github/workflows/check-repositories.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ name: DARMA repositories check

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

concurrency:
group: ${{ github.event.repository.name }}-${{ github.ref }}-${{ github.workflow }}
Expand Down Expand Up @@ -31,7 +34,7 @@ jobs:
runs-on: ubuntu-latest
needs: list_repositories
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_TOKEN: ${{ secrets.github_pat2}}
strategy:
fail-fast: false
matrix:
Expand Down
25 changes: 19 additions & 6 deletions ci/check_repository.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,14 @@ for file in "$WORKFLOWS_DIR"/*.yml; do
fi
done

# Ensure all workflows were found
# 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
Expand All @@ -73,16 +75,27 @@ fi
# Finalize
TSEND=$(date +%s)
TSDURATION=$(( $TSEND - $TSSTART ))
if [[ $N_ERRORS -gt 0 ]]
then
echo "$WORKING_DIR/$REPOSITORY has $N_ERRORS errors."
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
if [[ $N_ERRORS -gt 0 ]]; then
exit 1
fi

0 comments on commit fbecf8c

Please sign in to comment.