forked from withastro/astro
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run astro check on all examples in CI (withastro#5022)
* Run astro check on all examples in CI * Output stderr * Build Astro before running checks * Making things faster + colors * Fix errors inside examples * Add congrats message * Revert unentional change to tsconfigs * Remove more unneeded changes
- Loading branch information
1 parent
640ce72
commit f604ef6
Showing
18 changed files
with
200 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: Examples astro check | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
paths: | ||
- 'examples/**' | ||
- '.github/workflows/check.yml' | ||
- 'scripts/smoke/check.js' | ||
- 'packages/astro/src/@types/astro.ts' | ||
|
||
env: | ||
ASTRO_TELEMETRY_DISABLED: true | ||
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} | ||
TURBO_TEAM: ${{ secrets.TURBO_TEAM }} | ||
FORCE_COLOR: true | ||
|
||
jobs: | ||
check: | ||
name: astro check | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup PNPM | ||
uses: pnpm/[email protected] | ||
|
||
- name: Setup Node | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 16 | ||
cache: 'pnpm' | ||
|
||
- name: Install dependencies | ||
run: pnpm install | ||
|
||
- name: Build | ||
run: pnpm run build | ||
|
||
- name: Status | ||
run: git status | ||
|
||
- name: astro check | ||
run: pnpm run test:check-examples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export interface Project { | ||
title: string; | ||
client: string; | ||
description: string; | ||
publishDate: string; | ||
tags: string[]; | ||
img: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
interface Product { | ||
export interface Product { | ||
id: number; | ||
name: string; | ||
price: number; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// @ts-check | ||
|
||
import { spawn } from 'child_process'; | ||
import { readdirSync, readFileSync, writeFileSync } from 'fs'; | ||
import * as path from 'path'; | ||
import { tsconfigResolverSync } from 'tsconfig-resolver'; | ||
|
||
function checkExamples() { | ||
let examples = readdirSync('./examples', { withFileTypes: true }); | ||
examples = examples.filter((dirent) => dirent.isDirectory()); | ||
|
||
console.log(`Running astro check on ${examples.length} examples...`); | ||
|
||
Promise.all( | ||
examples.map( | ||
(example) => | ||
new Promise((resolve) => { | ||
const originalConfig = prepareExample(example.name); | ||
let data = ''; | ||
const child = spawn('node', ['../../packages/astro/astro.js', 'check'], { | ||
cwd: path.join('./examples', example.name), | ||
env: { ...process.env, FORCE_COLOR: 'true' }, | ||
}); | ||
|
||
child.stdout.on('data', function (buffer) { | ||
data += buffer.toString(); | ||
}); | ||
|
||
child.on('exit', (code) => { | ||
if (code !== 0) { | ||
console.error(data); | ||
} | ||
if (originalConfig) { | ||
resetExample(example.name, originalConfig); | ||
} | ||
resolve(code); | ||
}); | ||
}) | ||
) | ||
).then((codes) => { | ||
if (codes.some((code) => code !== 0)) { | ||
process.exit(1); | ||
} | ||
|
||
console.log("No errors found!"); | ||
}); | ||
} | ||
|
||
/** | ||
* @param {string} examplePath | ||
*/ | ||
function prepareExample(examplePath) { | ||
const tsconfigPath = path.join('./examples/', examplePath, 'tsconfig.json'); | ||
const tsconfig = tsconfigResolverSync({ filePath: tsconfigPath, cache: false }); | ||
let originalConfig = undefined; | ||
|
||
if (tsconfig.exists) { | ||
tsconfig.config.extends = 'astro/tsconfigs/strictest'; | ||
originalConfig = readFileSync(tsconfigPath).toString(); | ||
|
||
if (!tsconfig.config.compilerOptions) { | ||
tsconfig.config.compilerOptions = {}; | ||
} | ||
|
||
tsconfig.config.compilerOptions = Object.assign(tsconfig.config.compilerOptions, { | ||
types: tsconfig.config.compilerOptions.types ?? [], // Speeds up tests | ||
}); | ||
} | ||
|
||
writeFileSync(tsconfigPath, JSON.stringify(tsconfig.config)); | ||
|
||
return originalConfig; | ||
} | ||
|
||
/** | ||
* @param {string} examplePath | ||
* @param {string} originalConfig | ||
*/ | ||
function resetExample(examplePath, originalConfig) { | ||
const tsconfigPath = path.join('./examples/', examplePath, 'tsconfig.json'); | ||
writeFileSync(tsconfigPath, originalConfig); | ||
} | ||
|
||
checkExamples(); |