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

Commit ba15160

Browse files
authored
Merge pull request #34 from aerogear/github-actions
GitHub actions
2 parents 69879a5 + a7a2f3a commit ba15160

23 files changed

+378
-228
lines changed

.circleci/config.yml

Lines changed: 0 additions & 36 deletions
This file was deleted.

.github/workflows/build.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Build, Lint & Test
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
types: [opened, synchronize, reopened, ready_for_review]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
timeout-minutes: 60
13+
steps:
14+
- name: Checkout master
15+
uses: actions/checkout@v2
16+
- name: Use Node.js
17+
uses: actions/setup-node@v1
18+
with:
19+
node-version: 12.x
20+
- name: Cache Dependencies
21+
id: cache-dependencies
22+
uses: actions/cache@master
23+
with:
24+
path: |
25+
node_modules
26+
*/*/node_modules
27+
key: ${{ runner.os }}-${{ hashFiles('**/package.json') }}
28+
- name: Install dependencies
29+
if: steps.cache-dependencies.outputs.cache-hit != 'true'
30+
run: yarn
31+
- name: Build
32+
run: yarn build
33+
- name: Lint
34+
run: yarn lint
35+
- name: Unit Test
36+
run: yarn test

.github/workflows/release.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Release workflow
2+
on:
3+
push:
4+
tags:
5+
- '*'
6+
jobs:
7+
build:
8+
runs-on: ubuntu-latest
9+
timeout-minutes: 60
10+
env:
11+
CI: true
12+
steps:
13+
- name: Checkout master
14+
uses: actions/checkout@v2
15+
- name: Use Node.js
16+
uses: actions/setup-node@v1
17+
with:
18+
node-version: 12.x
19+
- name: Cache Dependencies
20+
id: cache-dependencies
21+
uses: actions/cache@master
22+
with:
23+
path: |
24+
node_modules
25+
*/*/node_modules
26+
key: ${{ runner.os }}-${{ hashFiles('**/package.json') }}
27+
- name: Build
28+
run: yarn build
29+
- name: Lint
30+
run: yarn lint
31+
- name: Unit Tests
32+
run: yarn test
33+
- name: Publish
34+
run: echo "//registry.npmjs.org/:_authToken=${{secrets.NPM_AUTH_TOKEN}}" > ~/.npmrc && TAG=${GITHUB_REF#"refs/tags/"} npm run release:publish

__tests__/ListAddField.tsx

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,18 @@ import { IonButton } from '@ionic/react';
44

55
import createContext from './_createContext';
66
import mount from './_mount';
7+
import { merge } from 'lodash';
78

8-
const parent = {
9-
maxCount: 3,
10-
value: [],
11-
};
9+
const onChange = jest.fn();
10+
const context = (schema?: {}) =>
11+
createContext(
12+
merge({ x: { type: Array, maxCount: 3 }, 'x.$': String }, schema),
13+
{ onChange, model: { x: [] } },
14+
);
15+
16+
beforeEach(() => {
17+
onChange.mockClear();
18+
});
1219

1320
test('<ListAddField> - works', () => {
1421
const element = <ListAddField name="x.$" parent={parent} />;
@@ -58,20 +65,9 @@ test('<ListAddField> - prevents onClick when limit reached', () => {
5865
});
5966

6067
test('<ListAddField> - correctly reacts on click', () => {
61-
const onChange = jest.fn();
62-
63-
const element = (
64-
<ListAddField
65-
name="x.1"
66-
parent={Object.assign({}, parent, { onChange })}
67-
value="y"
68-
/>
69-
);
70-
const wrapper = mount(
71-
element,
72-
createContext({ x: { type: Array }, 'x.$': { type: String } }),
73-
);
68+
const element = <ListAddField name="x.1" value="y" />;
69+
const wrapper = mount(element, context());
7470

7571
expect(wrapper.find(IonButton).simulate('click')).toBeTruthy();
76-
expect(onChange).toHaveBeenLastCalledWith(['y']);
72+
expect(onChange).toHaveBeenLastCalledWith('x', ['y']);
7773
});

__tests__/ListDelField.tsx

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@ import { IonButton } from '@ionic/react';
44

55
import createContext from './_createContext';
66
import mount from './_mount';
7+
import { merge } from 'lodash';
78

8-
const parent = {
9-
maxCount: 3,
10-
minCount: 0,
11-
value: ['x', 'y', 'z'],
12-
};
9+
const onChange = jest.fn();
10+
const context = (schema?: {}) =>
11+
createContext(
12+
merge({ x: { type: Array, maxCount: 3 }, 'x.$': String }, schema),
13+
{ onChange, model: { x: ['x', 'y', 'z'] } },
14+
);
15+
16+
beforeEach(() => {
17+
onChange.mockClear();
18+
});
1319

1420
test('<ListDelField> - works', () => {
1521
const element = <ListDelField name="x.1" parent={parent} />;
@@ -59,16 +65,9 @@ test('<ListDelField> - prevents onClick when limit reached', () => {
5965
});
6066

6167
test('<ListDelField> - correctly reacts on click', () => {
62-
const onChange = jest.fn();
63-
64-
const element = (
65-
<ListDelField name="x.1" parent={Object.assign({}, parent, { onChange })} />
66-
);
67-
const wrapper = mount(
68-
element,
69-
createContext({ x: { type: Array }, 'x.$': { type: String } }),
70-
);
68+
const element = <ListDelField name="x.1" />;
69+
const wrapper = mount(element, context());
7170

72-
expect(wrapper.find(IonButton).simulate('click')).toBeTruthy();
73-
expect(onChange).toHaveBeenLastCalledWith(['x', 'y']);
71+
expect(wrapper.find(IonButton).simulate('click')).toBeTruthy();
72+
expect(onChange).toHaveBeenLastCalledWith('x', ['x', 'z']);
7473
});

__tests__/ListField.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,13 @@ test('<ListField> - renders children with correct name (children)', () => {
114114
.find(Child)
115115
.at(0)
116116
.prop('name'),
117-
).toBe('x.0');
117+
).toBe('0');
118118
expect(
119119
wrapper
120120
.find(Child)
121121
.at(1)
122122
.prop('name'),
123-
).toBe('x.1');
123+
).toBe('1');
124124
});
125125

126126
test('<ListField> - renders children with correct name (value)', () => {
@@ -135,11 +135,11 @@ test('<ListField> - renders children with correct name (value)', () => {
135135
.find(ListItemField)
136136
.at(0)
137137
.prop('name'),
138-
).toBe('x.0');
138+
).toBe('0');
139139
expect(
140140
wrapper
141141
.find(ListItemField)
142142
.at(1)
143143
.prop('name'),
144-
).toBe('x.1');
144+
).toBe('1');
145145
});

__tests__/NestField.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ test('<NestField> - renders an <AutoField> for each field', () => {
2222
.find(AutoField)
2323
.at(0)
2424
.prop('name'),
25-
).toBe('x.a');
25+
).toBe('a');
2626
expect(
2727
wrapper
2828
.find(AutoField)
2929
.at(1)
3030
.prop('name'),
31-
).toBe('x.b');
31+
).toBe('b');
3232
});
3333

