Skip to content

Commit

Permalink
feat(ci): integrate dorny/paths-filter for PR test control
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaP700 committed Jan 29, 2025
1 parent 735aefc commit b7232dd
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 25 deletions.
64 changes: 39 additions & 25 deletions .github/workflows/pr-testing-with-test-project.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,33 @@
#This workflow runs the tests in the test projects to make sure the generator works as a library where it is a Node dependency along with the template.
name: Test using test project

on:
pull_request:
types: [opened, reopened, synchronize, ready_for_review]
paths:
- 'package.json'
- 'package-lock.json'
- 'apps/**'
- 'packages/**'
- '.github/workflows/**'
- '!**/*.md'
- '!docs/**'

jobs:
should-test:
changes:
runs-on: ubuntu-latest
outputs:
run_tests: ${{ steps.check.outputs.run_tests }}
should_test: ${{ steps.filter.outputs.changes }}
steps:
- name: Check if tests should run
id: check
run: |
# Skip for bot PRs with specific titles
if [[ "${{ github.actor }}" == "asyncapi-bot" && "${{ github.event.pull_request.title }}" =~ ^(ci:\ update|chore\(release\):) ]] || \
[[ "${{ github.actor }}" == "allcontributors[bot]" && "${{ github.event.pull_request.title }}" =~ ^docs: ]]; then
echo "run_tests=false" >> $GITHUB_OUTPUT
else
echo "run_tests=true" >> $GITHUB_OUTPUT
fi
- uses: actions/checkout@v3
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
changes:
- 'package.json'
- 'package-lock.json'
- 'apps/**'
- 'packages/**'
- '.github/workflows/**'
- '!**/*.md'
- '!docs/**'
test:
needs: should-test
if: needs.should-test.outputs.run_tests == 'true' && github.event.pull_request.draft == false
needs: changes
if: ${{ needs.changes.outputs.should_test == 'true' && github.event.pull_request.draft == false }}
name: Test generator as dependency with Node ${{ matrix.node }}
runs-on: ubuntu-latest
strategy:
Expand All @@ -40,7 +36,25 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Run test
- name: Determine if tests should run
id: should_run
if: >
!github.event.pull_request.draft && !(
(github.actor == 'asyncapi-bot' && (
startsWith(github.event.pull_request.title, 'ci: update of files from global .github repo') ||
startsWith(github.event.pull_request.title, 'chore(release):')
)) ||
(github.actor == 'asyncapi-bot-eve' && (
startsWith(github.event.pull_request.title, 'ci: update of files from global .github repo') ||
startsWith(github.event.pull_request.title, 'chore(release):')
)) ||
(github.actor == 'allcontributors[bot]' &&
startsWith(github.event.pull_request.title, 'docs: add')
)
)
run: echo "shouldrun=true" >> $GITHUB_OUTPUT
shell: bash
- if: steps.should_run.outputs.shouldrun == 'true'
name: Run test
run: NODE_IMAGE_TAG=${{ matrix.node }} docker compose up --abort-on-container-exit --remove-orphans --force-recreate
working-directory: ./apps/generator/test/test-project
working-directory: ./apps/generator/test/test-project
43 changes: 43 additions & 0 deletions playground-1.mongodb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* global use, db */
// MongoDB Playground
// To disable this template go to Settings | MongoDB | Use Default Template For Playground.
// Make sure you are connected to enable completions and to be able to run a playground.
// Use Ctrl+Space inside a snippet or a string literal to trigger completions.
// The result of the last command run in a playground is shown on the results panel.
// By default the first 20 documents will be returned with a cursor.
// Use 'console.log()' to print to the debug output.
// For more documentation on playgrounds please refer to
// https://www.mongodb.com/docs/mongodb-vscode/playgrounds/

// Select the database to use.
use('mongodbVSCodePlaygroundDB');

// Insert a few documents into the sales collection.
db.getCollection('sales').insertMany([
{ 'item': 'abc', 'price': 10, 'quantity': 2, 'date': new Date('2014-03-01T08:00:00Z') },
{ 'item': 'jkl', 'price': 20, 'quantity': 1, 'date': new Date('2014-03-01T09:00:00Z') },
{ 'item': 'xyz', 'price': 5, 'quantity': 10, 'date': new Date('2014-03-15T09:00:00Z') },
{ 'item': 'xyz', 'price': 5, 'quantity': 20, 'date': new Date('2014-04-04T11:21:39.736Z') },
{ 'item': 'abc', 'price': 10, 'quantity': 10, 'date': new Date('2014-04-04T21:23:13.331Z') },
{ 'item': 'def', 'price': 7.5, 'quantity': 5, 'date': new Date('2015-06-04T05:08:13Z') },
{ 'item': 'def', 'price': 7.5, 'quantity': 10, 'date': new Date('2015-09-10T08:43:00Z') },
{ 'item': 'abc', 'price': 10, 'quantity': 5, 'date': new Date('2016-02-06T20:20:13Z') },
]);

// Run a find command to view items sold on April 4th, 2014.
const salesOnApril4th = db.getCollection('sales').find({
date: { $gte: new Date('2014-04-04'), $lt: new Date('2014-04-05') }
}).count();

// Print a message to the output window.
console.log(`${salesOnApril4th} sales occurred in 2014.`);

// Here we run an aggregation and open a cursor to the results.
// Use '.toArray()' to exhaust the cursor to return the whole result set.
// You can use '.hasNext()/.next()' to iterate through the cursor page by page.
db.getCollection('sales').aggregate([
// Find all of the sales that occurred in 2014.
{ $match: { date: { $gte: new Date('2014-01-01'), $lt: new Date('2015-01-01') } } },
// Group the total sales for each product.
{ $group: { _id: '$item', totalSaleAmount: { $sum: { $multiply: [ '$price', '$quantity' ] } } } }
]);

0 comments on commit b7232dd

Please sign in to comment.