diff --git a/.github/workflows/lighthouse.yml b/.github/workflows/lighthouse.yml new file mode 100644 index 0000000..4c96acb --- /dev/null +++ b/.github/workflows/lighthouse.yml @@ -0,0 +1,76 @@ +name: Lighthouse CI + +on: + push: + branches: + - main + pull_request: + +jobs: + lighthouse: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '22.x' + cache: 'yarn' + + - name: Install dependencies + run: yarn install --frozen-lockfile + + - name: Build library + run: yarn build + + - name: Build demo + run: yarn build:demo --base=/react-mentions-ts/ + + - name: Run Lighthouse CI + id: lighthouseci + run: | + set +e + DEBUG=lhci: npx @lhci/cli@0.15.x autorun + LHCI_EXIT_CODE=$? + ls -la .lighthouseci + set -e + ls -la + pwd + + REPORTS_DIR=$(node -p "(() => { + const cfg = require('./lighthouserc.cjs') + const dir = (cfg && cfg.ci && cfg.ci.upload && cfg.ci.upload.outputDir) || 'lighthouse-reports' + return dir.startsWith('./') ? dir.slice(2) : dir + })()") + + mkdir -p .lighthouseci + mkdir -p "$REPORTS_DIR" + + if [ -f ".lighthouseci/manifest.json" ] && [ -z "$(ls -A "$REPORTS_DIR" 2>/dev/null)" ]; then + npx @lhci/cli@0.15.x upload --target=filesystem --outputDir="$REPORTS_DIR" || true + fi + + echo "resultsPath=.lighthouseci" >> "$GITHUB_OUTPUT" + echo "reportsPath=$REPORTS_DIR" >> "$GITHUB_OUTPUT" + + exit $LHCI_EXIT_CODE + env: + LHCI_GITHUB_APP_TOKEN: ${{ secrets.LHCI_GITHUB_APP_TOKEN }} + + - name: Upload Lighthouse reports + if: always() + uses: actions/upload-artifact@v4 + with: + name: lighthouse-reports + if-no-files-found: ignore + path: ${{ steps.lighthouseci.outputs.reportsPath }} + + - name: Upload Lighthouse artifacts + if: always() + uses: actions/upload-artifact@v4 + with: + name: lighthouse-artifacts + if-no-files-found: ignore + path: .lighthouseci diff --git a/.gitignore b/.gitignore index dfda699..d67ec4d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ /coverage /demo/dist /demo/build +.lighthouseci npm-debug.log* @@ -13,4 +14,4 @@ npm-debug.log* /dist *.tgz /attw* -.npm-cache \ No newline at end of file +.npm-cache diff --git a/demo/index.html b/demo/index.html index 4fa0a16..257a134 100644 --- a/demo/index.html +++ b/demo/index.html @@ -4,9 +4,9 @@