Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

infra: Fix and make CI faster #159

Merged
merged 2 commits into from
Oct 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 58 additions & 9 deletions .github/workflows/pages-deploy.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# Based on https://gist.github.com/AndrewLester/2d3e6257d932831756226ca9a281d9b5
name: Build and Deploy to Pages

on:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand All @@ -156,42 +178,66 @@ 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
uses: actions/checkout@v4
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
Expand All @@ -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
Expand All @@ -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
Expand Down
Loading