From 43e96f59a2dd1fba8fa51a379aa4090850812f99 Mon Sep 17 00:00:00 2001 From: Dawid Dao Xuan Date: Thu, 31 Oct 2024 20:51:06 +0100 Subject: [PATCH] chore: fix workflows (#86) --- .github/workflows/check.yml | 75 +++++------ .github/workflows/nextjs_bundle_analysis.yml | 128 +++++-------------- .github/workflows/playwright.yml | 65 +++++----- starters/shopify-algolia/README.md | 2 +- starters/shopify-meilisearch/README.md | 2 +- 5 files changed, 91 insertions(+), 181 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 955edb6..19be24c 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -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 @@ -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: @@ -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 }} diff --git a/.github/workflows/nextjs_bundle_analysis.yml b/.github/workflows/nextjs_bundle_analysis.yml index 0bc6da4..4f67a6f 100644 --- a/.github/workflows/nextjs_bundle_analysis.yml +++ b/.github/workflows/nextjs_bundle_analysis.yml @@ -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 @@ -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: @@ -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: "" - - - 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: | - - # 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 }} diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 970557f..2590a63 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -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 @@ -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 @@ -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: @@ -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 diff --git a/starters/shopify-algolia/README.md b/starters/shopify-algolia/README.md index 8490341..b51d00e 100644 --- a/starters/shopify-algolia/README.md +++ b/starters/shopify-algolia/README.md @@ -1,4 +1,4 @@ -🚀 Shopify + Algolia Starter for your next storefront +# 🚀 Shopify + Algolia Starter for your next storefront Run this command and let our CLI do the job or [see our documentation for manual setup instruction](https://blazity.com/r/commerce-docs). diff --git a/starters/shopify-meilisearch/README.md b/starters/shopify-meilisearch/README.md index 3f0e010..54073b8 100644 --- a/starters/shopify-meilisearch/README.md +++ b/starters/shopify-meilisearch/README.md @@ -1,4 +1,4 @@ -🚀 Shopify + Meilisearch Starter for your next storefront +# 🚀 Shopify + Meilisearch Starter for your next storefront Run this command and let our CLI do the job or [see our documentation for manual setup instruction](https://blazity.com/r/commerce-docs).