From 33e554148115ea7b657f97af5848afd27af3b13a Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Wed, 21 Aug 2024 16:44:45 +0200 Subject: [PATCH] ci: improve deploy --- .github/workflows/deploy.yml | 42 ++++++++++++++++++--- .gitignore | 2 + astro.config.mjs | 64 +++++++------------------------- eslint.config.mjs | 3 +- package.json | 2 +- src/adapters/ui/blocks/Bio.astro | 4 +- src/config/app.mjs | 5 --- src/config/app.ts | 44 ++++++++++++++++++++++ src/config/assets.ts | 61 ++++++++++++++++++++++++++++++ src/config/imports-policy.mjs | 50 +++++++++++++++++++++++-- 10 files changed, 208 insertions(+), 69 deletions(-) delete mode 100644 src/config/app.mjs create mode 100644 src/config/app.ts create mode 100644 src/config/assets.ts diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 830716b..02dc666 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -5,10 +5,14 @@ on: branches: [main] workflow_dispatch: +concurrency: + cancel-in-progress: false + group: pages + permissions: contents: read - pages: write id-token: write + pages: write jobs: build: @@ -16,28 +20,56 @@ jobs: env: ASTRO_TELEMETRY_DISABLED: 1 + BUILD_PATH: . steps: - name: Checkout your repository using git + id: checkout uses: actions/checkout@v4 + - name: Set yarn + id: yarn + run: corepack enable + - name: Set node + id: node uses: actions/setup-node@v4 + with: + cache: yarn + cache-dependency-path: ./yarn.lock - - name: Set yarn - run: corepack enable + - name: Setup Pages + id: pages + uses: actions/configure-pages@v5 - name: Install dependencies + id: install run: yarn install --frozen-lockfile + working-directory: ${{ env.BUILD_PATH }} - name: Lint + id: lint run: yarn run check + working-directory: ${{ env.BUILD_PATH }} - name: Test + id: test run: yarn run test + working-directory: ${{ env.BUILD_PATH }} + + - name: Build + id: build + run: | + yarn run build \ + --site "${{ steps.pages.outputs.origin }}" \ + --base "${{ steps.pages.outputs.base_path }}" + working-directory: ${{ env.BUILD_PATH }} - - name: Install, build, and upload the site - uses: withastro/action@v2 + - name: Upload + id: upload + uses: actions/upload-pages-artifact@v4 + with: + path: ${{ env.BUILD_PATH }}/dist deploy: needs: build diff --git a/.gitignore b/.gitignore index e12171a..83f0d5c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ .yarn dist node_modules +.env* +!.env.example diff --git a/astro.config.mjs b/astro.config.mjs index e192fbd..16a5a3a 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -11,74 +11,36 @@ import purgecss from 'astro-purgecss' import assetMinifier from '@playform/compress' import { FontaineTransform } from 'fontaine' -/** @type {boolean} */ -const isProd = process.env.NODE_ENV === 'production' +import app from './src/config/app.ts' +import assets from './src/config/assets.ts' -/** - * @type {object} - * @todo Move this to a config file. - */ -const sitemapConfig = { - i18n: { - defaultLocale: 'fr', - locales: { fr: 'fr-FR' } - }, - lastmod: new Date() -} - -/** @type {object} */ -const assetMinifierConfig = { - Image: false, - SVG: false -} - -/** @type {number} */ -const port = 4321 - -/** - * @type {string} - * @todo Move this to a config file (at least the production URL). - */ -const site = isProd ? 'https://maisonquiroga.art' : `http://localhost:${port}` - -/** - * @type {object} - * @todo Move this to a config file. - */ -const vite = { - plugins: [ - FontaineTransform.vite({ - fallbacks: ['Helvetica'], - resolvePath: (id) => new URL(`./public${id}`, import.meta.url) - }) - ] -} +/** @type {'production' | 'development'} */ +const mode = import.meta.env.PROD ? 'production' : 'development' /** @type {import('astro').AstroUserConfig} */ // https://astro.build/config export default defineConfig({ build: { - assets: 'public', - inlineStylesheets: 'always' + assets: assets[mode].output, + inlineStylesheets: assets[mode].inline }, - compressHTML: true, + compressHTML: assets[mode].compression.HTML, integrations: [ svelte(), - sitemap(sitemapConfig), + sitemap(app[mode].sitemap), tailwind(), /* @ts-ignore */ metadata(), insights(), purgecss(), - assetMinifier(assetMinifierConfig), + assetMinifier(assets[mode].compression), imageCompressor(), assetCompressor() ], output: 'static', - server: { - port - }, - site, + site: app[mode].site, trailingSlash: 'always', - vite + vite: { + plugins: [FontaineTransform.vite(assets[mode].fonts(import.meta.url))] + } }) diff --git a/eslint.config.mjs b/eslint.config.mjs index 1ebbeda..73f84ac 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -59,7 +59,8 @@ export default [ { files: ['**/*.ts'], rules: { - '@stylistic/indent': 'off' + '@stylistic/indent': 'off', + 'functional/no-mixed-types': 'off' } }, { diff --git a/package.json b/package.json index f1528d5..0d67435 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "npm": ">= 10.0.0" }, "scripts": { - "build": "astro check && astro build", + "build": "astro build", "check": "run-p check:astro check:eslint check:prettier check:stylelint", "check:astro": "astro check", "check:eslint": "eslint .", diff --git a/src/adapters/ui/blocks/Bio.astro b/src/adapters/ui/blocks/Bio.astro index daa6b2f..cf58ba4 100644 --- a/src/adapters/ui/blocks/Bio.astro +++ b/src/adapters/ui/blocks/Bio.astro @@ -1,6 +1,6 @@ --- -import BioArticle from './BioArticle.svelte' -import BioFigure from './BioFigure.astro' +import BioArticle from ';/blocks/BioArticle.svelte' +import BioFigure from ';/blocks/BioFigure.astro' const { title, text, figure } = Astro.props --- diff --git a/src/config/app.mjs b/src/config/app.mjs deleted file mode 100644 index 35bd240..0000000 --- a/src/config/app.mjs +++ /dev/null @@ -1,5 +0,0 @@ -/** - * Site configuration. - * - * @module site - */ diff --git a/src/config/app.ts b/src/config/app.ts new file mode 100644 index 0000000..dffed21 --- /dev/null +++ b/src/config/app.ts @@ -0,0 +1,44 @@ +/** + * Site configuration. + * + * @module app + */ + +type Sitemap = { + i18n: { + defaultLocale: string + locales: { [key: string]: string } + } + lastmod: Date +} + +const sitemap: Sitemap = { + i18n: { + defaultLocale: 'fr', + locales: { fr: 'fr-FR' } + }, + lastmod: new Date() +} + +type Config = { + site: string + sitemap: Sitemap +} + +type App = { + production: Config + development: Config +} + +const app: App = { + production: { + site: 'https://maisonquiroga.art', + sitemap + }, + development: { + site: 'http://localhost:4321', + sitemap + } +} + +export default app diff --git a/src/config/assets.ts b/src/config/assets.ts new file mode 100644 index 0000000..db71f64 --- /dev/null +++ b/src/config/assets.ts @@ -0,0 +1,61 @@ +/** + * Assets configuration. + * + * @module assets + */ + +type Compression = { + Image: boolean + HTML: boolean + SVG: boolean +} + +const compression: Compression = { + Image: false, + HTML: true, + SVG: false +} + +type Inline = 'always' | 'auto' | 'never' +const inline: Inline = 'always' + +type Output = string +const output = 'public' + +type Fonts = (url: string) => { + fallbacks: string[] + resolvePath: (id: string) => URL +} + +const fonts: Fonts = (url) => { + return { + fallbacks: ['Helvetica'], + resolvePath: (id) => new URL(`public/${id}`, url) + } +} + +type Config = { + compression: Compression + fonts: Fonts + inline: Inline + output: Output +} + +const config: Config = { + compression, + fonts, + inline, + output +} + +type Assets = { + production: Config + development: Config +} + +const assets: Assets = { + production: config, + development: config +} + +export default assets diff --git a/src/config/imports-policy.mjs b/src/config/imports-policy.mjs index cba4598..e577485 100644 --- a/src/config/imports-policy.mjs +++ b/src/config/imports-policy.mjs @@ -6,7 +6,11 @@ export default [ 'no-restricted-imports': [ 'error', { - patterns: ['^(?!.*(schema-dts|\\$\\/|\\^\\/)).*$'] + patterns: [ + { + regex: '^(?!(schema-dts|\\$\\/|\\^\\/)).*$' + } + ] } ] } @@ -17,7 +21,7 @@ export default [ 'no-restricted-imports': [ 'error', { - patterns: ['^(?!.*(schema-dts|\\$\\/|\\@\\/|\\^\\/)).*$'] + patterns: [{ regex: '^(?!(schema-dts|\\$\\/|@\\/|\\^\\/)).*$' }] } ] } @@ -28,7 +32,41 @@ export default [ 'no-restricted-imports': [ 'error', { - patterns: ['^(?!.*(lowdb|\\$\\/utils|\\^\\/ports)).*$'] + patterns: [ + { + regex: '^(?!(lowdb|\\$/utils|\\$/types|&/)).*$' + } + ] + } + ] + } + }, + { + files: ['src/adapters/ui/**/*'], + rules: { + 'no-restricted-imports': [ + 'error', + { + patterns: [ + { + regex: '^(?!(astro|svelte|tailwind|\\$/types|=/|\\+/|;/)).*$' + } + ] + } + ] + } + }, + { + files: ['src/adapters/stores/**/*'], + rules: { + 'no-restricted-imports': [ + 'error', + { + patterns: [ + { + regex: '^(?!(schema-dts|svelte|\\^/|\\+/)).*$' + } + ] } ] } @@ -36,4 +74,8 @@ export default [ ] // @todo Finish this. Forbid outward dependencies. -// @todo Fix this, regex not working. Author: Mauko. Date: 2024-08-19 +// @todo extract schema-dts from stores. +// @todo extract svelte/store, use nano-stores. +// @todo extract entities from stores. +// @todo extract svelte/store from ui. +// @todo extract tailwind config from ui.