Skip to content

Commit

Permalink
improve our smoke tests to run on all examples (withastro#2174)
Browse files Browse the repository at this point in the history
* improve smoke test

* chore(lint): Prettier fix

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
FredKSchott and github-actions[bot] committed Dec 13, 2021
1 parent bc08028 commit a656155
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
20 changes: 13 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,11 @@ jobs:
run: yarn workspace astro run test

smoke:
name: 'Smoke Test: ${{ matrix.target }}'
runs-on: ubuntu-latest
name: 'Test (Smoke) ${{ matrix.os }}'
runs-on: ${{ matrix.os }}
strategy:
matrix:
target: [docs, www]
os: [windows-latest, ubuntu-latest]
needs:
- build
steps:
Expand All @@ -177,7 +177,7 @@ jobs:
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: 16
node-version: 14
cache: 'yarn'

- name: Download Build Artifacts
Expand All @@ -198,9 +198,15 @@ jobs:
env:
CI: true

- name: Build
run: yarn build
working-directory: ${{ matrix.target }}
- name: Test
if: ${{ matrix.os != 'windows-latest' }}
run: yarn run build:examples --concurrency=1

# Turbo seems to fail on Windows, so run a custom script directly.
- name: Test (Windows)
if: ${{ matrix.os == 'windows-latest' }}
run: node ./scripts/smoke/index.js


# Changelog can only run _after_ Build and Test.
# We download all `dist/` artifacts from GitHub to skip the build process.
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"scripts": {
"release": "yarn build && changeset publish",
"build": "turbo run build --no-deps --scope=astro --scope=create-astro --scope=\"@astrojs/*\"",
"build:examples": "turbo run build --scope=docs --scope=www --scope=\"@example/*\"",
"dev": "turbo run dev --no-deps --no-cache --parallel --scope=astro --scope=create-astro --scope=\"@astrojs/*\"",
"test": "turbo run test --scope=astro",
"test:templates": "turbo run test --scope=create-astro",
Expand Down
31 changes: 31 additions & 0 deletions scripts/smoke/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import fs from 'fs';
import { execa } from 'execa';
import { fileURLToPath } from 'url';

// NOTE: Only needed for Windows, due to a Turbo bug.
// Once Turbo works on Windows, we can remove this script
// and update our CI to run through Turbo.

export default async function run() {
const examplesUrl = new URL('../../examples/', import.meta.url);
const examplesToTest = fs
.readdirSync(examplesUrl)
.map((filename) => new URL(filename, examplesUrl))
.filter((fileUrl) => fs.statSync(fileUrl).isDirectory());
const allProjectsToTest = [...examplesToTest, new URL('../../www', import.meta.url), new URL('../../docs', import.meta.url)];

console.log('');
for (const projectToTest of allProjectsToTest) {
const filePath = fileURLToPath(projectToTest);
console.log(' πŸ€– Testing', filePath, '\n');
try {
await execa('yarn', ['build'], { cwd: fileURLToPath(projectToTest), stdout: 'inherit', stderr: 'inherit' });
} catch (err) {
console.log(err);
process.exit(1);
}
console.log('\n πŸ€– Test complete.');
}
}

run();

0 comments on commit a656155

Please sign in to comment.