Skip to content

Commit

Permalink
chore: conditional workflows (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
ddaoxuan authored Oct 31, 2024
1 parent 727dec8 commit 93fd01a
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 53 deletions.
57 changes: 43 additions & 14 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,55 @@ name: Check
on:
push:
branches: ["main", "master", "develop", "preprod"]
paths:
- "starters/**"
pull_request:
types: [opened, synchronize]
paths:
- "starters/**"

jobs:
check-changes:
runs-on: ubuntu-latest
outputs:
meilisearch: ${{ steps.filter.outputs.meilisearch }}
algolia: ${{ steps.filter.outputs.algolia }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v2
id: filter
with:
filters: |
shopify-meilisearch:
- 'starters/shopify-meilisearch/**'
shopify-algolia:
- 'starters/shopify-algolia/**'
build:
needs: check-changes
strategy:
matrix:
app: [shopify-meilisearch, shopify-algolia]
include:
- app: shopify-meilisearch
working-directory: ./starters/shopify-meilisearch
- app: shopify-algolia
working-directory: ./starters/shopify-algolia
app:
[
{
name: shopify-meilisearch,
working-directory: ./starters/shopify-meilisearch,
should-run: needs.check-changes.outputs.shopify-meilisearch,
},
{
name: shopify-algolia,
working-directory: ./starters/shopify-algolia,
should-run: needs.check-changes.outputs.shopify-algolia,
},
]
if: ${{ fromJson(matrix.app.should-run) }}

environment: Production
name: Build and Test (${{ matrix.app }})
name: Build and Test (${{ matrix.app.name }})
timeout-minutes: 15
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-${{ matrix.app }}-${{ github.ref }}
group: ${{ github.workflow }}-${{ matrix.app.name }}-${{ github.ref }}
cancel-in-progress: true

env:
Expand All @@ -47,27 +76,27 @@ jobs:
- uses: actions/cache@v2
with:
path: "**/node_modules"
key: ${{ runner.os }}-${{ matrix.app }}-modules-${{ hashFiles('**/yarn.lock') }}
key: ${{ runner.os }}-${{ matrix.app.name }}-modules-${{ hashFiles('**/yarn.lock') }}

- name: Install dependencies
run: yarn install --frozen-lockfile --prefer-offline
working-directory: ${{ matrix.working-directory }}
working-directory: ${{ matrix.app.working-directory }}

- name: Licenses check
run: npx --yes license-checker-rseidelsohn --production --excludePrivatePackages --onlyAllow "MPL-2.0;UNKNOWN;MIT;Apache;AAL;BSD;Artistic;CC0;ISC;ISCL;PostgreSQL License;Public Domain;Unlicense;UPL;W3C;WTFPL;Python;CC-;BlueOak"

- name: Test
run: yarn test
working-directory: ${{ matrix.working-directory }}
working-directory: ${{ matrix.app.working-directory }}

- name: Lint
run: yarn lint
working-directory: ${{ matrix.working-directory }}
working-directory: ${{ matrix.app.working-directory }}

- name: Format
run: yarn format
working-directory: ${{ matrix.working-directory }}
working-directory: ${{ matrix.app.working-directory }}

- name: Build
run: yarn build
working-directory: ${{ matrix.working-directory }}
working-directory: ${{ matrix.app.working-directory }}
75 changes: 52 additions & 23 deletions .github/workflows/nextjs_bundle_analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,57 @@ on:
branches:
- main
- develop
paths:
- "starters/**"
pull_request:
branches:
- main
- develop
paths:
- "starters/**"
workflow_dispatch:

jobs:
check-changes:
runs-on: ubuntu-latest
outputs:
meilisearch: ${{ steps.filter.outputs.meilisearch }}
algolia: ${{ steps.filter.outputs.algolia }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v2
id: filter
with:
filters: |
shopify-meilisearch:
- 'starters/shopify-meilisearch/**'
shopify-algolia:
- 'starters/shopify-algolia/**'
analyze:
needs: check-changes
strategy:
matrix:
app: [shopify-meilisearch, shopify-algolia]
include:
- app: shopify-meilisearch
working-directory: ./starters/shopify-meilisearch
- app: shopify-algolia
working-directory: ./starters/shopify-algolia
app:
[
{
name: shopify-meilisearch,
working-directory: ./starters/shopify-meilisearch,
should-run: needs.check-changes.outputs.shopify-meilisearch,
},
{
name: shopify-algolia,
working-directory: ./starters/shopify-algolia,
should-run: needs.check-changes.outputs.shopify-algolia,
},
]
if: ${{ fromJson(matrix.app.should-run) }}

environment: Production
name: Analyze (${{ matrix.app }})
name: Analyze (${{ matrix.app.name }})
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-${{ matrix.app }}-${{ github.ref }}
group: ${{ github.workflow }}-${{ matrix.app.name }}-${{ github.ref }}
cancel-in-progress: true

env:
Expand All @@ -52,48 +81,48 @@ jobs:
- uses: actions/cache@v2
with:
path: "**/node_modules"
key: ${{ runner.os }}-${{ matrix.app }}-bundle-modules-${{ hashFiles('**/yarn.lock') }}
key: ${{ runner.os }}-${{ matrix.app.name }}-bundle-modules-${{ hashFiles('**/yarn.lock') }}

- name: Install dependencies
run: yarn install --frozen-lockfile --prefer-offline
working-directory: ${{ matrix.working-directory }}
working-directory: ${{ matrix.app.working-directory }}

- name: Restore next build
uses: actions/cache@v3
id: restore-build-cache
env:
cache-name: cache-next-build-${{ matrix.app }}
cache-name: cache-next-build-${{ matrix.app.name }}
with:
path: ${{ matrix.working-directory }}/.next/cache
path: ${{ matrix.app.working-directory }}/.next/cache
key: ${{ runner.os }}-build-${{ env.cache-name }}

- name: Build next.js app
env:
SKIP_BUILD_PRODUCT_REDIRECTS: 1
run: cd ${{ matrix.working-directory }} && yarn build && cd -
run: cd ${{ matrix.app.working-directory }} && yarn build && cd -

- name: Analyze bundle
working-directory: ${{ matrix.working-directory }}
working-directory: ${{ matrix.app.working-directory }}
run: node report-bundle-size.js

- name: Upload bundle
uses: actions/upload-artifact@v3
with:
name: bundle-${{ matrix.app }}
path: ${{ matrix.working-directory }}/.next/analyze/__bundle_analysis.json
name: bundle-${{ matrix.app.name }}
path: ${{ matrix.app.working-directory }}/.next/analyze/__bundle_analysis.json

- name: Download base branch bundle stats
uses: dawidd6/action-download-artifact@v2
if: success() && github.event.number
with:
workflow: nextjs_bundle_analysis.yml
branch: ${{ github.event.pull_request.base.ref }}
name: bundle-${{ matrix.app }}
path: ${{ matrix.working-directory }}/.next/analyze/base/bundle
name: bundle-${{ matrix.app.name }}
path: ${{ matrix.app.working-directory }}/.next/analyze/base/bundle

- name: Compare with base branch bundle
if: success() && github.event.number
working-directory: ${{ matrix.working-directory }}
working-directory: ${{ matrix.app.working-directory }}
run: |
if [ -f .next/analyze/base/bundle/__bundle_analysis.json ]; then
npx -p nextjs-bundle-analysis compare
Expand All @@ -105,7 +134,7 @@ jobs:
- name: Get comment body
id: get-comment-body
if: success() && github.event.number
working-directory: ${{ matrix.working-directory }}
working-directory: ${{ matrix.app.working-directory }}
run: |
body=$(cat .next/analyze/__bundle_analysis_comment.txt)
body="${body//'%'/'%25'}"
Expand All @@ -120,16 +149,16 @@ jobs:
with:
issue-number: ${{ github.event.number }}
comment-author: "github-actions[bot]"
body-includes: "<!-- NEXTJS_BUNDLE_${{ matrix.app }} -->"
body-includes: "<!-- NEXTJS_BUNDLE_${{ matrix.app.name }} -->"

- name: Create or update comment
uses: peter-evans/create-or-update-comment@v3
if: success() && github.event.number
with:
issue-number: ${{ github.event.number }}
body: |
<!-- NEXTJS_BUNDLE_${{ matrix.app }} -->
# Next.js Bundle Analysis (${{ matrix.app }})
<!-- NEXTJS_BUNDLE_${{ matrix.app.name }} -->
# Next.js Bundle Analysis (${{ matrix.app.name }})
${{ steps.get-comment-body.outputs.body }}
comment-id: ${{ steps.fc.outputs.comment-id }}
edit-mode: replace
61 changes: 45 additions & 16 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,51 @@ on:
- main
- master
- develop
pull_request: null
workflow_dispatch: null
paths:
- "starters/**"
pull_request:
paths:
- "starters/**"
workflow_dispatch:

jobs:
check-changes:
runs-on: ubuntu-latest
outputs:
meilisearch: ${{ steps.filter.outputs.meilisearch }}
algolia: ${{ steps.filter.outputs.algolia }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v2
id: filter
with:
filters: |
shopify-meilisearch:
- 'starters/shopify-meilisearch/**'
shopify-algolia:
- 'starters/shopify-algolia/**'
test:
needs: check-changes
strategy:
matrix:
app: [shopify-meilisearch, shopify-algolia]
include:
- app: shopify-meilisearch
working-directory: ./starters/shopify-meilisearch
- app: shopify-algolia
working-directory: ./starters/shopify-algolia
app:
[
{
name: shopify-meilisearch,
working-directory: ./starters/shopify-meilisearch,
should-run: needs.check-changes.outputs.shopify-meilisearch,
},
{
name: shopify-algolia,
working-directory: ./starters/shopify-algolia,
should-run: needs.check-changes.outputs.shopify-algolia,
},
]
if: ${{ fromJson(matrix.app.should-run) }}

environment: test
name: E2E Tests (${{ matrix.app }})
name: E2E Tests (${{ matrix.app.name }})
env:
NODE_ENV: test
SKIP_ENV_VALIDATION: true
Expand All @@ -37,7 +66,7 @@ jobs:
timeout-minutes: 60
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-${{ matrix.app }}-${{ github.ref }}
group: ${{ github.workflow }}-${{ matrix.app.name }}-${{ github.ref }}
cancel-in-progress: true

steps:
Expand All @@ -51,23 +80,23 @@ jobs:
- uses: actions/cache@v2
with:
path: "**/node_modules"
key: ${{ runner.os }}-${{ matrix.app }}-playwright-modules-${{ hashFiles('**/yarn.lock') }}
key: ${{ runner.os }}-${{ matrix.app.name }}-playwright-modules-${{ hashFiles('**/yarn.lock') }}

- name: Install dependencies
run: yarn install --frozen-lockfile --prefer-offline
working-directory: ${{ matrix.working-directory }}
working-directory: ${{ matrix.app.working-directory }}

- name: Install Playwright Browsers
run: yarn playwright install --with-deps
working-directory: ${{ matrix.working-directory }}
working-directory: ${{ matrix.app.working-directory }}

- name: Run Playwright tests
run: yarn e2e
working-directory: ${{ matrix.working-directory }}
working-directory: ${{ matrix.app.working-directory }}

- uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report-${{ matrix.app }}
path: ${{ matrix.working-directory }}/playwright-report/
name: playwright-report-${{ matrix.app.name }}
path: ${{ matrix.app.working-directory }}/playwright-report/
retention-days: 30

0 comments on commit 93fd01a

Please sign in to comment.