Skip to content

Commit

Permalink
chore: fix workflows (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
ddaoxuan authored Oct 31, 2024
1 parent 93fd01a commit 43e96f5
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 181 deletions.
75 changes: 29 additions & 46 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
name: Check
on:
push:
branches: ["main", "master", "develop", "preprod"]
paths:
- "starters/**"
branches: ["main"]
pull_request:
types: [opened, synchronize]
paths:
- "starters/**"

jobs:
check-changes:
changes:
runs-on: ubuntu-latest
outputs:
meilisearch: ${{ steps.filter.outputs.meilisearch }}
algolia: ${{ steps.filter.outputs.algolia }}
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v2
Expand All @@ -26,31 +21,34 @@ jobs:
shopify-algolia:
- 'starters/shopify-algolia/**'
build:
needs: check-changes
- id: set-matrix
run: |
matrix="{\"include\":["
if [[ "${{ steps.filter.outputs.shopify-meilisearch }}" == 'true' ]]; then
matrix="$matrix{\"app\":\"shopify-meilisearch\",\"working-directory\":\"./starters/shopify-meilisearch\"}"
fi
if [[ "${{ steps.filter.outputs.shopify-algolia }}" == 'true' ]]; then
if [[ "${{ steps.filter.outputs.shopify-meilisearch }}" == 'true' ]]; then
matrix="$matrix,"
fi
matrix="$matrix{\"app\":\"shopify-algolia\",\"working-directory\":\"./starters/shopify-algolia\"}"
fi
matrix="$matrix]}"
echo "matrix=$matrix" >> $GITHUB_OUTPUT
build-and-test:
needs: changes
if: ${{ needs.changes.outputs.matrix != '{"include":[]}' }}
strategy:
matrix:
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) }}
fail-fast: false
matrix: ${{ fromJson(needs.changes.outputs.matrix) }}

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

env:
Expand All @@ -75,28 +73,13 @@ jobs:

- uses: actions/cache@v2
with:
path: "**/node_modules"
key: ${{ runner.os }}-${{ matrix.app.name }}-modules-${{ hashFiles('**/yarn.lock') }}
path: ${{ matrix.working-directory }}/node_modules
key: ${{ runner.os }}-${{ matrix.app }}-modules-${{ hashFiles(format('{0}/yarn.lock', matrix.working-directory)) }}

- name: Install dependencies
run: yarn install --frozen-lockfile --prefer-offline
working-directory: ${{ matrix.app.working-directory }}
working-directory: ${{ matrix.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.app.working-directory }}

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

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

- name: Build
run: yarn build
working-directory: ${{ matrix.app.working-directory }}
working-directory: ${{ matrix.working-directory }}
128 changes: 29 additions & 99 deletions .github/workflows/nextjs_bundle_analysis.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
name: "Next.js Bundle Analysis"

on:
push:
branches:
- main
- develop
paths:
- "starters/**"
pull_request:
branches:
- main
- develop
paths:
- "starters/**"
workflow_dispatch:

jobs:
check-changes:
changes:
runs-on: ubuntu-latest
outputs:
meilisearch: ${{ steps.filter.outputs.meilisearch }}
algolia: ${{ steps.filter.outputs.algolia }}
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v2
Expand All @@ -32,30 +26,33 @@ jobs:
shopify-algolia:
- 'starters/shopify-algolia/**'
- id: set-matrix
run: |
matrix="{\"include\":["
if [[ "${{ steps.filter.outputs.shopify-meilisearch }}" == 'true' || "${{ github.event_name }}" == 'workflow_dispatch' ]]; then
matrix="$matrix{\"app\":\"shopify-meilisearch\",\"working-directory\":\"./starters/shopify-meilisearch\"}"
fi
if [[ "${{ steps.filter.outputs.shopify-algolia }}" == 'true' || "${{ github.event_name }}" == 'workflow_dispatch' ]]; then
if [[ "${{ steps.filter.outputs.shopify-meilisearch }}" == 'true' || "${{ github.event_name }}" == 'workflow_dispatch' ]]; then
matrix="$matrix,"
fi
matrix="$matrix{\"app\":\"shopify-algolia\",\"working-directory\":\"./starters/shopify-algolia\"}"
fi
matrix="$matrix]}"
echo "matrix=$matrix" >> $GITHUB_OUTPUT
analyze:
needs: check-changes
needs: changes
if: ${{ needs.changes.outputs.matrix != '{"include":[]}' }}
strategy:
matrix:
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) }}
fail-fast: false
matrix: ${{ fromJson(needs.changes.outputs.matrix) }}

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

