Skip to content
This repository was archived by the owner on May 4, 2023. It is now read-only.

Commit 587aa99

Browse files
authored
feat(github): Add GitHub action to test/build (#11)
* test(storybook): wire up for CI/CD Create node.js.yml Also fix broken interactions * build(github): use postgresql service containers https://docs.github.com/en/actions/using-containerized-services/creating-postgresql-service-containers * build(github): expose port to host https://docs.github.com/en/actions/using-containerized-services/about-service-containers#running-jobs-on-the-runner-machine * build(github): fix artifact name clobber * build: switch order to make sure storybook is built
1 parent 163ebe8 commit 587aa99

File tree

7 files changed

+73
-7
lines changed

7 files changed

+73
-7
lines changed

.github/workflows/node.js.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
3+
4+
name: Node.js CI
5+
6+
on:
7+
push:
8+
branches: [ main ]
9+
pull_request:
10+
branches: [ main ]
11+
workflow_dispatch:
12+
13+
jobs:
14+
build:
15+
16+
runs-on: ubuntu-20.04
17+
env:
18+
TEST_DATABASE_URL: postgresql://postgres:postgres@localhost:5432/postgres
19+
20+
services:
21+
# Label used to access the service container
22+
postgres:
23+
# Docker Hub image
24+
image: postgres@sha256:1cb07b811f2ec7b7bf3c42fc3dc19c1b5e87775eee88c2b1a8793420c4de0781
25+
# Provide the password for postgres
26+
env:
27+
POSTGRES_PASSWORD: postgres
28+
# Set health checks to wait until postgres has started
29+
options: >-
30+
--health-cmd pg_isready
31+
--health-interval 10s
32+
--health-timeout 5s
33+
--health-retries 5
34+
ports:
35+
# Maps tcp port 5432 on service container to the host
36+
- 5432:5432
37+
38+
strategy:
39+
matrix:
40+
node-version: [14.x, 16.x]
41+
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
42+
43+
steps:
44+
- uses: actions/checkout@v2
45+
- name: Use Node.js ${{ matrix.node-version }}
46+
uses: actions/setup-node@v2
47+
with:
48+
node-version: ${{ matrix.node-version }}
49+
cache: 'yarn'
50+
- run: yarn install --immutable
51+
- run: yarn rw test && yarn workspace web test-storybook:ci
52+
# order of steps is important, storybook needs to be built first as
53+
# it goes into web/public/storybook which then gets built and put into
54+
# web/dist
55+
- run: yarn rw sb --build --no-open && yarn rw build
56+
- uses: actions/[email protected]
57+
with:
58+
name: build-for-${{github.sha}}-node-${{matrix.node-version}}
59+
path: |
60+
api/dist/
61+
web/dist/

netlify.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
[build]
2-
command = "yarn rw deploy netlify --no-prisma --no-data-migrate && yarn rw sb --build"
2+
# order of steps is important, storybook needs to be built first as
3+
# it goes into web/public/storybook which then gets built and put into
4+
# web/dist
5+
command = "yarn rw sb --build --no-open && yarn rw deploy netlify --no-prisma --no-data-migrate"
36
publish = "web/dist"
47
functions = "api/dist/functions"
58

web/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"tailwindcss": "3.0.23"
3535
},
3636
"scripts": {
37-
"test-storybook": "test-storybook --url http://localhost:7910/ --config-dir \"${PWD}/node_modules/@redwoodjs/testing/config/storybook/\""
37+
"test-storybook": "test-storybook --url http://localhost:7910/ --config-dir \"${PWD}/../node_modules/@redwoodjs/testing/config/storybook/\"",
38+
"test-storybook:ci": "npx concurrently -k -s first -n \"SB,TEST\" -c \"magenta,blue\" \"yarn rw sb\" \"npx wait-on tcp:7910 && yarn test-storybook\""
3839
}
3940
}

web/src/layouts/BlogLayout/BlogLayout.stories.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ generated.play = async ({ canvasElement }) => {
1515
const canvas = within(canvasElement)
1616
const heading = await canvas.findByRole('heading')
1717
expect(heading).toHaveTextContent('Redwood Blog')
18-
const homeLink = await canvas.findByRole('link', { name: 'Home' })
19-
expect(homeLink).toHaveTextContent('Home')
2018
const aboutLink = await canvas.findByRole('link', { name: 'About' })
2119
expect(aboutLink).toHaveTextContent('About')
20+
const homeLink = await canvas.findByRole('link', { name: 'Contact' })
21+
expect(homeLink).toHaveTextContent('Contact')
2222
}
2323

2424
export default { title: 'Layouts/BlogLayout' }

web/src/pages/AboutPage/AboutPage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const AboutPage = () => {
55
<>
66
<MetaTags title="About" description="About page" />
77

8-
<p className="font-light">
8+
<p data-testid="about-paragraph" className="font-light">
99
This site was created to demonstrate my mastery of Redwood: Look on my
1010
works, ye mighty, and despair!
1111
</p>

web/src/pages/AboutPage/AboutPage.stories.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//@ts-check
2-
import { within, userEvent } from '@storybook/testing-library'
2+
import { within } from '@storybook/testing-library'
33
import { expect } from '@storybook/jest'
44
import AboutPage from './AboutPage'
55

@@ -9,7 +9,7 @@ export const generated = () => {
99

1010
generated.play = async ({ canvasElement }) => {
1111
const canvas = within(canvasElement)
12-
const paragraph = await canvas.findByRole('note')
12+
const paragraph = await canvas.findByTestId('about-paragraph')
1313
expect(paragraph).toHaveTextContent(
1414
'Look on my works, ye mighty, and despair!'
1515
)

web/src/pages/AboutPage/__snapshots__/AboutPage.test.js.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ exports[`AboutPage fragment matches snapshot 1`] = `
44
<DocumentFragment>
55
<p
66
class="font-light"
7+
data-testid="about-paragraph"
78
>
89
This site was created to demonstrate my mastery of Redwood: Look on my works, ye mighty, and despair!
910
</p>

0 commit comments

Comments
 (0)