|
| 1 | +name: Run Unit Tests |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, synchronize, reopened] |
| 6 | + |
| 7 | +jobs: |
| 8 | + run-tests: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + steps: |
| 11 | + - name: Checkout code |
| 12 | + uses: actions/checkout@v4 |
| 13 | + |
| 14 | + - name: Set up Node.js |
| 15 | + uses: actions/setup-node@v4 |
| 16 | + with: |
| 17 | + node-version: '22.x' |
| 18 | + |
| 19 | + - name: Install dependencies for all plugins |
| 20 | + run: | |
| 21 | + npm run setup-repo-old |
| 22 | +
|
| 23 | + - name: Run tests for Audit plugin |
| 24 | + working-directory: ./packages/contentstack-audit |
| 25 | + run: npm run test:unit |
| 26 | + |
| 27 | + - name: Run tests for Contentstack Config |
| 28 | + working-directory: ./packages/contentstack-config |
| 29 | + run: npm run test |
| 30 | + # - name: Fetch latest references |
| 31 | + # run: | |
| 32 | + # git fetch --prune |
| 33 | + |
| 34 | + # - name: Identify Changed Plugins |
| 35 | + # id: changes |
| 36 | + # run: | |
| 37 | + # echo "Finding changed files..." |
| 38 | + # # Ensure both commit references are valid |
| 39 | + # if [[ -z "${{ github.event.before }}" || -z "${{ github.sha }}" ]]; then |
| 40 | + # echo "Error: Missing commit references" |
| 41 | + # exit 1 |
| 42 | + # fi |
| 43 | + |
| 44 | + # CHANGED_FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }}) |
| 45 | + # echo "Changed files:" |
| 46 | + # echo "$CHANGED_FILES" |
| 47 | + |
| 48 | + # # Identify affected plugins |
| 49 | + # AFFECTED_PLUGINS=$(echo "$CHANGED_FILES" | grep -oP '(?<=^packages/)([^/]+)' | sort -u | tr '\n' ' ') |
| 50 | + # echo "Affected plugins: $AFFECTED_PLUGINS" |
| 51 | + |
| 52 | + # # Set output for the next step |
| 53 | + # echo "::set-output name=affected_plugins::$AFFECTED_PLUGINS" |
| 54 | + |
| 55 | + # - name: Run Unit Tests for Affected Plugins |
| 56 | + # run: | |
| 57 | + # for plugin in ${{ steps.changes.outputs.affected_plugins }}; do |
| 58 | + # echo "Checking if tests should run for $plugin..." |
| 59 | + # if [[ "$plugin" == "contentstack-audit" ]]; then |
| 60 | + # echo "Running tests for contentstack-audit..." |
| 61 | + # npm run test:unit --prefix ./packages/contentstack-audit |
| 62 | + # else |
| 63 | + # echo "contentstack-audit has not changed. Skipping tests." |
| 64 | + # fi |
| 65 | + # done |
0 commit comments