env:
Expand All @@ -80,85 +77,18 @@ jobs:

- uses: actions/cache@v2
with:
path: "**/node_modules"
key: ${{ runner.os }}-${{ matrix.app.name }}-bundle-modules-${{ hashFiles('**/yarn.lock') }}
path: ${{ matrix.working-directory }}/node_modules
key: ${{ runner.os }}-${{ matrix.app }}-bundle-modules-${{ hashFiles(format('{0}/yarn.lock', matrix.working-directory)) }}

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

- name: Restore next build
uses: actions/cache@v3
id: restore-build-cache
env:
cache-name: cache-next-build-${{ matrix.app.name }}
with:
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.app.working-directory }} && yarn build && cd -

- name: Analyze bundle
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.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.name }}
path: ${{ matrix.app.working-directory }}/.next/analyze/base/bundle

- name: Compare with base branch bundle
if: success() && github.event.number
working-directory: ${{ matrix.app.working-directory }}
run: |
if [ -f .next/analyze/base/bundle/__bundle_analysis.json ]; then
npx -p nextjs-bundle-analysis compare
else
echo "Base bundle analysis file not found. Skipping comparison."
exit 0
fi
- name: Get comment body
id: get-comment-body
if: success() && github.event.number
working-directory: ${{ matrix.app.working-directory }}
run: |
body=$(cat .next/analyze/__bundle_analysis_comment.txt)
body="${body//'%'/'%25'}"
body="${body//$'\n'/'%0A'}"
body="${body//$'\r'/'%0D'}"
echo "::set-output name=body::$body"
- name: Find Comment
uses: peter-evans/find-comment@v2
if: success() && github.event.number
id: fc
with:
issue-number: ${{ github.event.number }}
comment-author: "github-actions[bot]"
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
cache-name: cache-next-build-${{ matrix.app }}
with:
issue-number: ${{ github.event.number }}
body: |
<!-- 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
path: ${{ matrix.working-directory }}/.next/cache
key: ${{ runner.os }}-build-${{ env.cache_name }}
65 changes: 31 additions & 34 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,14 @@ on:
- main
- master
- develop
paths:
- "starters/**"
pull_request:
paths:
- "starters/**"
workflow_dispatch:
pull_request: null
workflow_dispatch: null

jobs:
check-changes:
changes:
runs-on: ubuntu-latest
outputs:
meilisearch: ${{ steps.filter.outputs.meilisearch }}
algolia: ${{ steps.filter.outputs.algolia }}
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v2
Expand All @@ -29,27 +24,30 @@ jobs:
shopify-algolia:
- 'starters/shopify-algolia/**'
- id: set-matrix
run: |
matrix="{\"include\":["
if [[ "${{ steps.filter.outputs.shopify-meilisearch }}" == 'true' || "${{ github.event_name }}" == 'workflow_dispatch' ]]; then
matrix="$matrix{\"app\":\"shopify-meilisearch\",\"working-directory\":\"./starters/shopify-meilisearch\"}"
fi
if [[ "${{ steps.filter.outputs.shopify-algolia }}" == 'true' || "${{ github.event_name }}" == 'workflow_dispatch' ]]; then
if [[ "${{ steps.filter.outputs.shopify-meilisearch }}" == 'true' || "${{ github.event_name }}" == 'workflow_dispatch' ]]; then
matrix="$matrix,"
fi
matrix="$matrix{\"app\":\"shopify-algolia\",\"working-directory\":\"./starters/shopify-algolia\"}"
fi
matrix="$matrix]}"
echo "matrix=$matrix" >> $GITHUB_OUTPUT
test:
needs: check-changes
needs: changes
if: ${{ needs.changes.outputs.matrix != '{"include":[]}' }}
strategy:
matrix:
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) }}
fail-fast: false
matrix: ${{ fromJson(needs.changes.outputs.matrix) }}

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

steps:
Expand All @@ -76,27 +74,26 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: "${{ env.node_version }}"

- uses: actions/cache@v2
with:
path: "**/node_modules"
key: ${{ runner.os }}-${{ matrix.app.name }}-playwright-modules-${{ hashFiles('**/yarn.lock') }}
key: ${{ runner.os }}-${{ matrix.app }}-playwright-modules-${{ hashFiles('**/yarn.lock') }}

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

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

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

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

0 comments on commit 43e96f5

Please sign in to comment.