Skip to content

Commit

Permalink
#1: implementing dynamic ci matrix strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
tlamonthezie committed Sep 18, 2024
1 parent 51b3b0c commit b8baddc
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 76 deletions.
32 changes: 31 additions & 1 deletion .github/workflows/check-repositories.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,45 @@ on:
- 1-validate-required-workflows-usage-across-repositories

jobs:
list_repositories:
name: List repositories
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: List repositories
run:
- name: Set matrix
id: set-matrix
run: |
EXCLUDE='[
"DARMA-tasking.github.io",
"find-unsigned-commits",
"check-commit-format",
"find-trailing-whitespace",
"check-pr-fixes-issue"
]'
JQ=$EXCLUDE' as $blacklist | .[] | select( . as $in | $blacklist | index($in) | not)'
MATRIX=$(gh repo list DARMA-tasking --json name,defaultBranchRef --jq "$JQ" --jq 'sort_by(.name)' | jq)
echo "::set-output name=matrix::$(echo $MATRIX)"
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}

check_repositories:
name: Check repositories
runs-on: ubuntu-latest
needs: list_repositories
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
strategy:
matrix:
repository: ${{ fromJson(needs.list_repositories.outputs.matrix) }}
steps:
- uses: actions/checkout@v4

- name: Check repositories
run: bash ./ci/check_repositories.sh
run: |
bash ./ci/check_repository.sh
75 changes: 0 additions & 75 deletions ci/check_repositories.sh

This file was deleted.

46 changes: 46 additions & 0 deletions ci/check_repository.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash

CURRENT_DIR="$(dirname -- "$(realpath -- "$0")")" # Current directory
PARENT_DIR="$(dirname "$CURRENT_DIR")"
WORKING_DIR="$PARENT_DIR/output"
ORG=DARMA-tasking

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

CHECKS_REPOS=( \
find-unsigned-commits \
check-commit-format \
find-trailing-whitespace \
check-pr-fixes-issue \
)

N_ERRORS=0
TSSTART=$(date +%s)
echo "$ORG/$e > Cloning repository...";
git clone https://github.com/$ORG/$e $WORKING_DIR/$e >/dev/null 2>&1
for w in "${EXPECTED_WORKFLOWS[@]}"
do
if [ ! -f "$WORKING_DIR/$e/.github/workflows/$w.yml" ]; then
echo "[error] Missing workflow file '$w.yml' at $WORKING_DIR/$e/.github/workflows/$w.yml"
$((N_ERRORS++))
else
echo "[ok] workflow file '$w.yml' OK"
fi
done
TSEND=$(date +%s)
TSDURATION=$(( $TSEND - $TSSTART ))
if [[ $N_REPO_ERRORS -gt 0 ]]
then
echo "$WORKING_DIR/$e has $N_REPO_ERRORS errors."
else
echo "[success] repository checks OK."
fi
echo "$WORKING_DIR/$e has been processed in $TSDURATION seconds."
echo "--------------------------------------------------";

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

CURRENT_DIR="$(dirname -- "$(realpath -- "$0")")" # Current directory
PARENT_DIR="$(dirname "$CURRENT_DIR")"
WORKING_DIR="$PARENT_DIR/output"
ORG=DARMA-tasking

EXCLUDE='[
"DARMA-tasking.github.io",
"find-unsigned-commits",
"check-commit-format",
"find-trailing-whitespace",
"check-pr-fixes-issue"
]'
JQ=$EXCLUDE' as $blacklist | .[] | select( . as $in | $blacklist | index($in) | not)'
gh repo list DARMA-tasking --json name,defaultBranchRef --jq "$JQ" --jq 'sort_by(.name)' | jq

0 comments on commit b8baddc

Please sign in to comment.