Skip to content

ci(*): more efficient testing #4

ci(*): more efficient testing

ci(*): more efficient testing #4

name: Conditional Testing
on:
pull_request:
branches: ["**"]
jobs:
check_changes:
runs-on: ubuntu-latest
outputs:
changed_extensions: ${{ steps.set_changed.outputs.changed_extensions }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Get changed directories
id: set_changed
run: |
echo "::group::Determining Changed Directories"
DIRECTORIES="Firebase auth-mailchimp-sync delete-user-data firestore-bigquery-export firestore-counter firestore-send-email firestore-shorten-urls-bitly firestore-translate-text rtdb-limit-child-nodes storage-resize-images"
# Set commit SHAs for comparison
BASE_SHA=${{ github.event.pull_request.base.sha }}
HEAD_SHA=${{ github.event.pull_request.head.sha }}
# Initialize an empty string for changed directories
CHANGED_EXTENSIONS=""
# Check for changes, and handle possible failure on base/head resolution
if ! git diff --name-only $BASE_SHA $HEAD_SHA > /dev/null 2>&1; then
echo "Error detecting changes using PR base and head SHAs, falling back to default branch comparison."
BASE_SHA=$(git rev-parse origin/main) # Ensure 'main' is your default branch
fi
# Collect directories that have changed
for dir in $DIRECTORIES; do
if git diff --name-only $BASE_SHA $HEAD_SHA | grep -q "^$dir/"; then
CHANGED_EXTENSIONS+="$dir "
fi
done
# Trim trailing spaces and write to output file
CHANGED_EXTENSIONS=$(echo $CHANGED_EXTENSIONS | xargs)
echo "changed_extensions=$CHANGED_EXTENSIONS" >> $GITHUB_OUTPUT
echo "Changed extensions: $CHANGED_EXTENSIONS"
echo "::endgroup::"
test_extensions:
needs: check_changes
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
extension:
${{ fromJson(needs.check_changes.outputs.changed_extensions) }}
defaults:
run:
working-directory: ${{ matrix.extension }}/functions
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: "18"
cache: "npm"
cache-dependency-path: "**/package-lock.json"
- run: npm install
- run: npm run build
- run: npm test