Skip to content

Commit

Permalink
chore(func): Filter test runs based on file changes
Browse files Browse the repository at this point in the history
  • Loading branch information
avattipalli committed Nov 5, 2024
1 parent f15fcae commit 637d7fe
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 8 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/pull-request-data.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,33 @@
module.exports = async ({ github, context, core }) => {
const exemptPaths = [
'integrations/',
'packages/create-catalyst/',
'packages/eslint-config-catalyst/'
];

const result = await github.rest.repos.listPullRequestsAssociatedWithCommit({
owner: context.repo.owner,
repo: context.repo.repo,
commit_sha: context.sha,
});

const { data: files } = await github.pulls.listFiles({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: result?.data[0]?.number,
});

const changedFiles = files.map(f => f.filename);
const nonExemptFiles = changedFiles.filter(f => {
return !exemptPaths.some(path => f.startsWith(path));
});
if (nonExemptFiles.length === 0) {
runJob = false;
}

core.setOutput('pr', result?.data[0]?.number || '');
core.setOutput('title', result?.data[0]?.title || '');
core.setOutput('url', result?.data[0]?.html_url || '');
core.setOutput('draft', `${result?.data[0]?.draft}` || 'true');
core.setOutput('run_job', runJob.toString());
}
26 changes: 18 additions & 8 deletions .github/workflows/regression-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,32 @@ env:
BIGCOMMERCE_STORE_HASH: ${{ secrets.BIGCOMMERCE_STORE_HASH }}

jobs:
generate-lighthouse-audit:
name: Lighthouse Audit
timeout-minutes: 30
changes:
runs-on: ubuntu-latest
if: ${{ contains(fromJson('["Production – catalyst-latest", "Preview – catalyst-latest"]'), github.event.deployment_status.environment) }}

outputs:
run_job: ${{ steps.check_changes.outputs.run_job }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Pull Request Details
id: pr_details
uses: actions/github-script@v7
with:
script: |
const prData = require('./.github/workflows/pull-request-data.js');
await prData({ github, context, core });
generate-lighthouse-audit:
needs: changes
name: Lighthouse Audit
timeout-minutes: 30
runs-on: ubuntu-latest
if: ${{ needs.check_changes.outputs.run_job == 'true' && contains(fromJson('["Production – catalyst-latest", "Preview – catalyst-latest"]'), github.event.deployment_status.environment) }}

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Lighthouse house audit on desktop
id: lighthouse_audit_desktop
uses: treosh/lighthouse-ci-action@v11
Expand Down Expand Up @@ -104,10 +112,11 @@ jobs:
${{ steps.format_lighthouse_score_mobile.outputs.comment }}
ui-tests:
needs: changes
name: Playwright UI Tests
timeout-minutes: 30
runs-on: ubuntu-latest
if: ${{ contains(fromJson('["Production – catalyst-latest", "Preview – catalyst-latest"]'), github.event.deployment_status.environment) }}
if: ${{ needs.check_changes.outputs.run_job == 'true' && contains(fromJson('["Production – catalyst-latest", "Preview – catalyst-latest"]'), github.event.deployment_status.environment) }}

steps:
- name: Checkout code
Expand Down Expand Up @@ -166,10 +175,11 @@ jobs:
}
visual-regression-tests:
needs: changes
name: Playwright Visual Regression Tests
timeout-minutes: 30
runs-on: macos-14
if: ${{ contains(fromJson('["Production – catalyst-latest", "Preview – catalyst-latest"]'), github.event.deployment_status.environment) }}
if: ${{ needs.check_changes.outputs.run_job == 'true' && contains(fromJson('["Production – catalyst-latest", "Preview – catalyst-latest"]'), github.event.deployment_status.environment) }}

steps:
- name: Checkout code
Expand Down

0 comments on commit 637d7fe

Please sign in to comment.