forked from thomvaill/log4brains
-
Notifications
You must be signed in to change notification settings - Fork 0
144 lines (125 loc) · 5.28 KB
/
ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# Inspired from https://github.com/backstage/backstage/blob/master/.github/workflows/ci.yml. Thanks!
name: CI
on:
workflow_dispatch:
pull_request:
defaults:
run:
shell: bash
jobs:
quality:
strategy:
# We use a matrix even if it's not needed here to be able to re-use the same Yarn setup snippet everywhere
matrix:
os: [ubuntu-latest]
node-version: [16.x] # Active LTS (https://github.com/nodejs/release)
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
# Beginning of yarn setup [KEEP IN SYNC BETWEEN ALL WORKFLOWS]
# TODO: create a dedicated composite GitHub Action to avoid copy/pastes everywhere
- name: use node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
registry-url: https://registry.npmjs.org/ # needed for auth when publishing
# Cache every node_modules folder inside the monorepo
- name: cache all node_modules
id: cache-modules
uses: actions/cache@v2
with:
path: "**/node_modules"
# We use both yarn.lock and package.json as cache keys to ensure that
# changes to local monorepo packages bust the cache.
key: ${{ runner.os }}-v${{ matrix.node-version }}-node_modules-${{ hashFiles('yarn.lock', '**/package.json') }}
# If we get a cache hit for node_modules, there's no need to bring in the global
# yarn cache or run yarn install, as all dependencies will be installed already.
- name: find location of global yarn cache
id: yarn-cache
if: steps.cache-modules.outputs.cache-hit != 'true'
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: cache global yarn cache
uses: actions/cache@v2
if: steps.cache-modules.outputs.cache-hit != 'true'
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: yarn install
if: steps.cache-modules.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile
# End of yarn setup
# TODO: make dev & test work without having to build everything (inspiration: https://github.com/Izhaki/mono.ts)
- name: build
run: yarn build
- name: format
run: yarn format
- name: lint
run: yarn lint
tests:
needs: quality
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: [16.x] # Active LTS (https://github.com/nodejs/release); we test other versions in the main Build workflow because it's too slow
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0 # fetch all history to make Jest snapshot tests work
- name: fetch branch master
run: git fetch origin master
# Beginning of yarn setup [KEEP IN SYNC BETWEEN ALL WORKFLOWS] (copy/paste of the snippet above)
- name: use node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
registry-url: https://registry.npmjs.org/
- name: cache all node_modules
id: cache-modules
uses: actions/cache@v2
with:
path: "**/node_modules"
key: ${{ runner.os }}-v${{ matrix.node-version }}-node_modules-${{ hashFiles('yarn.lock', '**/package.json') }}
- name: find location of global yarn cache
id: yarn-cache
if: steps.cache-modules.outputs.cache-hit != 'true'
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: cache global yarn cache
uses: actions/cache@v2
if: steps.cache-modules.outputs.cache-hit != 'true'
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: yarn install
if: steps.cache-modules.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile
# End of yarn setup
- name: check for yarn.lock changes
id: yarn-lock
run: git diff --quiet origin/master HEAD -- yarn.lock
continue-on-error: true
# - steps.yarn-lock.outcome == 'success' --> yarn.lock was not changed
# - steps.yarn-lock.outcome == 'failure' --> yarn.lock was changed
# We have to build all the packages before the tests
# Because init-log4brains's integration tests use @log4brains/cli, which uses @log4brains/core
# TODO: we should separate tests that require built packages of the others, to get a quicker feedback
# Once it's done, we should add "yarn test" in each package's preVersion script
- name: build
run: |
yarn build
yarn link-cli
echo "$(yarn global bin)" >> $GITHUB_PATH
- name: typescript checks
run: yarn typescript
- name: test changed packages
if: ${{ steps.yarn-lock.outcome == 'success' }}
run: yarn test --since origin/master
- name: test all packages
if: ${{ steps.yarn-lock.outcome == 'failure' }}
run: yarn test
- name: E2E tests
run: yarn e2e