3434
test('<NestField> - renders custom content if given', () => {

package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
"coverage": "jest --coverage --runInBand",
1414
"lint": "eslint --ext js,ts,tsx src",
1515
"reset": "rimraf dist node_modules",
16+
"release:validate": "./scripts/validateRelease.sh TAG=1.2.3",
17+
"release:publish": "./scripts/publishRelease.sh",
1618
"test": "jest --runInBand"
1719
},
1820
"devDependencies": {
@@ -24,16 +26,16 @@
2426
"@ionic/react-test-utils": "^0.0.3",
2527
"@testing-library/react": "^10.0.2",
2628
"@types/classnames": "2.2.10",
27-
"@types/enzyme": "3.10.5",
29+
"@types/enzyme": "3.10.8",
2830
"@types/invariant": "^2.2.31",
2931
"@types/jest": "^25.1.5",
3032
"@types/lodash": "4.14.149",
3133
"@typescript-eslint/eslint-plugin": "2.25.0",
3234
"@typescript-eslint/parser": "2.25.0",
3335
"babel-eslint": "^10.1.0",
3436
"classnames": "^2.2.6",
35-
"enzyme": "^3.11.0",
36-
"enzyme-adapter-react-16": "^1.15.2",
37+
"enzyme": "3.11.0",
38+
"enzyme-adapter-react-16": "1.15.6",
3739
"eslint": "6.8.0",
3840
"eslint-config-prettier": "6.10.1",
3941
"eslint-config-vazco": "5.2.0",
@@ -60,8 +62,8 @@
6062
"ts-node": "8.8.1",
6163
"tslib": "1.11.1",
6264
"typescript": "3.8.3",
63-
"uniforms": "v3.0.0-alpha.5",
64-
"uniforms-bridge-simple-schema-2": "v3.0.0-alpha.5"
65+
"uniforms": "3.0.0",
66+
"uniforms-bridge-simple-schema-2": "3.0.0"
6567
},
6668
"engines": {
6769
"npm": ">=5.0.0"

scripts/prepareRelease.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
echo "Preparing release"
3+
4+
set -e
5+
6+
rm -Rf node_modules
7+
yarn
8+
yarn clean
9+
yarn test
10+
yarn lint
11+
12+
# don't run in CI
13+
if [ ! "$CI" = true ]; then
14+
npm publish
15+
fi
16+
17+
echo "Repository is ready for release."
18+

scripts/publishRelease.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
# explicit declaration that this script needs a $TAG variable passed in e.g TAG=1.2.3 ./script.sh
4+
TAG=$TAG
5+
6+
RELEASE_SYNTAX='^[0-9]+\.[0-9]+\.[0-9]+$'
7+
PRERELEASE_SYNTAX='^[0-9]+\.[0-9]+\.[0-9]+(-.+)+$'
8+
9+
if [ ! "$CI" = true ]; then
10+
echo "Warning: this script should not be run outside of the CI"
11+
echo "If you really need to run this script, you can use"
12+
echo "CI=true ./scripts/publishRelease.sh"
13+
exit 1
14+
fi
15+
16+
if [[ "$(echo $TAG | grep -E $RELEASE_SYNTAX)" == "$TAG" ]]; then
17+
TAG=$TAG npm run release:validate
18+
echo "publishing a new release: $TAG"
19+
npm publish
20+
elif [[ "$(echo $TAG | grep -E $PRERELEASE_SYNTAX)" == "$TAG" ]]; then
21+
npm publish --tag next
22+
echo "publishing a new pre release: $TAG"
23+
"npm publish --tag next"
24+
else
25+
echo "Error: the tag $TAG is not valid. exiting..."
26+
exit 1
27+
fi
28+
29+

0 commit comments

Comments
 (0)