diff --git a/.github/workflows/pages-deploy.yml b/.github/workflows/pages-deploy.yml index d8b7b65b..9c81a435 100644 --- a/.github/workflows/pages-deploy.yml +++ b/.github/workflows/pages-deploy.yml @@ -1,4 +1,3 @@ -# Based on https://gist.github.com/AndrewLester/2d3e6257d932831756226ca9a281d9b5 name: Build and Deploy to Pages on: @@ -66,6 +65,7 @@ jobs: repository: ${{ github.event.repository.full_name }} ref: ${{ github.head_ref }} token: ${{ needs.permissions-check.outputs.has-permissions == 'false' && github.token || secrets.WORKFLOW_PAT }} + fetch-depth: ${{ github.event_name == 'push' && 2 || 1 }} - name: 📥 Install pnpm uses: pnpm/action-setup@v2 @@ -118,7 +118,7 @@ jobs: echo "changes_detected=false >> $GITHUB_OUTPUT" fi - - name: ❌ Exit if Inlang config is not updated + - name: ❌ Exit if Inlang config is not up-to-date if: needs.permissions-check.outputs.has-permissions == 'false' && steps.detect-changes-inlang.outputs.changes_detected == 'true' run: exit 1 @@ -134,11 +134,33 @@ jobs: if: needs.permissions-check.outputs.has-permissions == 'true' && steps.auto-commit-action-inlang.outputs.changes_detected == 'true' run: exit 1 + - name: 🔍 Get modified files + id: modified-files + uses: tj-actions/changed-files@v39 + + - name: 📤 Export results + id: changed-files + run: | + code_changes=false + config_changes=false + + for file in ${{ steps.modified-files.outputs.all_changed_files }}; do + if [[ $file =~ ^src/ || $file =~ ^static/ ]]; then + code_changes=true + elif [[ $file =~ ^.*.config.*s || $file =~ ^tsconfig.json ]]; then + config_changes=true + fi + done + + echo "code_changes=${code_changes}" >> $GITHUB_OUTPUT + echo "config_changes=${config_changes}" >> $GITHUB_OUTPUT + - name: ✨ Check Svelte format + if: steps.changed-files.code_changes == 'true' run: pnpm check - name: ✨ Check style with Prettier & ESLint - id: lint-check + if: steps.changed-files.code_changes == 'true' || steps.changed-files.config_changes == 'true' run: pnpm lint - name: 🔧 Fix lint @@ -156,6 +178,8 @@ jobs: runs-on: ubuntu-latest needs: prechecks if: (!failure() || github.event_name == 'push') && !cancelled() + outputs: + has-built: ${{ steps.changed-files.requires_build }} steps: - name: 📂 Checkout @@ -163,35 +187,57 @@ jobs: with: repository: ${{ github.event.repository.full_name }} ref: ${{ github.head_ref }} + fetch-depth: ${{ github.event_name == 'push' && 2 || 1 }} + + - name: 🔍 Get modified files + id: modified-files + uses: tj-actions/changed-files@v39 + + - name: 📤 Export results + id: changed-files + run: | + requires_build=false + + for file in ${{ steps.modified-files.outputs.all_changed_files }}; do + if [[ $file =~ ^src/ || $file =~ ^static/ || $file =~ ^package.json || $file =~ ^pnpm-lock.yaml || $file =~ ^.*.config.*s || $file =~ ^tsconfig.json ]]; then + requires_build=true + fi + done + + echo "requires_build=${requires_build}" >> $GITHUB_OUTPUT - name: 🔧 Configure pages uses: actions/configure-pages@v3 - if: github.event_name != 'pull_request' + if: github.event_name != 'pull_request' && steps.changed-files.requires_build == 'true' id: pages with: static_site_generator: sveltekit - name: 📥 Install pnpm + if: steps.changed-files.requires_build == 'true' uses: pnpm/action-setup@v2 with: version: latest - name: 🧭 Setup Node + if: steps.changed-files.requires_build == 'true' uses: actions/setup-node@v4 with: node-version: latest cache: pnpm - name: 📥 Install NPM dependencies + if: steps.changed-files.requires_build == 'true' run: pnpm i # no need for `--no-frozen-lockfile` here, as the sync is ensured by the `prechecks` job - name: 🔨 Build repo + if: steps.changed-files.requires_build == 'true' run: | + touch static/.nojekyll pnpm build - touch build/.nojekyll - name: 📤 Upload artifact - if: github.event_name == 'push' + if: github.event_name == 'push' && steps.changed-files.requires_build == 'true' uses: actions/upload-pages-artifact@v2 with: path: build @@ -200,7 +246,7 @@ jobs: name: Deploy website to GitHub Pages runs-on: ubuntu-latest needs: build - if: github.event_name == 'push' && !failure() && !cancelled() + if: github.event_name == 'push' && !failure() && !cancelled() && needs.build.outputs.has-built == 'true' concurrency: group: pages cancel-in-progress: true @@ -221,10 +267,13 @@ jobs: perf-check: name: Performance checks runs-on: ubuntu-latest - needs: deploy - if: github.event_name == 'push' && !failure() && !cancelled() + needs: [build, deploy] + if: github.event_name == 'push' && !failure() && !cancelled() && needs.build.outputs.has-built == 'true' steps: + - name: 🧭 Setup Bun + uses: oven-sh/setup-bun@v1 + - name: ⚓️ Unlighthouse check run: | npm i -g @unlighthouse/cli puppeteer