Skip to content

Commit

Permalink
ci: improve deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
bonjourmauko committed Aug 21, 2024
1 parent 333876e commit 33e5541
Show file tree
Hide file tree
Showing 10 changed files with 208 additions and 69 deletions.
42 changes: 37 additions & 5 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,71 @@ on:
branches: [main]
workflow_dispatch:

concurrency:
cancel-in-progress: false
group: pages

permissions:
contents: read
pages: write
id-token: write
pages: write

jobs:
build:
runs-on: ubuntu-latest

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
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
.yarn
dist
node_modules
.env*
!.env.example
64 changes: 13 additions & 51 deletions astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
}
})
3 changes: 2 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ export default [
{
files: ['**/*.ts'],
rules: {
'@stylistic/indent': 'off'
'@stylistic/indent': 'off',
'functional/no-mixed-types': 'off'
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 .",
Expand Down
4 changes: 2 additions & 2 deletions src/adapters/ui/blocks/Bio.astro
Original file line number Diff line number Diff line change
@@ -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
---
Expand Down
5 changes: 0 additions & 5 deletions src/config/app.mjs

This file was deleted.

44 changes: 44 additions & 0 deletions src/config/app.ts
Original file line number Diff line number Diff line change
@@ -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
61 changes: 61 additions & 0 deletions src/config/assets.ts
Original file line number Diff line number Diff line change
@@ -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
50 changes: 46 additions & 4 deletions src/config/imports-policy.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ export default [
'no-restricted-imports': [
'error',
{
patterns: ['^(?!.*(schema-dts|\\$\\/|\\^\\/)).*$']
patterns: [
{
regex: '^(?!(schema-dts|\\$\\/|\\^\\/)).*$'
}
]
}
]
}
Expand All @@ -17,7 +21,7 @@ export default [
'no-restricted-imports': [
'error',
{
patterns: ['^(?!.*(schema-dts|\\$\\/|\\@\\/|\\^\\/)).*$']
patterns: [{ regex: '^(?!(schema-dts|\\$\\/|@\\/|\\^\\/)).*$' }]
}
]
}
Expand All @@ -28,12 +32,50 @@ 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|\\^/|\\+/)).*$'
}
]
}
]
}
}
]

// @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.

0 comments on commit 33e5541

Please sign in to comment.